-
-
Notifications
You must be signed in to change notification settings - Fork 350
/
Copy pathapolloGraphql.spec.ts
77 lines (68 loc) · 2.2 KB
/
apolloGraphql.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { ApolloGraphQLInteraction } from './apolloGraphql';
chai.use(chaiAsPromised);
const { expect } = chai;
describe('ApolloGraphQLInteraction', () => {
let interaction: ApolloGraphQLInteraction;
beforeEach(() => {
interaction = new ApolloGraphQLInteraction();
});
describe('#withVariables', () => {
describe('when given a set of variables', () => {
it('adds the variables to the payload', () => {
interaction.uponReceiving('a request');
interaction.withRequest({
path: '/graphql',
method: 'POST',
});
interaction.withOperation('query');
interaction.withQuery('{ hello }');
interaction.withVariables({
foo: 'bar',
});
interaction.willRespondWith({
status: 200,
body: { data: {} },
});
const json: any = interaction.json();
expect(json.request.body.variables).to.deep.eq({ foo: 'bar' });
});
});
describe('when no variables are presented', () => {
it('adds an empty variables property to the payload', () => {
interaction.uponReceiving('a request');
interaction.withRequest({
path: '/graphql',
method: 'POST',
});
interaction.withOperation('query');
interaction.withQuery('{ hello }');
interaction.willRespondWith({
status: 200,
body: { data: {} },
});
const json: any = interaction.json();
expect(json.request.body).to.have.property('variables');
});
});
});
describe('#withOperation', () => {
describe('when no operationName is presented', () => {
it('adds a null operationName property to the payload', () => {
interaction.uponReceiving('a request');
interaction.withRequest({
path: '/graphql',
method: 'POST',
});
interaction.withQuery('{ hello }');
interaction.willRespondWith({
status: 200,
body: { data: {} },
});
const json: any = interaction.json();
expect(json.request.body).to.have.property('operationName');
});
});
});
});