Skip to content

Commit

Permalink
Replace some calls to testsuite.Reset() with testdata.ResetContactData()
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 9, 2021
1 parent 2c11f44 commit a2f2fca
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
12 changes: 6 additions & 6 deletions core/models/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestGetOrCreateContact(t *testing.T) {

defer testdata.ResetContactData(db)

testdata.InsertContactGroup(db, testdata.Org1, "d636c966-79c1-4417-9f1c-82ad629773a2", "Telegrammer", `telegram = 100001`)
testdata.InsertContactGroup(db, testdata.Org1, "dcc16d85-8274-4d19-a3c2-152d4ee99380", "Telegrammer", `telegram = 100001`)

// add some orphaned URNs
testdata.InsertContactURN(db, testdata.Org1, nil, urns.URN("telegram:200001"), 100)
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestGetOrCreateContact(t *testing.T) {
true,
[]urns.URN{"telegram:100001?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=30002&priority=1000"},
testdata.TwilioChannel.ID,
[]assets.GroupUUID{"d636c966-79c1-4417-9f1c-82ad629773a2"},
[]assets.GroupUUID{"dcc16d85-8274-4d19-a3c2-152d4ee99380"},
},
{
testdata.Org1.ID,
Expand All @@ -257,7 +257,7 @@ func TestGetOrCreateContact(t *testing.T) {
false,
[]urns.URN{"telegram:100001?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=30002&priority=1000"},
models.NilChannelID,
[]assets.GroupUUID{"d636c966-79c1-4417-9f1c-82ad629773a2"},
[]assets.GroupUUID{"dcc16d85-8274-4d19-a3c2-152d4ee99380"},
},
{
testdata.Org1.ID,
Expand All @@ -266,7 +266,7 @@ func TestGetOrCreateContact(t *testing.T) {
false,
[]urns.URN{"telegram:100001?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=30002&priority=1000"},
models.NilChannelID,
[]assets.GroupUUID{"d636c966-79c1-4417-9f1c-82ad629773a2"},
[]assets.GroupUUID{"dcc16d85-8274-4d19-a3c2-152d4ee99380"},
},
{
testdata.Org1.ID,
Expand All @@ -275,7 +275,7 @@ func TestGetOrCreateContact(t *testing.T) {
false,
[]urns.URN{"telegram:100001?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=30002&priority=1000"},
models.NilChannelID,
[]assets.GroupUUID{"d636c966-79c1-4417-9f1c-82ad629773a2"},
[]assets.GroupUUID{"dcc16d85-8274-4d19-a3c2-152d4ee99380"},
},
{
testdata.Org1.ID,
Expand All @@ -284,7 +284,7 @@ func TestGetOrCreateContact(t *testing.T) {
false,
[]urns.URN{"telegram:100001?channel=74729f45-7f29-4868-9dc4-90e491e3c7d8&id=30002&priority=1000"},
models.NilChannelID,
[]assets.GroupUUID{"d636c966-79c1-4417-9f1c-82ad629773a2"},
[]assets.GroupUUID{"dcc16d85-8274-4d19-a3c2-152d4ee99380"},
},
{
testdata.Org1.ID,
Expand Down
4 changes: 4 additions & 0 deletions testsuite/testdata/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func InsertContactURN(db *sqlx.DB, org *Org, contact *Contact, urn urns.URN, pri
func ResetContactData(db *sqlx.DB) {
db.MustExec(`DELETE FROM tickets_ticketevent`)
db.MustExec(`DELETE FROM tickets_ticket`)
db.MustExec(`DELETE FROM channels_channelcount`)
db.MustExec(`DELETE FROM msgs_msg`)
db.MustExec(`DELETE FROM contacts_contacturn WHERE id >= 30000`)
db.MustExec(`DELETE FROM contacts_contactgroup_contacts WHERE contact_id >= 30000`)
Expand All @@ -101,4 +102,7 @@ func ResetContactData(db *sqlx.DB) {
db.MustExec(`ALTER SEQUENCE contacts_contact_id_seq RESTART WITH 30000`)
db.MustExec(`ALTER SEQUENCE contacts_contacturn_id_seq RESTART WITH 30000`)
db.MustExec(`ALTER SEQUENCE contacts_contactgroup_id_seq RESTART WITH 30000`)

// because groups have changed
models.FlushCache()
}
2 changes: 2 additions & 0 deletions web/msg/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
func TestServer(t *testing.T) {
_, _, db, _ := testsuite.Get()

defer testdata.ResetContactData(db)

cathyIn := testdata.InsertIncomingMsg(db, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "hello", models.MsgStatusHandled)
cathyOut := testdata.InsertOutgoingMsg(db, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "how can we help", nil, models.MsgStatusSent)
bobOut := testdata.InsertOutgoingMsg(db, testdata.Org1, testdata.VonageChannel, testdata.Bob, "this failed", nil, models.MsgStatusFailed)
Expand Down
4 changes: 3 additions & 1 deletion web/org/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
)

func TestMetrics(t *testing.T) {
ctx, _, db, rp := testsuite.Reset()
ctx, _, db, rp := testsuite.Get()

defer testsuite.Reset()

promToken := "2d26a50841ff48237238bbdd021150f6a33a4196"
db.MustExec(`INSERT INTO api_apitoken(is_active, org_id, created, key, role_id, user_id) VALUES(TRUE, $1, NOW(), $2, 12, 1);`, testdata.Org1.ID, promToken)
Expand Down
4 changes: 3 additions & 1 deletion web/simulation/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ const (
)

func TestServer(t *testing.T) {
ctx, _, db, rp := testsuite.Reset()
ctx, _, db, rp := testsuite.Get()

defer testsuite.Reset()

wg := &sync.WaitGroup{}

Expand Down
4 changes: 3 additions & 1 deletion web/surveyor/surveyor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import (
)

func TestSurveyor(t *testing.T) {
ctx, _, db, rp := testsuite.Reset()
ctx, _, db, rp := testsuite.Get()
rc := rp.Get()
defer rc.Close()

defer testsuite.Reset()

wg := &sync.WaitGroup{}
server := web.NewServer(ctx, config.Mailroom, db, rp, nil, nil, nil, wg)
server.Start()
Expand Down
20 changes: 15 additions & 5 deletions web/ticket/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
)

func TestTicketAssign(t *testing.T) {
_, _, db, _ := testsuite.Reset()
_, _, db, _ := testsuite.Get()

defer testdata.ResetContactData(db)

testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.DefaultTopic, "Need help", "Have you seen my cookies?", "17", testdata.Admin)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.DefaultTopic, "More help", "Have you seen my cookies?", "21", testdata.Agent)
Expand All @@ -22,7 +24,9 @@ func TestTicketAssign(t *testing.T) {
}

func TestTicketAddNote(t *testing.T) {
_, _, db, _ := testsuite.Reset()
_, _, db, _ := testsuite.Get()

defer testdata.ResetContactData(db)

testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.DefaultTopic, "Need help", "Have you seen my cookies?", "17", testdata.Admin)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.DefaultTopic, "More help", "Have you seen my cookies?", "21", testdata.Agent)
Expand All @@ -32,7 +36,9 @@ func TestTicketAddNote(t *testing.T) {
}

func TestTicketChangeTopic(t *testing.T) {
_, _, db, _ := testsuite.Reset()
_, _, db, _ := testsuite.Get()

defer testdata.ResetContactData(db)

testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.DefaultTopic, "Need help", "Have you seen my cookies?", "17", testdata.Admin)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.SupportTopic, "More help", "Have you seen my cookies?", "21", testdata.Agent)
Expand All @@ -42,7 +48,9 @@ func TestTicketChangeTopic(t *testing.T) {
}

func TestTicketClose(t *testing.T) {
_, _, db, _ := testsuite.Reset()
_, _, db, _ := testsuite.Get()

defer testdata.ResetContactData(db)

// create 2 open tickets and 1 closed one for Cathy across two different ticketers
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Need help", "Have you seen my cookies?", "17", testdata.Admin)
Expand All @@ -54,7 +62,9 @@ func TestTicketClose(t *testing.T) {
}

func TestTicketReopen(t *testing.T) {
_, _, db, _ := testsuite.Reset()
_, _, db, _ := testsuite.Get()

defer testdata.ResetContactData(db)

// create 2 closed tickets and 1 open one for Cathy
testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Need help", "Have you seen my cookies?", "17", testdata.Admin)
Expand Down

0 comments on commit a2f2fca

Please sign in to comment.