Skip to content

Commit

Permalink
Use the new testdata.InsertOpenTicket in RocketChat ticketer
Browse files Browse the repository at this point in the history
  • Loading branch information
koallann committed Oct 20, 2020
1 parent f37c923 commit 8705272
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 11 deletions.
98 changes: 89 additions & 9 deletions services/tickets/rocketchat/testdata/event_callback.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
"label": "error response if no such ticketer",
"method": "POST",
"path": "/mr/tickets/types/rocketchat/event_callback/XYZ",
"body": "{\"type\":\"agent-message\",\"ticketID\":\"88bfa1dc-be33-45c2-b469-294ecb0eba90\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"text\":\"We can help\"}}",
"body": {
"type": "agent-message",
"ticketID": "88bfa1dc-be33-45c2-b469-294ecb0eba90",
"visitor": {
"token": "1234"
},
"data": {
"text": "We can help"
}
},
"status": 404,
"response": {
"error": "not found: /mr/tickets/types/rocketchat/event_callback/XYZ"
Expand All @@ -13,7 +22,16 @@
"label": "unauthorized response if missing auth",
"method": "POST",
"path": "/mr/tickets/types/rocketchat/event_callback/6c50665f-b4ff-4e37-9625-bc464fe6a999",
"body": "{\"type\":\"agent-message\",\"ticketID\":\"88bfa1dc-be33-45c2-b469-294ecb0eba90\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"text\":\"We can help\"}}",
"body": {
"type": "agent-message",
"ticketID": "88bfa1dc-be33-45c2-b469-294ecb0eba90",
"visitor": {
"token": "1234"
},
"data": {
"text": "We can help"
}
},
"status": 404,
"response": {
"status": "unauthorized"
Expand All @@ -26,7 +44,16 @@
"headers": {
"Authorization": "Token 987654321"
},
"body": "{\"type\":\"agent-message\",\"ticketID\":\"88bfa1dc-be33-45c2-b469-294ecb0eba90\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"text\":\"We can help\"}}",
"body": {
"type": "agent-message",
"ticketID": "88bfa1dc-be33-45c2-b469-294ecb0eba90",
"visitor": {
"token": "1234"
},
"data": {
"text": "We can help"
}
},
"status": 404,
"response": {
"status": "unauthorized"
Expand All @@ -39,7 +66,15 @@
"headers": {
"Authorization": "Token 123456789"
},
"body": "{\"ticketID\":\"88bfa1dc-be33-45c2-b469-294ecb0eba90\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"text\":\"We can help\"}}",
"body": {
"ticketID": "88bfa1dc-be33-45c2-b469-294ecb0eba90",
"visitor": {
"token": "1234"
},
"data": {
"text": "We can help"
}
},
"status": 400,
"response": {
"error": "field 'type' is required"
Expand All @@ -52,7 +87,16 @@
"headers": {
"Authorization": "Token 123456789"
},
"body": "{\"type\":\"agent-message\",\"ticketID\":\"88bfa1dc-be33-45c2-b469-294ecb0eba90\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"text\":\"We can help\"}}",
"body": {
"type": "agent-message",
"ticketID": "88bfa1dc-be33-45c2-b469-294ecb0eba90",
"visitor": {
"token": "1234"
},
"data": {
"text": "We can help"
}
},
"status": 400,
"response": {
"error": "no such ticket 88bfa1dc-be33-45c2-b469-294ecb0eba90"
Expand All @@ -65,7 +109,16 @@
"headers": {
"Authorization": "Token 123456789"
},
"body": "{\"type\":\"other\",\"ticketID\":\"c69f103c-db64-4481-815b-1112890419ef\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"text\":\"We can help\"}}",
"body": {
"type": "other",
"ticketID": "c69f103c-db64-4481-815b-1112890419ef",
"visitor": {
"token": "1234"
},
"data": {
"text": "We can help"
}
},
"status": 400,
"response": {
"error": "invalid event type"
Expand All @@ -78,7 +131,16 @@
"headers": {
"Authorization": "Token 123456789"
},
"body": "{\"type\":\"agent-message\",\"ticketID\":\"c69f103c-db64-4481-815b-1112890419ef\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"text\":\"We can help\"}}",
"body": {
"type": "agent-message",
"ticketID": "c69f103c-db64-4481-815b-1112890419ef",
"visitor": {
"token": "1234"
},
"data": {
"text": "We can help"
}
},
"status": 200,
"response": {
"status": "handled"
Expand All @@ -101,7 +163,19 @@
"headers": {
"Authorization": "Token 123456789"
},
"body": "{\"type\":\"agent-message\",\"ticketID\":\"c69f103c-db64-4481-815b-1112890419ef\",\"visitor\":{\"token\":\"1234\"},\"data\":{\"attachments\":[{\"type\": \"image/jpg\", \"url\": \"https://link.to/image.jpg\"}]}}",
"body": {
"type": "agent-message",
"ticketID": "c69f103c-db64-4481-815b-1112890419ef",
"visitor": {
"token": "1234"
},
"data": {
"attachments": [{
"type": "image/jpg",
"url": "https://link.to/image.jpg"
}]
}
},
"http_mocks": {
"https://link.to/image.jpg": [
{
Expand All @@ -128,7 +202,13 @@
"headers": {
"Authorization": "Token 123456789"
},
"body": "{\"type\":\"close-room\",\"ticketID\":\"c69f103c-db64-4481-815b-1112890419ef\",\"visitor\":{\"token\":\"1234\"}}",
"body": {
"type": "close-room",
"ticketID": "c69f103c-db64-4481-815b-1112890419ef",
"visitor": {
"token": "1234"
}
},
"status": 200,
"response": {
"status": "handled"
Expand Down
4 changes: 2 additions & 2 deletions services/tickets/rocketchat/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rocketchat_test
import (
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/testsuite"
"github.com/nyaruka/mailroom/testsuite/testdata"
"github.com/nyaruka/mailroom/web"
"testing"
)
Expand All @@ -12,8 +13,7 @@ func TestEventCallback(t *testing.T) {
db := testsuite.DB()

// create a rocketchat ticket for Cathy
db.MustExec(`INSERT INTO tickets_ticket(id, uuid, org_id, contact_id, ticketer_id, status, subject, body, opened_on, modified_on)
VALUES(1, 'c69f103c-db64-4481-815b-1112890419ef', $1, $2, $3, 'O', 'Need help', 'Have you seen my cookies?', NOW(), NOW())`, models.Org1, models.CathyID, models.RocketChatID)
testdata.InsertOpenTicket(t, db, models.Org1, models.CathyID, models.RocketChatID, "c69f103c-db64-4481-815b-1112890419ef", "Need help", "Have you seen my cookies?", "1234")

web.RunWebTests(t, "testdata/event_callback.json")
}

0 comments on commit 8705272

Please sign in to comment.