Skip to content

Commit 58891d6

Browse files
authored
Added Relay to the GraohQL API query schema (#63)
1 parent 112d691 commit 58891d6

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

resources/fixtures/api/default_snapshot.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
]
2424
}
2525
],
26+
"relay": {
27+
"type": "NOTIFICATION",
28+
"method": "POST",
29+
"endpoint": "http://localhost:8080/notify",
30+
"description": "",
31+
"activated": true
32+
},
2633
"components": [
2734
"app1"
2835
]

src/core/api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ func createQuery(domainId string, environment string) string {
221221
operation
222222
values
223223
}
224+
relay {
225+
type
226+
method
227+
endpoint
228+
description
229+
activated
230+
}
224231
components
225232
}
226233
}

src/core/api_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ import (
1212
)
1313

1414
const SWITCHER_API_JWT_SECRET = "SWITCHER_API_JWT_SECRET"
15+
const DEFAULT_SNAPSHOT = "../../resources/fixtures/api/default_snapshot.json"
16+
const DEFAULT_SNAPSHOT_INVALID = "../../resources/fixtures/api/error_invalid_domain.json"
17+
const DEFAULT_SNAPSHOT_VERSION = "../../resources/fixtures/api/default_snapshot_version.json"
18+
const DEFAULT_SNAPSHOT_VERSION_INVALID = "../../resources/fixtures/api/error_invalid_domain.json"
1519

1620
func TestFetchSnapshotVersion(t *testing.T) {
1721
t.Run("Should return snapshot version", func(t *testing.T) {
18-
responsePayload := utils.ReadJsonFromFile("../../resources/fixtures/api/default_snapshot_version.json")
22+
responsePayload := utils.ReadJsonFromFile(DEFAULT_SNAPSHOT_VERSION)
1923
fakeApiServer := givenApiResponse(http.StatusOK, responsePayload)
2024
defer fakeApiServer.Close()
2125

@@ -37,7 +41,7 @@ func TestFetchSnapshotVersion(t *testing.T) {
3741
})
3842

3943
t.Run("Should return error - invalid domain", func(t *testing.T) {
40-
responsePayload := utils.ReadJsonFromFile("../../resources/fixtures/api/error_invalid_domain.json")
44+
responsePayload := utils.ReadJsonFromFile(DEFAULT_SNAPSHOT_VERSION_INVALID)
4145
fakeApiServer := givenApiResponse(http.StatusUnauthorized, responsePayload)
4246
defer fakeApiServer.Close()
4347

@@ -57,7 +61,7 @@ func TestFetchSnapshotVersion(t *testing.T) {
5761

5862
func TestFetchSnapshot(t *testing.T) {
5963
t.Run("Should return snapshot", func(t *testing.T) {
60-
responsePayload := utils.ReadJsonFromFile("../../resources/fixtures/api/default_snapshot.json")
64+
responsePayload := utils.ReadJsonFromFile(DEFAULT_SNAPSHOT)
6165
fakeApiServer := givenApiResponse(http.StatusOK, responsePayload)
6266
defer fakeApiServer.Close()
6367

@@ -68,10 +72,11 @@ func TestFetchSnapshot(t *testing.T) {
6872
assert.Contains(t, snapshot, "version", "Missing version in snapshot")
6973
assert.Contains(t, snapshot, "group", "Missing groups in snapshot")
7074
assert.Contains(t, snapshot, "config", "Missing config in snapshot")
75+
assert.Contains(t, snapshot, "relay", "Missing relay in snapshot")
7176
})
7277

7378
t.Run("Should return data from snapshot", func(t *testing.T) {
74-
responsePayload := utils.ReadJsonFromFile("../../resources/fixtures/api/default_snapshot.json")
79+
responsePayload := utils.ReadJsonFromFile(DEFAULT_SNAPSHOT)
7580
fakeApiServer := givenApiResponse(http.StatusOK, responsePayload)
7681
defer fakeApiServer.Close()
7782

@@ -82,6 +87,9 @@ func TestFetchSnapshot(t *testing.T) {
8287
assert.NotNil(t, data.Snapshot.Domain, "domain", "Missing domain in data")
8388
assert.NotNil(t, data.Snapshot.Domain.Group, "group", "Missing groups in data")
8489
assert.NotNil(t, data.Snapshot.Domain.Group[0].Config, "config", "Missing config in data")
90+
assert.NotNil(t, data.Snapshot.Domain.Group[0].Config[0].Strategies, "strategies", "Missing strategies in data")
91+
assert.NotNil(t, data.Snapshot.Domain.Group[0].Config[0].Relay, "relay", "Missing relay in data")
92+
assert.Contains(t, data.Snapshot.Domain.Group[0].Config[0].Relay.Type, "NOTIFICATION", "Missing relay type in data")
8593
})
8694

8795
t.Run("Should return error - invalid API key", func(t *testing.T) {
@@ -95,7 +103,7 @@ func TestFetchSnapshot(t *testing.T) {
95103
})
96104

97105
t.Run("Should return error - invalid domain", func(t *testing.T) {
98-
responsePayload := utils.ReadJsonFromFile("../../resources/fixtures/api/error_invalid_domain.json")
106+
responsePayload := utils.ReadJsonFromFile(DEFAULT_SNAPSHOT_INVALID)
99107
fakeApiServer := givenApiResponse(http.StatusUnauthorized, responsePayload)
100108
defer fakeApiServer.Close()
101109

0 commit comments

Comments
 (0)