Skip to content

Commit

Permalink
Added diffAgainstStore test for returned missing fields data.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasconstantino committed Jul 8, 2017
1 parent 2bb50e9 commit dc8da9b
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions test/diffAgainstStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ describe('diffing queries against the store', () => {
query,
});

assert.notOk(diffQueryAgainstStore({
const { isMissing, missingFields } = diffQueryAgainstStore({
store,
query,
}).isMissing);
});

assert.notOk(isMissing);
assert.equal(missingFields.length, 0);
});

it('caches root queries both under the ID of the node and the query name', () => {
Expand Down Expand Up @@ -207,6 +210,40 @@ describe('diffing queries against the store', () => {
assert.isTrue(isMissing);
});

it('returns missing fields info when fields are missing', () => {
const firstQuery = gql`
query {
a { b }
}`;

const firstResult = {
a: {
b: 1,
},
};

const store = writeQueryToStore({
result: firstResult,
query: firstQuery,
});

const secondQuery = gql`
query {
a { b c }
}`;

const { isMissing, missingFields } = diffQueryAgainstStore({
store,
query: secondQuery,
});

assert.isTrue(isMissing);
assert.equal(missingFields[0].storeKeyName, 'c');
assert.equal(missingFields[0].objId, '$ROOT_QUERY.a');
assert.equal(missingFields[0].fieldName, 'c');
assert.equal(missingFields[0].args, null);
});

it('throws an error on a query with fields missing from matching named fragments', () => {
const firstQuery = gql`
query {
Expand Down

0 comments on commit dc8da9b

Please sign in to comment.