Skip to content

Commit 53c1140

Browse files
authored
Allow for no mutation type in schema (#17)
* allow for no mutation type in schema * fix typo in assertion message
1 parent b34e7d7 commit 53c1140

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

addon/mocks/create.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ export const composeCreateMocksForSchema =
99
(createMocks, mockQuery, mockMutation) =>
1010
(schema, db, options) => {
1111
let typesAndMockFns = [
12-
[schema._queryType, mockQuery],
13-
[schema._mutationType, mockMutation]
12+
[schema._queryType, mockQuery]
1413
];
14+
15+
if (schema._mutationType) {
16+
typesAndMockFns.push([schema._mutationType, mockMutation]);
17+
}
18+
1519
let mocks = createMocks(typesAndMockFns, db, options);
1620

1721
return mocks;

tests/unit/mocks/create-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ module('Unit | Mocks | create', function() {
2323

2424
createMocksForSchema(schema, db, options);
2525
});
26+
27+
test('it creates mocks for query type, if no mutation type', function(assert) {
28+
assert.expect(1);
29+
30+
let schema = { _queryType: {} };
31+
let createMocks = (typesAndMockFns) => {
32+
assert.deepEqual(typesAndMockFns, [
33+
[schema._queryType, null]
34+
], 'It received the query type to mock');
35+
};
36+
let createMocksForSchema =
37+
composeCreateMocksForSchema(createMocks, null, null);
38+
39+
createMocksForSchema(schema);
40+
});
2641
});
2742

2843
module('reduce mocks', function() {

0 commit comments

Comments
 (0)