diff --git a/packages/collections/src/collections.js b/packages/collections/src/collections.js index 930da387b..43ff57743 100644 --- a/packages/collections/src/collections.js +++ b/packages/collections/src/collections.js @@ -59,14 +59,11 @@ export const setMockClient = mockClient => { export function get(name, query = {}) { return async state => { let [resolvedName, resolvedQuery] = expandReferences(state, name, query); - // TODO need a test on this if (typeof resolvedQuery === 'string') { resolvedQuery = { key: resolvedQuery }; } const { key, ...rest } = expandQuery(resolvedQuery); - // TODO maybe add query options here - // I haven't really given myself much space for this in the api const response = await request( state, getClient(state), @@ -75,7 +72,6 @@ export function get(name, query = {}) { ); let data; - // TODO unit tests on json encoding please if (!key.match(/\*/) || Object.keys(resolvedQuery).length === 0) { // If one specific item was requested, write it straight to state.data const body = await response.body.json(); @@ -188,8 +184,6 @@ export function remove(name, query = {}, options = {}) { const { key, ...rest } = expandQuery(resolvedQuery); - // TODO maybe add query options here - // I haven't really given myself much space for this in the api const response = await request( state, getClient(state), @@ -231,8 +225,7 @@ export function each(name, query = {}, callback = () => {}) { const [resolvedName, resolvedQuery] = expandReferences(state, name, query); const { key, ...rest } = expandQuery(resolvedQuery); - // TODO maybe add query options here - // I haven't really given myself much space for this in the api + const response = await request( state, getClient(state), diff --git a/packages/collections/test/Adaptor.test.js b/packages/collections/test/Adaptor.test.js index a0cfc1786..a632fd4c5 100644 --- a/packages/collections/test/Adaptor.test.js +++ b/packages/collections/test/Adaptor.test.js @@ -116,7 +116,7 @@ describe('get', () => { expect(err.code).to.eql('INVALID_AUTH'); }); - it('should get a single item', async () => { + it('should get a single item with string query', async () => { const { state } = init(); const result = await collections.get(COLLECTION, 'x')(state); @@ -127,6 +127,17 @@ describe('get', () => { }); }); + it('should get a single item with object query', async () => { + const { state } = init(); + + const result = await collections.get(COLLECTION, { key: 'x' })(state); + + expect(result.data).to.eql({ + key: 'x', + value: { id: 'x' }, + }); + }); + it('should get all items', async () => { const { state } = init([ ['a', { id: 'a' }],