Skip to content

Commit

Permalink
Merge pull request #613 from nyaruka/update_testdb
Browse files Browse the repository at this point in the history
Update test database
  • Loading branch information
rowanseymour authored Apr 4, 2022
2 parents e34f917 + 39d68bb commit 4d8b5a3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 32 deletions.
19 changes: 10 additions & 9 deletions core/models/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@ func TestLoadGroups(t *testing.T) {
require.NoError(t, err)

tcs := []struct {
ID models.GroupID
UUID assets.GroupUUID
Name string
Query string
id models.GroupID
uuid assets.GroupUUID
name string
query string
}{
{testdata.DoctorsGroup.ID, testdata.DoctorsGroup.UUID, "Doctors", ""},
{testdata.OpenTicketsGroup.ID, testdata.OpenTicketsGroup.UUID, "Open Tickets", "tickets > 0"},
{testdata.TestersGroup.ID, testdata.TestersGroup.UUID, "Testers", ""},
}

assert.Equal(t, 2, len(groups))
assert.Equal(t, 3, len(groups))
for i, tc := range tcs {
group := groups[i].(*models.Group)
assert.Equal(t, tc.UUID, group.UUID())
assert.Equal(t, tc.ID, group.ID())
assert.Equal(t, tc.Name, group.Name())
assert.Equal(t, tc.Query, group.Query())
assert.Equal(t, tc.uuid, group.UUID())
assert.Equal(t, tc.id, group.ID())
assert.Equal(t, tc.name, group.Name())
assert.Equal(t, tc.query, group.Query())
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/models/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestGetContactIDsForQueryPage(t *testing.T) {
ExpectedError string
}{
{
Group: testdata.AllContactsGroup.UUID,
Group: testdata.ActiveGroup.UUID,
Query: "george",
ExpectedESRequest: `{
"_source": false,
Expand All @@ -63,7 +63,7 @@ func TestGetContactIDsForQueryPage(t *testing.T) {
},
{
"term": {
"groups": "d1ee73f0-bdb5-47ce-99dd-0c95d4ebf008"
"groups": "b97f69f7-5edf-45c7-9fda-d37066eae91d"
}
},
{
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestGetContactIDsForQueryPage(t *testing.T) {
ExpectedTotal: 1,
},
{
Group: testdata.BlockedContactsGroup.UUID,
Group: testdata.BlockedGroup.UUID,
ExcludeIDs: []models.ContactID{testdata.Bob.ID, testdata.Cathy.ID},
Query: "age > 32",
Sort: "-age",
Expand All @@ -139,7 +139,7 @@ func TestGetContactIDsForQueryPage(t *testing.T) {
},
{
"term": {
"groups": "9295ebab-5c2d-4eb1-86f9-7c15ed2f3219"
"groups": "14f6ea01-456b-4417-b0b8-35e942f549f1"
}
},
{
Expand Down
10 changes: 3 additions & 7 deletions core/models/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ func TestCloseTickets(t *testing.T) {
},
}))

testdata.InsertContactGroup(db, testdata.Org1, "94c816d7-cc87-42db-a577-ce072ceaab80", "Tickets", "tickets > 0")

oa, err := models.GetOrgAssetsWithRefresh(ctx, rt, testdata.Org1.ID, models.RefreshTicketers|models.RefreshGroups)
require.NoError(t, err)

Expand All @@ -299,7 +297,7 @@ func TestCloseTickets(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, "Doctors", cathy.Groups().All()[0].Name())
assert.Equal(t, "Tickets", cathy.Groups().All()[1].Name())
assert.Equal(t, "Open Tickets", cathy.Groups().All()[1].Name())

logger := &models.HTTPLogger{}
evts, err := models.CloseTickets(ctx, rt, oa, testdata.Admin.ID, []*models.Ticket{modelTicket1, modelTicket2}, true, false, logger)
Expand Down Expand Up @@ -354,8 +352,6 @@ func TestReopenTickets(t *testing.T) {
},
}))

testdata.InsertContactGroup(db, testdata.Org1, "94c816d7-cc87-42db-a577-ce072ceaab80", "Two Tickets", "tickets = 2")

oa, err := models.GetOrgAssetsWithRefresh(ctx, rt, testdata.Org1.ID, models.RefreshTicketers|models.RefreshGroups)
require.NoError(t, err)

Expand Down Expand Up @@ -385,9 +381,9 @@ func TestReopenTickets(t *testing.T) {
// but no events for ticket #2 which waas already open
assertdb.Query(t, db, `SELECT count(*) FROM tickets_ticketevent WHERE ticket_id = $1 AND event_type = 'R'`, ticket2.ID).Returns(0)

// check Cathy is now in the two tickets group
// check Cathy is now in the open tickets group
_, cathy := testdata.Cathy.Load(db, oa)
assert.Equal(t, 2, len(cathy.Groups().All()))
assert.Equal(t, "Doctors", cathy.Groups().All()[0].Name())
assert.Equal(t, "Two Tickets", cathy.Groups().All()[1].Name())
assert.Equal(t, "Open Tickets", cathy.Groups().All()[1].Name())
}
Binary file modified mailroom_test.dump
Binary file not shown.
14 changes: 9 additions & 5 deletions testsuite/testdata/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@ var IncomingExtraFlow = &Flow{10006, "376d3de6-7f0e-408c-80d6-b1919738bc80"}
var ParentTimeoutFlow = &Flow{10007, "81c0f323-7e06-4e0c-a960-19c20f17117c"}
var CampaignFlow = &Flow{10009, "3a92a964-3a8d-420b-9206-2cd9d884ac30"}

var CreatedOnField = &Field{3, "53499958-0a0a-48a5-bb5f-8f9f4d8af77b"}
var LastSeenOnField = &Field{5, "4307df2e-b00b-42b6-922b-4a1dcfc268d8"}
var CreatedOnField = &Field{3, "fd18a69d-7514-4b76-9fad-072641995e17"}
var LanguageField = &Field{4, "4307df2e-b00b-42b6-922b-4a1dcfc268d8"}
var LastSeenOnField = &Field{5, "660ebe03-b717-4a80-aebf-9b7c718266e1"}
var GenderField = &Field{6, "3a5891e4-756e-4dc9-8e12-b7a766168824"}
var AgeField = &Field{7, "903f51da-2717-47c7-a0d3-f2f32877013d"}
var JoinedField = &Field{8, "d83aae24-4bbf-49d0-ab85-6bfd201eac6d"}

var AllContactsGroup = &Group{1, "d1ee73f0-bdb5-47ce-99dd-0c95d4ebf008"}
var BlockedContactsGroup = &Group{2, "9295ebab-5c2d-4eb1-86f9-7c15ed2f3219"}
var ActiveGroup = &Group{1, "b97f69f7-5edf-45c7-9fda-d37066eae91d"}
var BlockedGroup = &Group{2, "14f6ea01-456b-4417-b0b8-35e942f549f1"}
var StoppedGroup = &Group{3, "d1ee73f0-bdb5-47ce-99dd-0c95d4ebf008"}
var ArchivedGroup = &Group{4, "9295ebab-5c2d-4eb1-86f9-7c15ed2f3219"}
var OpenTicketsGroup = &Group{5, "361838c4-2866-495a-8990-9f3c222a7604"}
var DoctorsGroup = &Group{10000, "c153e265-f7c9-4539-9dbc-9b358714b638"}
var TestersGroup = &Group{10001, "5e9d8fab-5e7e-4f51-b533-261af5dea70d"}

var ReportingLabel = &Label{10000, "ebc4dedc-91c4-4ed4-9dd6-daa05ea82698"}
var TestingLabel = &Label{10001, "a6338cdc-7938-4437-8b05-2d5d785e3a08"}

var DefaultTopic = &Topic{1, "ffc903f7-8cbb-443f-9627-87106842d1aa"}
var DefaultTopic = &Topic{1, "5cc1848a-357c-4de9-9720-45770ec18d11"}
var SalesTopic = &Topic{2, "9ef2ff21-064a-41f1-8560-ccc990b4f937"}
var SupportTopic = &Topic{3, "0a8f2e00-fef6-402c-bd79-d789446ec0e0"}

Expand Down
14 changes: 7 additions & 7 deletions web/contact/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ func TestSearch(t *testing.T) {
{
method: "POST",
url: "/mr/contact/search",
body: fmt.Sprintf(`{"org_id": 1, "query": "birthday = tomorrow", "group_uuid": "%s"}`, testdata.AllContactsGroup.UUID),
body: fmt.Sprintf(`{"org_id": 1, "query": "birthday = tomorrow", "group_uuid": "%s"}`, testdata.ActiveGroup.UUID),
expectedStatus: 400,
expectedError: "can't resolve 'birthday' to attribute, scheme or field",
},
{
method: "POST",
url: "/mr/contact/search",
body: fmt.Sprintf(`{"org_id": 1, "query": "age > tomorrow", "group_uuid": "%s"}`, testdata.AllContactsGroup.UUID),
body: fmt.Sprintf(`{"org_id": 1, "query": "age > tomorrow", "group_uuid": "%s"}`, testdata.ActiveGroup.UUID),
expectedStatus: 400,
expectedError: "can't convert 'tomorrow' to a number",
},
{
method: "POST",
url: "/mr/contact/search",
body: fmt.Sprintf(`{"org_id": 1, "query": "Cathy", "group_uuid": "%s"}`, testdata.AllContactsGroup.UUID),
body: fmt.Sprintf(`{"org_id": 1, "query": "Cathy", "group_uuid": "%s"}`, testdata.ActiveGroup.UUID),
esResponse: singleESResponse,
expectedStatus: 200,
expectedHits: []models.ContactID{testdata.Cathy.ID},
Expand All @@ -126,7 +126,7 @@ func TestSearch(t *testing.T) {
{
method: "POST",
url: "/mr/contact/search",
body: fmt.Sprintf(`{"org_id": 1, "query": "Cathy", "group_uuid": "%s", "exclude_ids": [%d, %d]}`, testdata.AllContactsGroup.UUID, testdata.Bob.ID, testdata.George.ID),
body: fmt.Sprintf(`{"org_id": 1, "query": "Cathy", "group_uuid": "%s", "exclude_ids": [%d, %d]}`, testdata.ActiveGroup.UUID, testdata.Bob.ID, testdata.George.ID),
esResponse: singleESResponse,
expectedStatus: 200,
expectedHits: []models.ContactID{testdata.Cathy.ID},
Expand All @@ -153,7 +153,7 @@ func TestSearch(t *testing.T) {
},
{
"term": {
"groups": "d1ee73f0-bdb5-47ce-99dd-0c95d4ebf008"
"groups": "b97f69f7-5edf-45c7-9fda-d37066eae91d"
}
},
{
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestSearch(t *testing.T) {
{
method: "POST",
url: "/mr/contact/search",
body: fmt.Sprintf(`{"org_id": 1, "query": "AGE = 10 and gender = M", "group_uuid": "%s"}`, testdata.AllContactsGroup.UUID),
body: fmt.Sprintf(`{"org_id": 1, "query": "AGE = 10 and gender = M", "group_uuid": "%s"}`, testdata.ActiveGroup.UUID),
esResponse: singleESResponse,
expectedStatus: 200,
expectedHits: []models.ContactID{testdata.Cathy.ID},
Expand All @@ -204,7 +204,7 @@ func TestSearch(t *testing.T) {
{
method: "POST",
url: "/mr/contact/search",
body: fmt.Sprintf(`{"org_id": 1, "query": "", "group_uuid": "%s"}`, testdata.AllContactsGroup.UUID),
body: fmt.Sprintf(`{"org_id": 1, "query": "", "group_uuid": "%s"}`, testdata.ActiveGroup.UUID),
esResponse: singleESResponse,
expectedStatus: 200,
expectedHits: []models.ContactID{testdata.Cathy.ID},
Expand Down

0 comments on commit 4d8b5a3

Please sign in to comment.