Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Relay to the GraohQL API query schema #63

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions resources/fixtures/api/default_snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
]
}
],
"relay": {
"type": "NOTIFICATION",
"method": "POST",
"endpoint": "http://localhost:8080/notify",
"description": "",
"activated": true
},
"components": [
"app1"
]
Expand Down
7 changes: 7 additions & 0 deletions src/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ func createQuery(domainId string, environment string) string {
operation
values
}
relay {
type
method
endpoint
description
activated
}
components
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import (
)

const SWITCHER_API_JWT_SECRET = "SWITCHER_API_JWT_SECRET"
const DEFAULT_SNAPSHOT = "../../resources/fixtures/api/default_snapshot.json"
const DEFAULT_SNAPSHOT_INVALID = "../../resources/fixtures/api/error_invalid_domain.json"
const DEFAULT_SNAPSHOT_VERSION = "../../resources/fixtures/api/default_snapshot_version.json"
const DEFAULT_SNAPSHOT_VERSION_INVALID = "../../resources/fixtures/api/error_invalid_domain.json"

func TestFetchSnapshotVersion(t *testing.T) {
t.Run("Should return snapshot version", func(t *testing.T) {
responsePayload := utils.ReadJsonFromFile("../../resources/fixtures/api/default_snapshot_version.json")
responsePayload := utils.ReadJsonFromFile(DEFAULT_SNAPSHOT_VERSION)
fakeApiServer := givenApiResponse(http.StatusOK, responsePayload)
defer fakeApiServer.Close()

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

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

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

func TestFetchSnapshot(t *testing.T) {
t.Run("Should return snapshot", func(t *testing.T) {
responsePayload := utils.ReadJsonFromFile("../../resources/fixtures/api/default_snapshot.json")
responsePayload := utils.ReadJsonFromFile(DEFAULT_SNAPSHOT)
fakeApiServer := givenApiResponse(http.StatusOK, responsePayload)
defer fakeApiServer.Close()

Expand All @@ -68,10 +72,11 @@ func TestFetchSnapshot(t *testing.T) {
assert.Contains(t, snapshot, "version", "Missing version in snapshot")
assert.Contains(t, snapshot, "group", "Missing groups in snapshot")
assert.Contains(t, snapshot, "config", "Missing config in snapshot")
assert.Contains(t, snapshot, "relay", "Missing relay in snapshot")
})

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

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

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

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

Expand Down
Loading