Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Oct 30, 2024
1 parent b672bcf commit 7beea86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 1 addition & 8 deletions packages/collections/src/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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();
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
13 changes: 12 additions & 1 deletion packages/collections/test/Adaptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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' }],
Expand Down

0 comments on commit 7beea86

Please sign in to comment.