Skip to content

Commit

Permalink
test: use context option
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Nov 3, 2020
1 parent f2f1812 commit daa52cc
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,56 @@ it('should pass in the context value from the config', async () => {
expect(subscribeFn.mock.calls[0][0].contextValue).toBe(context);
});

it('should pass the `onSubscribe` exec args to the `context` option and use it', async (done) => {
const context = {};
const execArgs = {
// no context here
schema,
document: parse(`query { getValue }`),
};

const { url } = await startTServer({
onSubscribe: () => {
return execArgs;
},
context: (_ctx, _msg, args) => {
expect(args).toBe(args); // from `onSubscribe`
return context; // will be injected
},
execute: (args) => {
expect(args).toBe(execArgs); // from `onSubscribe`
expect(args.contextValue).toBe(context); // injected by `context`
done();
return execute(args);
},
subscribe,
});

const client = await createTClient(url);
client.ws.send(
stringifyMessage<MessageType.ConnectionInit>({
type: MessageType.ConnectionInit,
}),
);
await client.waitForMessage(({ data }) => {
expect(parseMessage(data).type).toBe(MessageType.ConnectionAck);
});

client.ws.send(
stringifyMessage<MessageType.Subscribe>({
id: '1',
type: MessageType.Subscribe,
payload: {
query: `{ getValue }`,
},
}),
);
});

it.todo(
'should prefer the `onSubscribe` context value even if `context` option is set',
);

describe('Connect', () => {
it('should refuse connection and close socket if returning `false`', async () => {
const { url } = await startTServer({
Expand Down

0 comments on commit daa52cc

Please sign in to comment.