Skip to content

Commit

Permalink
More tests and fix loading of tickets with topics
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 26, 2021
1 parent 2a38d81 commit e50667d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/models/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -181,6 +182,7 @@ SELECT
t.ticketer_id AS ticketer_id,
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
Expand Down Expand Up @@ -210,6 +212,7 @@ SELECT
t.ticketer_id AS ticketer_id,
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
Expand Down Expand Up @@ -258,6 +261,7 @@ SELECT
t.ticketer_id AS ticketer_id,
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
Expand Down Expand Up @@ -286,6 +290,7 @@ SELECT
t.ticketer_id AS ticketer_id,
t.external_id AS external_id,
t.status AS status,
t.topic_id AS topic_id,
t.subject AS subject,
t.body AS body,
t.assignee_id AS assignee_id,
Expand Down Expand Up @@ -468,7 +473,10 @@ func TicketsChangeTopic(ctx context.Context, db Queryer, oa *OrgAssets, userID U
eventsByTicket := make(map[*Ticket]*TicketEvent, len(tickets))
now := dates.Now()

fmt.Printf("TicketsChangeTopic topic=%d\n", topicID)

for _, ticket := range tickets {
fmt.Printf("ticket #%d topic=%d\n", ticket.ID(), ticket.TopicID())
if ticket.TopicID() != topicID {
ids = append(ids, ticket.ID())
t := &ticket.t
Expand Down
32 changes: 31 additions & 1 deletion core/models/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestUpdateTicketLastActivity(t *testing.T) {

}

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

defer deleteTickets(db)
Expand Down Expand Up @@ -237,6 +237,36 @@ func TestTicketsAddNote(t *testing.T) {
testsuite.AssertQuery(t, db, `SELECT count(*) FROM tickets_ticketevent WHERE event_type = 'N' AND note = 'spam'`).Returns(2)
}

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

defer deleteTickets(db)

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

ticket1 := testdata.InsertClosedTicket(db, testdata.Org1, testdata.Cathy, testdata.Mailgun, testdata.SalesTopic, "Problem", "Where my shoes", "123", nil)
modelTicket1 := ticket1.Load(db)

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

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

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

evts, err := models.TicketsChangeTopic(ctx, db, oa, testdata.Admin.ID, []*models.Ticket{modelTicket1, modelTicket2, modelTicket3}, testdata.SupportTopic.ID)
require.NoError(t, err)
assert.Equal(t, 2, len(evts)) // ticket 2 not included as already has that topic
assert.Equal(t, models.TicketEventTypeTopicChanged, evts[modelTicket1].EventType())
assert.Equal(t, models.TicketEventTypeTopicChanged, evts[modelTicket3].EventType())

// check tickets are updated and we have events
testsuite.AssertQuery(t, db, `SELECT count(*) FROM tickets_ticket WHERE topic_id = $1`, testdata.SupportTopic.ID).Returns(3)
testsuite.AssertQuery(t, db, `SELECT count(*) FROM tickets_ticketevent WHERE event_type = 'T' AND topic_id = $1`, testdata.SupportTopic.ID).Returns(2)
}

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

Expand Down

0 comments on commit e50667d

Please sign in to comment.