File size: 2,402 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
package smoke
import (
"encoding/json"
"fmt"
"testing"
"github.com/target/goalert/test/smoke/harness"
)
// TestGraphQLUserFavorites tests that services can be set and unset as user favorites
func TestGraphQLUserFavorites(t *testing.T) {
t.Parallel()
sql := `
insert into users (id, name, email)
values
({{uuid "user"}}, 'bob', 'joe');
insert into escalation_policies (id, name)
values
({{uuid "eid"}}, 'esc policy');
insert into services (id, escalation_policy_id, name)
values
({{uuid "sid1"}}, {{uuid "eid"}}, 'service1'),
({{uuid "sid2"}}, {{uuid "eid"}}, 'service2');
`
h := harness.NewHarness(t, sql, "UserFavorites")
defer h.Close()
doQL := func(query string, res interface{}) {
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))
if res == nil {
return
}
err := json.Unmarshal(g.Data, &res)
if err != nil {
t.Fatal(err)
}
}
doQL(fmt.Sprintf(`
mutation{
setFavorite(input:{
target:{
id: "%s"
type: service
}
favorite: true
})
}
`, h.UUID("sid1")), nil)
var s struct {
Service struct {
IsFavorite bool
}
}
doQL(fmt.Sprintf(`
query {
service(id: "%s") {
isFavorite
}
}
`, h.UUID("sid1")), &s)
if s.Service.IsFavorite != true {
t.Fatalf("ERROR: ServiceID %s IsUserFavorite=%t; want true", h.UUID("sid1"), s.Service.IsFavorite)
}
doQL(fmt.Sprintf(`
query {
service(id: "%s") {
isFavorite
}
}
`, h.UUID("sid2")), &s)
if s.Service.IsFavorite != false {
t.Fatalf("ERROR: ServiceID %s IsFavorite=%t; want false", h.UUID("sid2"), s.Service.IsFavorite)
}
// Again Setting as user-favorite should result in no change
doQL(fmt.Sprintf(`
mutation{
setFavorite(input:{
target:{
id: "%s"
type: service
}
favorite: true
})
}
`, h.UUID("sid2")), nil)
doQL(fmt.Sprintf(`
mutation{
setFavorite(input:{
target:{
id: "%s"
type: service
}
favorite: false
})
}
`, h.UUID("sid2")), nil)
doQL(fmt.Sprintf(`
query {
service(id: "%s") {
isFavorite
}
}
`, h.UUID("sid2")), &s)
if s.Service.IsFavorite != false {
t.Fatalf("ERROR: ServiceID %s IsUserFavorite=%t; want false", h.UUID("sid2"), s.Service.IsFavorite)
}
}
|