File size: 1,809 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package smoke

import (
	"fmt"
	"testing"
	"time"

	"github.com/target/goalert/test/smoke/harness"
)

// TestGraphQLDedup tests that creating and closing an alert with a dedup key works.
func TestGraphQLDedup(t *testing.T) {
	t.Parallel()

	sql := `
	insert into users (id, name, email) 
	values 
		({{uuid "user"}}, 'bob', 'joe');
	insert into user_contact_methods (id, user_id, name, type, value) 
	values
		({{uuid "cm"}}, {{uuid "user"}}, 'personal', 'SMS', {{phone "1"}});

	insert into user_notification_rules (user_id, contact_method_id, delay_minutes) 
	values
		({{uuid "user"}}, {{uuid "cm"}}, 0);

	insert into escalation_policies (id, name, repeat)
	values
		({{uuid "eid"}}, 'esc policy', 5);
	insert into escalation_policy_steps (id, escalation_policy_id, delay) 
	values
		({{uuid "esid"}}, {{uuid "eid"}}, 10);
	insert into escalation_policy_actions (escalation_policy_step_id, user_id) 
	values 
		({{uuid "esid"}}, {{uuid "user"}});

	insert into services (id, escalation_policy_id, name) 
	values
		({{uuid "sid"}}, {{uuid "eid"}}, 'service');
`

	h := harness.NewHarness(t, sql, "ids-to-uuids")
	defer h.Close()

	doQL := func(query string) {
		g := h.GraphQLQuery2(query)
		for _, err := range g.Errors {
			t.Error("GraphQL Error:", err.Message)
		}
		if len(g.Errors) > 0 {
			t.Fatal("errors returned from GraphQL")
		}
		t.Log("Response:", string(g.Data))
	}

	doQL(fmt.Sprintf(`mutation{createAlert(input: {summary: "foo", serviceID: "%s", dedup: "somekey1"}){id}}`, h.UUID("sid")))

	h.Twilio(t).Device(h.Phone("1")).ExpectSMS("foo")

	h.FastForward(10 * time.Minute)

	h.Twilio(t).Device(h.Phone("1")).ExpectSMS("foo")

	doQL(fmt.Sprintf(`mutation{closeMatchingAlert(input:{serviceID: "%s", dedup:"somekey1"})}`, h.UUID("sid")))

	h.FastForward(10 * time.Minute)

	// no new sms
}