Skip to content

Commit dc7c027

Browse files
Achieve full test coverage (#288)
1 parent f0c3ad8 commit dc7c027

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-24
lines changed

.nycrc.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
all: true
22
include:
3-
- 'src/**/*'
4-
- 'src/__tests__/starWarsData.js'
3+
- 'src/'
54
exclude: []
65
clean: true
76
temp-directory: 'coverage'
87
report-dir: 'coverage'
98
skip-full: true
109
reporter: [json, html, text]
10+
check-coverage: true
11+
branches: 100
12+
lines: 100
13+
functions: 100
14+
statements: 100

src/__tests__/starWarsSchema.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ import {
111111
const { nodeInterface, nodeField } = nodeDefinitions(
112112
(globalId) => {
113113
const { type, id } = fromGlobalId(globalId);
114-
if (type === 'Faction') {
115-
return getFaction(id);
116-
}
117-
if (type === 'Ship') {
118-
return getShip(id);
114+
switch (type) {
115+
case 'Faction':
116+
return getFaction(id);
117+
case 'Ship':
118+
return getShip(id);
119119
}
120120
},
121121
(obj) => (obj.ships ? factionType : shipType),

src/mutation/__tests__/mutation.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import {
1313

1414
import { mutationWithClientMutationId } from '../mutation';
1515

16+
function dummyResolve() {
17+
return { result: 1 };
18+
}
19+
1620
const simpleMutation = mutationWithClientMutationId({
1721
name: 'SimpleMutation',
1822
inputFields: {},
@@ -21,7 +25,7 @@ const simpleMutation = mutationWithClientMutationId({
2125
type: GraphQLInt,
2226
},
2327
},
24-
mutateAndGetPayload: () => ({ result: 1 }),
28+
mutateAndGetPayload: dummyResolve,
2529
});
2630

2731
const simpleMutationWithDescription = mutationWithClientMutationId({
@@ -33,7 +37,7 @@ const simpleMutationWithDescription = mutationWithClientMutationId({
3337
type: GraphQLInt,
3438
},
3539
},
36-
mutateAndGetPayload: () => ({ result: 1 }),
40+
mutateAndGetPayload: dummyResolve,
3741
});
3842

3943
const simpleMutationWithDeprecationReason = mutationWithClientMutationId({
@@ -44,7 +48,7 @@ const simpleMutationWithDeprecationReason = mutationWithClientMutationId({
4448
type: GraphQLInt,
4549
},
4650
},
47-
mutateAndGetPayload: () => ({ result: 1 }),
51+
mutateAndGetPayload: dummyResolve,
4852
deprecationReason: 'Just because',
4953
});
5054

src/node/__tests__/global.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ const postData = {
5050
const { nodeField, nodeInterface } = nodeDefinitions(
5151
(globalId) => {
5252
const { type, id } = fromGlobalId(globalId);
53-
if (type === 'User') {
54-
return userData[id];
55-
}
56-
if (type === 'Photo') {
57-
return photoData[id];
58-
}
59-
if (type === 'Post') {
60-
return postData[id];
53+
switch(type) {
54+
case 'User':
55+
return userData[id];
56+
case 'Photo':
57+
return photoData[id];
58+
case 'Post':
59+
return postData[id];
6160
}
6261
},
6362
(obj) => {
@@ -67,6 +66,8 @@ const { nodeField, nodeInterface } = nodeDefinitions(
6766
if (obj.photoId) {
6867
return photoType;
6968
}
69+
70+
// istanbul ignore else (Can't be reached)
7071
if (obj.text) {
7172
return postType;
7273
}

src/node/__tests__/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const { nodeField, nodesField, nodeInterface } = nodeDefinitions(
5151
if (userData[obj.id]) {
5252
return userType;
5353
}
54+
// istanbul ignore else (Can't be reached)
5455
if (photoData[obj.id]) {
5556
return photoType;
5657
}

src/node/plural.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow strict
22

3-
import { GraphQLList, GraphQLNonNull, isNonNullType } from 'graphql';
3+
import { GraphQLList, GraphQLNonNull, getNullableType } from 'graphql';
44

55
import type {
66
GraphQLFieldConfig,
@@ -24,17 +24,15 @@ type PluralIdentifyingRootFieldConfig = {
2424
export function pluralIdentifyingRootField(
2525
config: PluralIdentifyingRootFieldConfig,
2626
): GraphQLFieldConfig<mixed, mixed> {
27-
let inputType = config.inputType;
28-
if (isNonNullType(inputType)) {
29-
inputType = inputType.ofType;
30-
}
3127
return {
3228
description: config.description,
3329
type: new GraphQLList(config.outputType),
3430
args: {
3531
[config.argName]: {
3632
type: new GraphQLNonNull(
37-
new GraphQLList(new GraphQLNonNull(inputType)),
33+
new GraphQLList(
34+
new GraphQLNonNull(getNullableType(config.inputType)),
35+
),
3836
),
3937
},
4038
},

0 commit comments

Comments
 (0)