Skip to content

Commit

Permalink
PR FIXUP - Fix subscription tests
Browse files Browse the repository at this point in the history
Sorry about the late change, there was a bug in the subscription mapping from the old system that resulted in these silently passing.  It proved inconvienent to fix in the mapping as the old system did not specify the results for the triggering mutations which are required in the new system.  I decided it would be better to just convert the existing tests to the new system.
  • Loading branch information
AndrewSisley committed Feb 15, 2023
1 parent 7947e73 commit ee534b1
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 145 deletions.
214 changes: 127 additions & 87 deletions tests/integration/subscription/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,191 +17,209 @@ import (
)

func TestSubscriptionWithCreateMutations(t *testing.T) {
test := testUtils.RequestTestCase{
test := testUtils.TestCase{
Description: "Subscription with user creations",
Request: `subscription {
Actions: []any{
testUtils.SubscriptionRequest{
Request: `subscription {
User {
_key
name
age
}
}`,
PostSubscriptionRequests: []testUtils.SubscriptionRequest{
{
Results: []map[string]any{
{
"_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d",
"age": uint64(27),
"name": "John",
},
{
"_key": "bae-18def051-7f0f-5dc9-8a69-2a5e423f6b55",
"age": uint64(31),
"name": "Addo",
},
},
},
testUtils.Request{
Request: `mutation {
create_User(data: "{\"name\": \"John\",\"age\": 27,\"points\": 42.1,\"verified\": true}") {
_key
name
age
}
}`,
Results: []map[string]any{
{
"_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d",
"age": uint64(27),
"name": "John",
},
},
},
{
testUtils.Request{
Request: `mutation {
create_User(data: "{\"name\": \"Addo\",\"age\": 31,\"points\": 42.1,\"verified\": true}") {
_key
name
age
}
}`,
Results: []map[string]any{
{
"_key": "bae-18def051-7f0f-5dc9-8a69-2a5e423f6b55",
"age": uint64(31),
"name": "Addo",
},
},
},
},
}

executeTestCase(t, test)
execute(t, test)
}

func TestSubscriptionWithFilterAndOneCreateMutation(t *testing.T) {
test := testUtils.RequestTestCase{
test := testUtils.TestCase{
Description: "Subscription with filter and one user creation",
Request: `subscription {
Actions: []any{
testUtils.SubscriptionRequest{
Request: `subscription {
User(filter: {age: {_lt: 30}}) {
_key
name
age
}
}`,
PostSubscriptionRequests: []testUtils.SubscriptionRequest{
{
Results: []map[string]any{
{
"_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d",
"age": uint64(27),
"name": "John",
},
},
},
testUtils.Request{
Request: `mutation {
create_User(data: "{\"name\": \"John\",\"age\": 27,\"points\": 42.1,\"verified\": true}") {
_key
name
age
}
}`,
Results: []map[string]any{
{
"_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d",
"age": uint64(27),
"name": "John",
},
},
},
},
}

executeTestCase(t, test)
execute(t, test)
}

func TestSubscriptionWithFilterAndOneCreateMutationOutsideFilter(t *testing.T) {
test := testUtils.RequestTestCase{
test := testUtils.TestCase{
Description: "Subscription with filter and one user creation outside of the filter",
Request: `subscription {
Actions: []any{
testUtils.SubscriptionRequest{
Request: `subscription {
User(filter: {age: {_gt: 30}}) {
_key
name
age
}
}`,
PostSubscriptionRequests: []testUtils.SubscriptionRequest{
{
Results: []map[string]any{},
},
testUtils.Request{
Request: `mutation {
create_User(data: "{\"name\": \"John\",\"age\": 27,\"points\": 42.1,\"verified\": true}") {
_key
name
age
}
}`,
ExpectedTimout: true,
Results: []map[string]any{
{
"name": "John",
},
},
},
},
}

executeTestCase(t, test)
execute(t, test)
}

func TestSubscriptionWithFilterAndCreateMutations(t *testing.T) {
test := testUtils.RequestTestCase{
test := testUtils.TestCase{
Description: "Subscription with filter and user creation in and outside of the filter",
Request: `subscription {
Actions: []any{
testUtils.SubscriptionRequest{
Request: `subscription {
User(filter: {age: {_lt: 30}}) {
_key
name
age
}
}`,
PostSubscriptionRequests: []testUtils.SubscriptionRequest{
{
Results: []map[string]any{
{
"_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d",
"age": uint64(27),
"name": "John",
},
},
},
testUtils.Request{
Request: `mutation {
create_User(data: "{\"name\": \"John\",\"age\": 27,\"points\": 42.1,\"verified\": true}") {
_key
name
age
}
}`,
Results: []map[string]any{
{
"_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d",
"age": uint64(27),
"name": "John",
},
},
},
{
testUtils.Request{
Request: `mutation {
create_User(data: "{\"name\": \"Addo\",\"age\": 31,\"points\": 42.1,\"verified\": true}") {
_key
name
age
}
}`,
ExpectedTimout: true,
Results: []map[string]any{
{
"name": "Addo",
},
},
},
},
}

executeTestCase(t, test)
execute(t, test)
}

func TestSubscriptionWithUpdateMutations(t *testing.T) {
test := testUtils.RequestTestCase{
Description: "Subscription with user creations",
Request: `subscription {
User {
_key
name
age
points
}
}`,
Docs: map[int][]string{
0: {
`{
test := testUtils.TestCase{
Description: "Subscription with user creations and single mutation",
Actions: []any{
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "John",
"age": 27,
"verified": true,
"points": 42.1
}`,
`{
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "Addo",
"age": 35,
"verified": true,
"points": 50
}`,
},
},
PostSubscriptionRequests: []testUtils.SubscriptionRequest{
{
Request: `mutation {
update_User(filter: {name: {_eq: "John"}}, data: "{\"points\": 45}") {
testUtils.SubscriptionRequest{
Request: `subscription {
User {
_key
name
age
points
}
}`,
Results: []map[string]any{
Expand All @@ -213,46 +231,53 @@ func TestSubscriptionWithUpdateMutations(t *testing.T) {
},
},
},
testUtils.Request{
Request: `mutation {
update_User(filter: {name: {_eq: "John"}}, data: "{\"points\": 45}") {
name
}
}`,
Results: []map[string]any{
{
"name": "John",
},
},
},
},
}

executeTestCase(t, test)
execute(t, test)
}

func TestSubscriptionWithUpdateAllMutations(t *testing.T) {
test := testUtils.RequestTestCase{
Description: "Subscription with user creations",
Request: `subscription {
User {
_key
name
age
points
}
}`,
Docs: map[int][]string{
0: {
`{
test := testUtils.TestCase{
Description: "Subscription with user creations and mutations for all",
Actions: []any{
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "John",
"age": 27,
"verified": true,
"points": 42.1
}`,
`{
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "Addo",
"age": 31,
"age": 35,
"verified": true,
"points": 50
}`,
},
},
PostSubscriptionRequests: []testUtils.SubscriptionRequest{
{
Request: `mutation {
update_User(data: "{\"points\": 55}") {
testUtils.SubscriptionRequest{
Request: `subscription {
User {
_key
name
age
points
}
}`,
Results: []map[string]any{
Expand All @@ -263,15 +288,30 @@ func TestSubscriptionWithUpdateAllMutations(t *testing.T) {
"points": float64(55),
},
{
"_key": "bae-cf723876-5c6a-5dcf-a877-ab288eb30d57",
"age": uint64(31),
"_key": "bae-b04980aa-e290-5a13-b688-07c87d3dfd5d",
"age": uint64(35),
"name": "Addo",
"points": float64(55),
},
},
},
testUtils.Request{
Request: `mutation {
update_User(data: "{\"points\": 55}") {
name
}
}`,
Results: []map[string]any{
{
"name": "John",
},
{
"name": "Addo",
},
},
},
},
}

executeTestCase(t, test)
execute(t, test)
}
Loading

0 comments on commit ee534b1

Please sign in to comment.