-
Notifications
You must be signed in to change notification settings - Fork 13
/
level_test.go
218 lines (199 loc) · 7.92 KB
/
level_test.go
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2024"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateRubricLevels(t *testing.T) {
testRequest := autopilot.NewTestRequest(
`mutation LevelCreate($input:LevelCreateInput!){levelCreate(input: $input){level{alias,description,id,index,name},errors{message,path}}}`,
`{"input": { "name": "Kyle", "description": "Created By Kyle", "index": 4 }}`,
`{"data": { "levelCreate": { "level": { "alias": "kyle", "description": "Created By Kyle", "id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvNDgw", "index": 4, "name": "Kyle" }, "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/level_create", testRequest)
// Act
index := 4
result, _ := client.CreateLevel(ol.LevelCreateInput{
Name: "Kyle",
Description: ol.RefOf("Created By Kyle"),
Index: &index,
})
// Assert
autopilot.Equals(t, "kyle", result.Alias)
autopilot.Equals(t, 4, result.Index)
}
func TestGetRubricLevel(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query LevelGet($id:ID!){account{level(id: $id){alias,description,id,index,name}}}`,
`{"id": "Z2lkOi8vb3BzbGV2ZWwvQ2hlY2tsaXN0LzYyMg"}`,
`{"data": {
"account": {
"level": {
"alias": "bronze",
"description": "Services in this level satisfy critical checks. This is the minimum standard to ship to production.",
"id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzE3",
"index": 1,
"name": "Bronze"
}}}}`,
)
client := BestTestClient(t, "rubric/level_get", testRequest)
// Act
result, err := client.GetLevel("Z2lkOi8vb3BzbGV2ZWwvQ2hlY2tsaXN0LzYyMg")
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, "Bronze", result.Name)
}
func TestGetMissingRubricLevel(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query LevelGet($id:ID!){account{level(id: $id){alias,description,id,index,name}}}`,
`{"id": "Z2lkOi8vb3BzbGV2ZWwvQ2hlY2tsaXN0LzYyMg"}`,
`{"data": { "account": { "level": null }}}`,
)
client := BestTestClient(t, "rubric/level_get_missing", testRequest)
// Act
_, err := client.GetLevel("Z2lkOi8vb3BzbGV2ZWwvQ2hlY2tsaXN0LzYyMg")
// Assert
autopilot.Assert(t, err != nil, "This test should throw an error.")
}
func TestListRubricLevels(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`{account{rubric{levels{nodes{alias,description,id,index,name},{{ template "pagination_request" }},totalCount}}}}`,
`{}`,
`{
"data": {
"account": {
"rubric": {
"levels": {
"nodes": [
{
"alias": "beginner",
"description": "Services in this level are below the minimum standard to ship to production. You should address your failing checks as soon as possible.",
"id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMTAx",
"index": 0,
"name": "Beginner"
},
{
"alias": "bronze",
"description": "Services in this level satisfy critical checks. This is the minimum standard to ship to production.",
"id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzE3",
"index": 1,
"name": "Bronze"
},
{
"alias": "silver",
"description": "Services in this level satisfy important and critical checks. This is considered healthy.",
"id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzE4",
"index": 2,
"name": "Silver"
},
{
"alias": "gold",
"description": "Services in this level satisfy critical, important and useful checks. This is the requirement for your highest tier services but all services should aspire to be in this level.",
"id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvMzE5",
"index": 3,
"name": "Gold"
}
]
}
}
}
}
}`,
)
client := BestTestClient(t, "rubric/level/list", testRequest)
// Act
result, _ := client.ListLevels()
// Assert
autopilot.Equals(t, 4, len(result))
autopilot.Equals(t, "Bronze", result[1].Name)
}
func TestUpdateRubricLevel(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation LevelUpdate($input:LevelUpdateInput!){levelUpdate(input: $input){level{alias,description,id,index,name},errors{message,path}}}`,
`{"input": { {{ template "id1" }}, "name": "{{ template "name1" }}", "description": "{{ template "description" }}" }}`,
`{"data": { "levelUpdate": { "level": {{ template "level_1" }}, "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/level_update", testRequest)
// Act
result, _ := client.UpdateLevel(ol.LevelUpdateInput{
Id: id1,
Name: ol.RefOf("Example"),
Description: ol.RefOf("An example description"),
})
// Assert
autopilot.Equals(t, "example", result.Alias)
autopilot.Equals(t, "Example", result.Name)
autopilot.Equals(t, "An example description", result.Description)
}
func TestUpdateRubricLevelNoName(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation LevelUpdate($input:LevelUpdateInput!){levelUpdate(input: $input){level{alias,description,id,index,name},errors{message,path}}}`,
`{"input": { {{ template "id1" }}, "description": "{{ template "description" }}" } }`,
`{"data": { "levelUpdate": { "level": {{ template "level_1" }}, "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/level_update_noname", testRequest)
// Act
result, _ := client.UpdateLevel(ol.LevelUpdateInput{
Id: id1,
Description: ol.RefOf("An example description"),
})
// Assert
autopilot.Equals(t, "example", result.Alias)
autopilot.Equals(t, "Example", result.Name)
autopilot.Equals(t, "An example description", result.Description)
}
func TestUpdateRubricLevelEmptyDescription(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation LevelUpdate($input:LevelUpdateInput!){levelUpdate(input: $input){level{alias,description,id,index,name},errors{message,path}}}`,
`{"input": { {{ template "id1" }}, "name": "{{ template "name1" }}", "description": "" }}`,
`{"data": { "levelUpdate": { "level": {{ template "level_1" }}, "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/level_update_emptydescription", testRequest)
// Act
result, _ := client.UpdateLevel(ol.LevelUpdateInput{
Id: id1,
Name: ol.RefOf("Example"),
Description: ol.RefOf(""),
})
// Assert
autopilot.Equals(t, "example", result.Alias)
autopilot.Equals(t, "Example", result.Name)
autopilot.Equals(t, "An example description", result.Description)
}
func TestUpdateRubricLevelNoDescription(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation LevelUpdate($input:LevelUpdateInput!){levelUpdate(input: $input){level{alias,description,id,index,name},errors{message,path}}}`,
`{"input": { {{ template "id1" }}, "name": "{{ template "name1" }}" }}`,
`{"data": { "levelUpdate": { "level": {{ template "level_1" }}, "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/level_update_nodescription", testRequest)
// Act
result, _ := client.UpdateLevel(ol.LevelUpdateInput{
Id: id1,
Name: ol.RefOf("Example"),
})
// Assert
autopilot.Equals(t, "example", result.Alias)
autopilot.Equals(t, "Example", result.Name)
autopilot.Equals(t, "An example description", result.Description)
}
func TestDeleteRubricLevels(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation LevelDelete($input:LevelDeleteInput!){levelDelete(input: $input){deletedLevelId,errors{message,path}}}`,
`{"input": { "id": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvNDgw" }}`,
`{"data": { "levelDelete": { "deletedLevelId": "Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvNDgw", "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/level_delete", testRequest)
// Act
err := client.DeleteLevel("Z2lkOi8vb3BzbGV2ZWwvTGV2ZWwvNDgw")
// Assert
autopilot.Equals(t, nil, err)
}