Skip to content

Commit 32fcc93

Browse files
committed
add more test coverage
1 parent b3c54e3 commit 32fcc93

File tree

5 files changed

+46
-23
lines changed

5 files changed

+46
-23
lines changed

src/__tests__/starWarsObjectIdentificationTests.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Object Identification Tests', () => {
7676
expect(result).to.deep.equal({ data: expected });
7777
});
7878

79-
it('Correctly refetches the rebels', async () => {
79+
it('Correctly refetches the empire', async () => {
8080
var query = `
8181
query EmpireRefetchQuery {
8282
node(id: "RmFjdGlvbjoy") {
@@ -96,5 +96,26 @@ describe('Object Identification Tests', () => {
9696
var result = await graphql(StarWarsSchema, query);
9797
expect(result).to.deep.equal({ data: expected });
9898
});
99+
100+
it('Correctly refetches the X-Wing', async () => {
101+
var query = `
102+
query XWingRefetchQuery {
103+
node(id: "U2hpcDox") {
104+
id
105+
... on Ship {
106+
name
107+
}
108+
}
109+
}
110+
`;
111+
var expected = {
112+
node: {
113+
id: 'U2hpcDox',
114+
name: 'X-Wing'
115+
}
116+
};
117+
var result = await graphql(StarWarsSchema, query);
118+
expect(result).to.deep.equal({ data: expected });
119+
});
99120
});
100121
});

src/connection/__tests__/arrayconnection.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,22 @@ describe('connectionFromArray', () => {
466466
});
467467

468468
describe('Handles cursor edge cases', () => {
469+
it('Returns no elements if first is 0', () => {
470+
var c = connectionFromArray(
471+
letters,
472+
{first: 0}
473+
);
474+
return expect(c).to.deep.equal({
475+
edges: [],
476+
pageInfo: {
477+
startCursor: null,
478+
endCursor: null,
479+
hasPreviousPage: false,
480+
hasNextPage: false,
481+
}
482+
});
483+
});
484+
469485
it('Returns all elements if cursors are invalid', () => {
470486
var c = connectionFromArray(
471487
letters,

src/node/__tests__/global.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,16 @@ var {nodeField, nodeInterface} = nodeDefinitions(
5353
var {type, id} = fromGlobalId(globalId);
5454
if (type === 'User') {
5555
return userData[id];
56-
}
57-
if (type === 'Photo') {
56+
} else {
5857
return photoData[id];
5958
}
60-
return null;
6159
},
6260
(obj) => {
6361
if (obj.id) {
6462
return userType;
65-
}
66-
if (obj.photoId) {
63+
} else {
6764
return photoType;
6865
}
69-
return null;
7066
}
7167
);
7268

src/node/__tests__/node.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,16 @@ var {nodeField, nodeInterface} = nodeDefinitions(
5252
expect(info.schema).to.equal(schema);
5353
if (userData[id]) {
5454
return userData[id];
55-
}
56-
if (photoData[id]) {
55+
} else {
5756
return photoData[id];
5857
}
59-
return null;
6058
},
6159
(obj) => {
6260
if (userData[obj.id]) {
6361
return userType;
64-
}
65-
if (photoData[obj.id]) {
62+
} else {
6663
return photoType;
6764
}
68-
return null;
6965
}
7066
);
7167

src/node/__tests__/nodeasync.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,11 @@ var userData = {
3434
};
3535

3636
var {nodeField, nodeInterface} = nodeDefinitions(
37-
async (id) => {
38-
if (userData[id]) {
39-
return userData[id];
40-
}
41-
return null;
37+
(id) => {
38+
return userData[id];
4239
},
43-
(obj) => {
44-
if (userData[obj.id]) {
45-
return userType;
46-
}
47-
return null;
40+
() => {
41+
return userType;
4842
}
4943
);
5044

0 commit comments

Comments
 (0)