Skip to content

Commit

Permalink
Tweak new field name, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Mar 31, 2022
1 parent 6aea69d commit bace1d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions indexers/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM (
) AS flow,
current_flow_id AS flow_id,
(
SELECT array_to_json(array_agg(DISTINCT fr.flow_id))
FROM flows_flowrun fr WHERE fr.contact_id = contacts_contact.id
) AS flow_history
SELECT array_to_json(array_agg(DISTINCT fr.flow_id)) FROM flows_flowrun fr WHERE fr.contact_id = contacts_contact.id
) AS flow_history_ids
FROM contacts_contact
WHERE modified_on >= $1
ORDER BY modified_on ASC
Expand Down
2 changes: 1 addition & 1 deletion indexers/contacts.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"flow_id": {
"type": "integer"
},
"flow_history": {
"flow_history_ids": {
"type": "integer"
},
"tickets": {
Expand Down
2 changes: 2 additions & 0 deletions indexers/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var contactQueryTests = []struct {
{elastic.NewMatchQuery("flow", "4eea8ff1-4fe2-4ce5-92a4-0870a499973a"), []int64{4}},
{elastic.NewMatchQuery("flow_id", 1), []int64{2, 3}},
{elastic.NewMatchQuery("flow_id", 2), []int64{4}},
{elastic.NewMatchQuery("flow_history_ids", 1), []int64{1, 2, 3}},
{elastic.NewMatchQuery("flow_history_ids", 2), []int64{1, 2}},
{elastic.NewRangeQuery("created_on").Gt("2017-01-01"), []int64{1, 6, 8}}, // created_on range
{elastic.NewRangeQuery("last_seen_on").Lt("2019-01-01"), []int64{3, 4}}, // last_seen_on range
{elastic.NewExistsQuery("last_seen_on"), []int64{1, 2, 3, 4, 5, 6}}, // last_seen_on is set
Expand Down
4 changes: 3 additions & 1 deletion testdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,6 @@ INSERT INTO flows_flowrun(id, uuid, flow_id, contact_id) VALUES
(1, '8b30ee61-e19d-427e-bb9f-4b8cd2c31d0c', 1, 1),
(2, '94639979-155e-444d-95e9-a39dad64dbd5', 1, 1),
(3, '74d918df-0e31-4547-98a9-5d765450e2ac', 2, 1),
(4, '14fdf8fc-6e02-4759-b9be-cacc5991cd14', 1, 2);
(4, '14fdf8fc-6e02-4759-b9be-cacc5991cd14', 1, 2),
(5, '5171b4d8-e9bb-46c1-901e-53e13f3afe5d', 2, 2),
(6, '4cc84e32-910f-41d6-865d-63fe25db4cde', 1, 3);

0 comments on commit bace1d5

Please sign in to comment.