Skip to content

Commit

Permalink
Have TicketRecordReplied update last_activity_on to avoid making two …
Browse files Browse the repository at this point in the history
…db updates
  • Loading branch information
rowanseymour committed May 18, 2022
1 parent 26705d9 commit 3a6fd21
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 71 deletions.
6 changes: 3 additions & 3 deletions core/models/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func TestContacts(t *testing.T) {
defer testsuite.Reset(testsuite.ResetAll)

testdata.InsertContactURN(db, testdata.Org1, testdata.Bob, "whatsapp:250788373373", 999)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SupportTopic, "Where are my shoes?", "1234", testdata.Agent)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SalesTopic, "Where are my pants?", "2345", nil)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "His name is Bob", "", testdata.Editor)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SupportTopic, "Where are my shoes?", "1234", time.Now(), testdata.Agent)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SalesTopic, "Where are my pants?", "2345", time.Now(), nil)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "His name is Bob", "", time.Now(), testdata.Editor)

// delete mailgun ticketer
db.MustExec(`UPDATE tickets_ticketer SET is_active = false WHERE id = $1`, testdata.Mailgun.ID)
Expand Down
6 changes: 3 additions & 3 deletions core/models/counts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ type dailyTiming struct {

const sqlInsertDailyTiming = `INSERT INTO %s(count_type, scope, day, count, seconds, is_squashed) VALUES(:count_type, :scope, :day, :count, :seconds, FALSE)`

func insertDailyTiming(ctx context.Context, tx Queryer, table string, countType TicketDailyTimingType, tz *time.Location, scope string, count int, seconds int64) error {
func insertDailyTiming(ctx context.Context, tx Queryer, table string, countType TicketDailyTimingType, tz *time.Location, scope string, duration time.Duration) error {
day := dates.ExtractDate(dates.Now().In(tz))
timing := &dailyTiming{
dailyCount: dailyCount{
scopedCount: scopedCount{
CountType: string(countType),
Scope: scope,
Count: count,
Count: 1,
},
Day: day,
},
Seconds: 0,
Seconds: int64(duration / time.Second),
}

_, err := tx.NamedExecContext(ctx, fmt.Sprintf(sqlInsertDailyTiming, table), timing)
Expand Down
12 changes: 4 additions & 8 deletions core/models/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,9 +1157,9 @@ func CreateBroadcastMessages(ctx context.Context, rt *runtime.Runtime, oa *OrgAs
}

func (b *BroadcastBatch) updateTicket(ctx context.Context, db Queryer, oa *OrgAssets) error {
err := updateTicketLastActivity(ctx, db, []TicketID{b.TicketID()}, dates.Now())
firstReplySeconds, err := TicketRecordReplied(ctx, db, b.TicketID(), dates.Now())
if err != nil {
return errors.Wrapf(err, "error updating broadcast ticket")
return err
}

// record reply counts for org, user and team
Expand All @@ -1179,12 +1179,8 @@ func (b *BroadcastBatch) updateTicket(ctx context.Context, db Queryer, oa *OrgAs
return err
}

seconds, err := TicketRecordReplied(ctx, db, b.TicketID(), dates.Now())
if err != nil {
return err
}
if seconds >= 0 {
if err := insertTicketDailyTiming(ctx, db, TicketDailyTimingFirstReply, oa.Org().Timezone(), scopeOrg(oa), 1, seconds); err != nil {
if firstReplySeconds >= 0 {
if err := insertTicketDailyTiming(ctx, db, TicketDailyTimingFirstReply, oa.Org().Timezone(), scopeOrg(oa), firstReplySeconds); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/models/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func TestNonPersistentBroadcasts(t *testing.T) {

defer testsuite.Reset(testsuite.ResetData)

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "", "", nil)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Bob, testdata.Mailgun, testdata.DefaultTopic, "", "", time.Now(), nil)
modelTicket := ticket.Load(db)

translations := map[envs.Language]*models.BroadcastTranslation{envs.Language("eng"): {Text: "Hi there"}}
Expand Down
2 changes: 1 addition & 1 deletion core/models/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func assertNotifications(t *testing.T, ctx context.Context, db *sqlx.DB, after t
}

func openTicket(t *testing.T, ctx context.Context, db *sqlx.DB, openedBy *testdata.User, assignee *testdata.User) (*models.Ticket, *models.TicketEvent) {
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.SupportTopic, "Where my pants", "", assignee)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Internal, testdata.SupportTopic, "Where my pants", "", time.Now(), assignee)
modelTicket := ticket.Load(db)

openedEvent := models.NewTicketOpenedEvent(modelTicket, openedBy.SafeID(), assignee.SafeID())
Expand Down
3 changes: 2 additions & 1 deletion core/models/ticket_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models_test

import (
"testing"
"time"

"github.com/nyaruka/gocommon/dbutil/assertdb"
"github.com/nyaruka/mailroom/core/models"
Expand All @@ -17,7 +18,7 @@ func TestTicketEvents(t *testing.T) {

defer testsuite.Reset(testsuite.ResetData)

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Have you seen my cookies?", "17", nil)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Have you seen my cookies?", "17", time.Now(), nil)
modelTicket := ticket.Load(db)

e1 := models.NewTicketOpenedEvent(modelTicket, testdata.Admin.ID, testdata.Agent.ID)
Expand Down
31 changes: 19 additions & 12 deletions core/models/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (t *Ticket) Status() TicketStatus { return t.t.Status }
func (t *Ticket) TopicID() TopicID { return t.t.TopicID }
func (t *Ticket) Body() string { return t.t.Body }
func (t *Ticket) AssigneeID() UserID { return t.t.AssigneeID }
func (t *Ticket) RepliedOn() *time.Time { return t.t.RepliedOn }
func (t *Ticket) LastActivityOn() time.Time { return t.t.LastActivityOn }
func (t *Ticket) Config(key string) string {
return t.t.Config.GetString(key, "")
Expand Down Expand Up @@ -699,14 +700,16 @@ func recalcGroupsForTicketChanges(ctx context.Context, db Queryer, oa *OrgAssets
}

const sqlUpdateTicketRepliedOn = `
UPDATE tickets_ticket
SET replied_on = $2
WHERE id = $1 AND replied_on IS NOT NULL
RETURNING EXTRACT(EPOCH FROM (replied_on - opened_on))`

// TicketRecordReplied records a ticket as being replied to, returning the number of seconds between the reply
// and the ticket being opened, if this is
func TicketRecordReplied(ctx context.Context, db Queryer, ticketID TicketID, when time.Time) (int64, error) {
UPDATE tickets_ticket t1
SET last_activity_on = $2, replied_on = LEAST(t1.replied_on, $2)
FROM tickets_ticket t2
WHERE t1.id = t2.id AND t1.id = $1
RETURNING CASE WHEN t2.replied_on IS NULL THEN EXTRACT(EPOCH FROM (t1.replied_on - t1.opened_on)) ELSE NULL END`

// TicketRecordReplied records a ticket as being replied to, updating last_activity_on. If this is the first reply
// to this ticket then replied_on is updated and the function returns the number of seconds between that and when
// the ticket was opened.
func TicketRecordReplied(ctx context.Context, db Queryer, ticketID TicketID, when time.Time) (time.Duration, error) {
rows, err := db.QueryxContext(ctx, sqlUpdateTicketRepliedOn, ticketID, when)
if err != nil && err != sql.ErrNoRows {
return -1, err
Expand All @@ -719,12 +722,16 @@ func TicketRecordReplied(ctx context.Context, db Queryer, ticketID TicketID, whe
return -1, nil
}

var seconds int64
var seconds *float64
if err := rows.Scan(&seconds); err != nil {
return -1, err
}

return seconds, nil
if seconds != nil {
return time.Duration(*seconds * float64(time.Second)), nil
}

return time.Duration(-1), nil
}

// Ticketer is our type for a ticketer asset
Expand Down Expand Up @@ -915,6 +922,6 @@ func insertTicketDailyCounts(ctx context.Context, tx Queryer, countType TicketDa
return insertDailyCounts(ctx, tx, "tickets_ticketdailycount", countType, tz, scopeCounts)
}

func insertTicketDailyTiming(ctx context.Context, tx Queryer, countType TicketDailyTimingType, tz *time.Location, scope string, count int, seconds int64) error {
return insertDailyTiming(ctx, tx, "tickets_ticketdailytiming", countType, tz, scope, count, seconds)
func insertTicketDailyTiming(ctx context.Context, tx Queryer, countType TicketDailyTimingType, tz *time.Location, scope string, duration time.Duration) error {
return insertDailyTiming(ctx, tx, "tickets_ticketdailytiming", countType, tz, scope, duration)
}
66 changes: 51 additions & 15 deletions core/models/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestUpdateTicketConfig(t *testing.T) {

defer testsuite.Reset(testsuite.ResetData)

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", nil)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", time.Now(), nil)
modelTicket := ticket.Load(db)

// empty configs are null
Expand All @@ -171,19 +171,19 @@ func TestUpdateTicketLastActivity(t *testing.T) {

defer testsuite.Reset(testsuite.ResetData)

now := time.Date(2021, 6, 22, 15, 59, 30, 123456789, time.UTC)
now := time.Date(2021, 6, 22, 15, 59, 30, 123456000, time.UTC)

defer dates.SetNowSource(dates.DefaultNowSource)
dates.SetNowSource(dates.NewFixedNowSource(now))

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", nil)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", time.Now(), nil)
modelTicket := ticket.Load(db)

models.UpdateTicketLastActivity(ctx, db, []*models.Ticket{modelTicket})

assert.Equal(t, now, modelTicket.LastActivityOn())

assertdb.Query(t, db, `SELECT count(*) FROM tickets_ticket WHERE id = $1 AND last_activity_on = $2`, ticket.ID, modelTicket.LastActivityOn()).Returns(1)
assertdb.Query(t, db, `SELECT last_activity_on FROM tickets_ticket WHERE id = $1`, ticket.ID).Returns(modelTicket.LastActivityOn())

}

Expand All @@ -198,14 +198,14 @@ func TestTicketsAssign(t *testing.T) {
ticket1 := testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", nil)
modelTicket1 := ticket1.Load(db)

ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "234", nil)
ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "234", time.Now(), nil)
modelTicket2 := ticket2.Load(db)

// create ticket already assigned to a user
ticket3 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my glasses", "", testdata.Admin)
ticket3 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my glasses", "", time.Now(), testdata.Admin)
modelTicket3 := ticket3.Load(db)

testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", nil)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", time.Now(), nil)

evts, err := models.TicketsAssign(ctx, db, oa, testdata.Admin.ID, []*models.Ticket{modelTicket1, modelTicket2, modelTicket3}, testdata.Agent.ID, "please handle these")
require.NoError(t, err)
Expand Down Expand Up @@ -239,10 +239,10 @@ func TestTicketsAddNote(t *testing.T) {
ticket1 := testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", nil)
modelTicket1 := ticket1.Load(db)

ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "234", testdata.Agent)
ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "234", time.Now(), testdata.Agent)
modelTicket2 := ticket2.Load(db)

testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", nil)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", time.Now(), nil)

evts, err := models.TicketsAddNote(ctx, db, oa, testdata.Admin.ID, []*models.Ticket{modelTicket1, modelTicket2}, "spam")
require.NoError(t, err)
Expand All @@ -267,13 +267,13 @@ func TestTicketsChangeTopic(t *testing.T) {
ticket1 := testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.SalesTopic, "Where my shoes", "123", nil)
modelTicket1 := ticket1.Load(db)

ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SupportTopic, "Where my pants", "234", nil)
ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.SupportTopic, "Where my pants", "234", time.Now(), nil)
modelTicket2 := ticket2.Load(db)

ticket3 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "345", nil)
ticket3 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "345", time.Now(), nil)
modelTicket3 := ticket3.Load(db)

testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", nil)
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", time.Now(), nil)

evts, err := models.TicketsChangeTopic(ctx, db, oa, testdata.Admin.ID, []*models.Ticket{modelTicket1, modelTicket2, modelTicket3}, testdata.SupportTopic.ID)
require.NoError(t, err)
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestCloseTickets(t *testing.T) {
oa, err := models.GetOrgAssetsWithRefresh(ctx, rt, testdata.Org1.ID, models.RefreshTicketers|models.RefreshGroups)
require.NoError(t, err)

ticket1 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", nil)
ticket1 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", time.Now(), nil)
modelTicket1 := ticket1.Load(db)

ticket2 := testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "234", nil)
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestCloseTickets(t *testing.T) {
assertdb.Query(t, db, `SELECT count(*) FROM tickets_ticketevent WHERE ticket_id = $1 AND event_type = 'C'`, ticket2.ID).Returns(0)

// can close tickets without a user
ticket3 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", nil)
ticket3 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", time.Now(), nil)
modelTicket3 := ticket3.Load(db)

evts, err = models.CloseTickets(ctx, rt, oa, models.NilUserID, []*models.Ticket{modelTicket3}, false, false, logger)
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestReopenTickets(t *testing.T) {
ticket1 := testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", nil)
modelTicket1 := ticket1.Load(db)

ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "234", nil)
ticket2 := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Where my pants", "234", time.Now(), nil)
modelTicket2 := ticket2.Load(db)

logger := &models.HTTPLogger{}
Expand Down Expand Up @@ -410,6 +410,42 @@ func TestReopenTickets(t *testing.T) {
assertTicketDailyCount(t, db, models.TicketDailyCountOpening, fmt.Sprintf("o:%d", testdata.Org1.ID), 0)
}

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

defer testsuite.Reset(testsuite.ResetData)

openedOn := time.Date(2022, 5, 18, 14, 21, 0, 0, time.UTC)
repliedOn := time.Date(2022, 5, 18, 15, 0, 0, 0, time.UTC)

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Where my shoes", "123", openedOn, nil)

timing, err := models.TicketRecordReplied(ctx, db, ticket.ID, repliedOn)
assert.NoError(t, err)
assert.Equal(t, 2340*time.Second, timing)

modelTicket := ticket.Load(db)
assert.Equal(t, repliedOn, *modelTicket.RepliedOn())
assert.Equal(t, repliedOn, modelTicket.LastActivityOn())

assertdb.Query(t, db, `SELECT replied_on FROM tickets_ticket WHERE id = $1`, ticket.ID).Returns(repliedOn)
assertdb.Query(t, db, `SELECT last_activity_on FROM tickets_ticket WHERE id = $1`, ticket.ID).Returns(repliedOn)

repliedAgainOn := time.Date(2022, 5, 18, 15, 5, 0, 0, time.UTC)

// if we call it again, it won't change replied_on again but it will update last_activity_on
timing, err = models.TicketRecordReplied(ctx, db, ticket.ID, repliedAgainOn)
assert.NoError(t, err)
assert.Equal(t, time.Duration(-1), timing)

modelTicket = ticket.Load(db)
assert.Equal(t, repliedOn, *modelTicket.RepliedOn())
assert.Equal(t, repliedAgainOn, modelTicket.LastActivityOn())

assertdb.Query(t, db, `SELECT replied_on FROM tickets_ticket WHERE id = $1`, ticket.ID).Returns(repliedOn)
assertdb.Query(t, db, `SELECT last_activity_on FROM tickets_ticket WHERE id = $1`, ticket.ID).Returns(repliedAgainOn)
}

func assertTicketDailyCount(t *testing.T, db *sqlx.DB, countType models.TicketDailyCountType, scope string, expected int) {
assertdb.Query(t, db, `SELECT COALESCE(SUM(count), 0) FROM tickets_ticketdailycount WHERE count_type = $1 AND scope = $2`, countType, scope).Returns(expected)
}
4 changes: 2 additions & 2 deletions core/tasks/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestMsgEvents(t *testing.T) {
// give Cathy and Bob some tickets...
openTickets := map[*testdata.Contact][]*testdata.Ticket{
testdata.Cathy: {
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Ok", "", nil),
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Ok", "", nil),
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "Ok", "", time.Now(), nil),
testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Zendesk, testdata.DefaultTopic, "Ok", "", time.Now(), nil),
},
}
closedTickets := map[*testdata.Contact][]*testdata.Ticket{
Expand Down
8 changes: 6 additions & 2 deletions core/tasks/msgs/send_broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestBroadcastTask(t *testing.T) {
// insert a broadcast so we can check it is being set to sent
legacyID := testdata.InsertBroadcast(db, testdata.Org1, "base", map[envs.Language]string{"base": "hi @(PROPER(contact.name)) legacy"}, models.NilScheduleID, nil, nil)

ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", nil)
ticket := testdata.InsertOpenTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.DefaultTopic, "", "", time.Now(), nil)
modelTicket := ticket.Load(db)

evaluated := map[envs.Language]*models.BroadcastTranslation{
Expand Down Expand Up @@ -272,10 +272,12 @@ func TestBroadcastTask(t *testing.T) {
Returns(1, "%d: broadcast not marked as sent", i)
}

// if we had a ticket, make sure its last_activity_on was updated
// if we had a ticket, make sure its replied_on and last_activity_on were updated
if tc.TicketID != models.NilTicketID {
assertdb.Query(t, db, `SELECT count(*) FROM tickets_ticket WHERE id = $1 AND last_activity_on > $2`, tc.TicketID, modelTicket.LastActivityOn()).
Returns(1, "%d: ticket last_activity_on not updated", i)
assertdb.Query(t, db, `SELECT count(*) FROM tickets_ticket WHERE id = $1 AND replied_on IS NOT NULL`, tc.TicketID).
Returns(1, "%d: ticket replied_on not updated", i)
}

lastNow = time.Now()
Expand All @@ -284,4 +286,6 @@ func TestBroadcastTask(t *testing.T) {

assertdb.Query(t, db, `SELECT SUM(count) FROM tickets_ticketdailycount WHERE count_type = 'R' AND scope = CONCAT('o:', $1::text)`, testdata.Org1.ID).Returns(1)
assertdb.Query(t, db, `SELECT SUM(count) FROM tickets_ticketdailycount WHERE count_type = 'R' AND scope = CONCAT('o:', $1::text, ':u:', $2::text)`, testdata.Org1.ID, testdata.Agent.ID).Returns(1)

assertdb.Query(t, db, `SELECT SUM(count) FROM tickets_ticketdailytiming WHERE count_type = 'R' AND scope = CONCAT('o:', $1::text)`, testdata.Org1.ID).Returns(1)
}
Loading

0 comments on commit 3a6fd21

Please sign in to comment.