-
Notifications
You must be signed in to change notification settings - Fork 13
/
category_test.go
116 lines (106 loc) · 4.41 KB
/
category_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
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2024"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation CategoryCreate($input:CategoryCreateInput!){categoryCreate(input: $input){category{id,name},errors{message,path}}}`,
`{ "input": { "name": "Kyle" }}`,
`{"data": { "categoryCreate": { "category": { {{ template "id1" }}, "name": "Kyle" }, "errors": [] } }}`,
)
client := BestTestClient(t, "rubric/category_create", testRequest)
// Act
result, _ := client.CreateCategory(ol.CategoryCreateInput{
Name: "Kyle",
})
// Assert
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "Kyle", result.Name)
}
func TestGetRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query CategoryGet($id:ID!){account{category(id: $id){id,name}}}`,
`{ {{ template "id2" }} }`,
`{"data": { "account": { "category": { {{ template "id3" }}, "name": "Reliability" } }}}`,
)
client := BestTestClient(t, "rubric/category_get", testRequest)
// Act
result, err := client.GetCategory(id2)
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id3, result.Id)
autopilot.Equals(t, "Reliability", result.Name)
}
func TestGetMissingRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query CategoryGet($id:ID!){account{category(id: $id){id,name}}}`,
`{ {{ template "id1" }} }`,
`{"data": { "account": { "category": null }}}`,
)
client := BestTestClient(t, "rubric/category_get_missing", testRequest)
// Act
_, err := client.GetCategory(id1)
// Assert
autopilot.Assert(t, err != nil, "This test should throw an error.")
}
func TestListRubricCategories(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},{{ template "pagination_request" }},totalCount}}}}`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response1" }} }, { {{ template "rubric_categories_response2" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},{{ template "pagination_request" }},totalCount}}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response3" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
requests := []autopilot.TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "rubric/category_list", requests...)
// Act
response, err := client.ListCategories(nil)
result := response.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, response.TotalCount)
autopilot.Equals(t, "🟢 Reliability", result[1].Name)
autopilot.Equals(t, "🔍 Observability", result[2].Name)
// fmt.Println(Templated(requests[0].Request))
// panic(true)
}
func TestUpdateRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation CategoryUpdate($input:CategoryUpdateInput!){categoryUpdate(input: $input){category{id,name},errors{message,path}}}`,
`{ "input": { {{ template "id4" }}, "name": "Emily" }}`,
`{"data": { "categoryUpdate": { "category": { {{ template "id4" }}, "name": "Emily" }, "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/category_update", testRequest)
// Act
result, err := client.UpdateCategory(ol.CategoryUpdateInput{
Id: id4,
Name: ol.RefOf("Emily"),
})
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id4, result.Id)
autopilot.Equals(t, "Emily", result.Name)
}
func TestDeleteRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation CategoryDelete($input:CategoryDeleteInput!){categoryDelete(input: $input){deletedCategoryId,errors{message,path}}}`,
`{ "input": { {{ template "id2" }} }}`,
`{"data": { "categoryDelete": { "deletedCategoryId": "{{ template "id2_string" }}", "errors": [] }}}`,
)
client := BestTestClient(t, "rubric/category_delete", testRequest)
// Act
err := client.DeleteCategory(id2)
// Assert
autopilot.Equals(t, nil, err)
}