Skip to content

Commit 6baca7e

Browse files
committed
subscription: more tests cases
1 parent 2b63a00 commit 6baca7e

File tree

2 files changed

+27
-57
lines changed

2 files changed

+27
-57
lines changed

subscription.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ func ExecuteSubscription(p ExecuteParams) chan *Result {
228228
select {
229229
case <-p.Context.Done():
230230
println("context cancelled")
231-
232-
// TODO send the context error to the resultchannel
231+
// TODO send the context error to the resultchannel?
233232
return
234233

235234
case res, more := <-sub:
@@ -243,7 +242,6 @@ func ExecuteSubscription(p ExecuteParams) chan *Result {
243242
default:
244243
fmt.Println(fieldResult)
245244
resultChannel <- mapSourceToResponse(fieldResult)
246-
247245
return
248246
}
249247
}()

subscription_test.go

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ func TestSchemaSubscribe(t *testing.T) {
155155
{
156156
"field": "bye",
157157
},
158+
{
159+
"field": nil,
160+
},
158161
}),
159162
},
160163
},
@@ -169,6 +172,7 @@ func TestSchemaSubscribe(t *testing.T) {
169172
ExpectedResults: []testutil.TestResponse{
170173
{Data: `{ "sub_with_object": { "field": "hello" } }`},
171174
{Data: `{ "sub_with_object": { "field": "bye" } }`},
175+
{Data: `{ "sub_with_object": { "field": null } }`},
172176
},
173177
},
174178

@@ -196,60 +200,28 @@ func TestSchemaSubscribe(t *testing.T) {
196200
},
197201
},
198202
},
199-
// {
200-
// Name: "subscription_resolver_can_error_optional_msg",
201-
// Schema: schema,
202-
// Query: `
203-
// subscription onHelloSaid {
204-
// helloSaidNullable {
205-
// msg
206-
// }
207-
// }
208-
// `,
209-
// ExpectedResults: []testutil.TestResponse{
210-
// {
211-
// Data: json.RawMessage(`
212-
// {
213-
// "helloSaidNullable": {
214-
// "msg": null
215-
// }
216-
// }
217-
// `),
218-
// Errors: []gqlerrors.FormattedError{{Message: ""}}},
219-
// },
220-
// },
221-
// {
222-
// Name: "subscription_resolver_can_error_optional_event",
223-
// Schema: schema,
224-
// Query: `
225-
// subscription onHelloSaid {
226-
// helloSaidNullable {
227-
// msg
228-
// }
229-
// }
230-
// `,
231-
// ExpectedResults: []testutil.TestResponse{
232-
// {
233-
// Data: json.RawMessage(`
234-
// {
235-
// "helloSaidNullable": null
236-
// }
237-
// `),
238-
// Errors: []gqlerrors.FormattedError{{Message: ""}}},
239-
// },
240-
// },
241-
// {
242-
// Name: "schema_without_resolver_errors",
243-
// Schema: schema,
244-
// Query: `
245-
// subscription onHelloSaid {
246-
// helloSaid {
247-
// msg
248-
// }
249-
// }
250-
// `,
251-
// ExpectedErr: errors.New("schema created without resolver, can not subscribe"),
252-
// },
203+
204+
{
205+
Name: "schema_without_subscribe_errors",
206+
Schema: makeSubscriptionSchema(t, graphql.ObjectConfig{
207+
Name: "Subscription",
208+
Fields: graphql.Fields{
209+
"should_error": &graphql.Field{
210+
Type: graphql.String,
211+
},
212+
},
213+
}),
214+
Query: `
215+
subscription {
216+
should_error
217+
}
218+
`,
219+
ExpectedResults: []testutil.TestResponse{
220+
{
221+
Errors: []string{"the subscription function \"should_error\" is not defined"},
222+
},
223+
},
224+
},
253225
})
254226
}
255227

0 commit comments

Comments
 (0)