Skip to content

Commit

Permalink
Update test database
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 3, 2022
1 parent cb27b38 commit 7e3f097
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/tasks/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func TestMsgEvents(t *testing.T) {
assertdb.Query(t, db, `SELECT count(*) from flows_flowsession where contact_id = $1 and timeout_on IS NULL`, testdata.Org2Contact.ID).Returns(6)

// force an error by marking our run for fred as complete (our session is still active so this will blow up)
db.MustExec(`UPDATE flows_flowrun SET status = 'C' WHERE contact_id = $1`, testdata.Org2Contact.ID)
db.MustExec(`UPDATE flows_flowrun SET status = 'C', exited_on = NOW() WHERE contact_id = $1`, testdata.Org2Contact.ID)
task = makeMsgTask(testdata.Org2, testdata.Org2Channel, testdata.Org2Contact, "red")
handler.QueueHandleTask(rc, testdata.Org2Contact.ID, task)

Expand Down
Binary file modified mailroom_test.dump
Binary file not shown.
19 changes: 14 additions & 5 deletions testsuite/testdata/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ func InsertFlowSession(db *sqlx.DB, org *Org, contact *Contact, sessionType mode
now := time.Now()
tomorrow := now.Add(time.Hour * 24)

var waitStartedOn, waitExpiresOn *time.Time
var waitStartedOn, waitExpiresOn, endedOn *time.Time
if status == models.SessionStatusWaiting {
waitStartedOn = &now
waitExpiresOn = &tomorrow
} else {
endedOn = &now
}

var id models.SessionID
must(db.Get(&id,
`INSERT INTO flows_flowsession(uuid, org_id, contact_id, status, output, responded, created_on, session_type, current_flow_id, connection_id, wait_started_on, wait_expires_on, wait_resume_on_expire)
VALUES($1, $2, $3, $4, '{}', TRUE, NOW(), $5, $6, $7, $8, $9, FALSE) RETURNING id`, uuids.New(), org.ID, contact.ID, status, sessionType, currentFlow.ID, connectionID, waitStartedOn, waitExpiresOn,
`INSERT INTO flows_flowsession(uuid, org_id, contact_id, status, output, responded, created_on, session_type, current_flow_id, connection_id, wait_started_on, wait_expires_on, wait_resume_on_expire, ended_on)
VALUES($1, $2, $3, $4, '{}', TRUE, NOW(), $5, $6, $7, $8, $9, FALSE, $10) RETURNING id`, uuids.New(), org.ID, contact.ID, status, sessionType, currentFlow.ID, connectionID, waitStartedOn, waitExpiresOn, endedOn,
))
return id
}
Expand All @@ -114,10 +116,17 @@ func InsertWaitingSession(db *sqlx.DB, org *Org, contact *Contact, sessionType m

// InsertFlowRun inserts a flow run
func InsertFlowRun(db *sqlx.DB, org *Org, sessionID models.SessionID, contact *Contact, flow *Flow, status models.RunStatus) models.FlowRunID {
now := time.Now()

var exitedOn *time.Time
if status != models.RunStatusActive && status != models.RunStatusWaiting {
exitedOn = &now
}

var id models.FlowRunID
must(db.Get(&id,
`INSERT INTO flows_flowrun(uuid, org_id, session_id, contact_id, flow_id, status, responded, created_on, modified_on)
VALUES($1, $2, $3, $4, $5, $6, TRUE, NOW(), NOW()) RETURNING id`, uuids.New(), org.ID, null.Int(sessionID), contact.ID, flow.ID, status,
`INSERT INTO flows_flowrun(uuid, org_id, session_id, contact_id, flow_id, status, responded, created_on, modified_on, exited_on)
VALUES($1, $2, $3, $4, $5, $6, TRUE, NOW(), NOW(), $7) RETURNING id`, uuids.New(), org.ID, null.Int(sessionID), contact.ID, flow.ID, status, exitedOn,
))
return id
}

0 comments on commit 7e3f097

Please # to comment.