Skip to content

Commit

Permalink
increase web tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Jul 25, 2023
1 parent 8d7d9b9 commit 37132e0
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 0 deletions.
10 changes: 10 additions & 0 deletions web/contact/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ func TestCreateContacts(t *testing.T) {
web.RunWebTests(t, ctx, rt, "testdata/create.json", nil)
}

func TestCreateContactsWithErrors(t *testing.T) {
ctx, rt, db, _ := testsuite.Get()

defer testsuite.Reset(testsuite.ResetAll)

db.MustExec(`ALTER SEQUENCE contacts_contact_id_seq RESTART WITH 30000`)

web.RunWebTests(t, ctx, rt, "testdata/create_with_errors.json", nil)
}

func TestModifyContacts(t *testing.T) {
ctx, rt, db, _ := testsuite.Get()

Expand Down
44 changes: 44 additions & 0 deletions web/contact/testdata/create_with_errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"label": "error if contact not provided",
"method": "POST",
"path": "/mr/contact/create",
"body": {
"org_id": 12345,
"user_id": 1,
"contact": {}
},
"status": 500,
"response": {
"error": "unable to load org assets: error loading environment for org 12345: no org with id: 12345"
}
},
{
"label": "create contact with all properties",
"method": "POST",
"path": "/mr/contact/create",
"body": {
"org_id": 1,
"user_id": 1,
"contact": {
"name": "José",
"language": "spa",
"urns": [
"tel:+16055700001"
],
"fields": {
"gender": "M",
"age": "39",
"lorem": "ipsum"
},
"groups": [
"c153e265-f7c9-4539-9dbc-9b358714b638"
]
}
},
"status": 400,
"response": {
"error": "unknown contact field 'lorem'"
}
}
]
29 changes: 29 additions & 0 deletions web/contact/testdata/modify.json
Original file line number Diff line number Diff line change
Expand Up @@ -1393,5 +1393,34 @@
]
}
}
},
{
"label": "with no contacts for error on validate",
"method": "POST",
"path": "/mr/contact/modify",
"body": {
"org_id": 1,
"modifiers": []
},
"status": 400,
"response": {
"error": "request failed validation: field 'contact_ids' is required"
}
},
{
"label": "with invalid org id",
"method": "POST",
"path": "/mr/contact/modify",
"body": {
"org_id": 12345,
"contact_ids": [
10000
],
"modifiers": []
},
"status": 500,
"response": {
"error": "unable to load org assets: error loading environment for org 12345: no org with id: 12345"
}
}
]
14 changes: 14 additions & 0 deletions web/contact/testdata/resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,19 @@
"count": 1
}
]
},
{
"label": "error with invalid org id",
"method": "POST",
"path": "/mr/contact/resolve",
"body": {
"org_id": 12345,
"channel_id": 10000,
"urn": "tel:+1-605-5747777"
},
"status": 500,
"response": {
"error": "unable to load org assets: error loading environment for org 12345: no org with id: 12345"
}
}
]
27 changes: 27 additions & 0 deletions web/po/testdata/export.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,32 @@
},
"status": 200,
"response_file": "testdata/multiple_flows_noargs.es.po"
},
{
"label": "export POT with invalid body single flow",
"method": "POST",
"path": "/mr/po/export",
"body": {
"key1": 1
},
"status": 500,
"response": {
"error": "request failed validation: field 'org_id' is required, field 'flow_ids' is required"
}
},
{
"label": "export POT from single flow with invalid org_id",
"method": "POST",
"path": "/mr/po/export",
"body": {
"org_id": 11,
"flow_ids": [
10009
]
},
"status": 500,
"response": {
"error": "unable to load org assets: error loading environment for org 11: no org with id: 11"
}
}
]
Loading

0 comments on commit 37132e0

Please sign in to comment.