Skip to content

Commit

Permalink
Fix a single entity fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Aug 3, 2018
1 parent 0408943 commit 895463b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export async function* getEntityRecord( state, kind, name, key ) {
return;
}
const record = await apiFetch( { path: `${ entity.baseURL }/${ key }?context=edit` } );
yield receiveEntityRecords( kind, name, record );
yield receiveEntityRecords( kind, name, record, {
[ entity.key || 'id' ]: key,
} );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/core-data/src/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe( 'getEntityRecord', () => {
};
const fulfillment = getEntityRecord( state, 'root', 'postType', 'post' );
const received = ( await fulfillment.next() ).value;
expect( received ).toEqual( receiveEntityRecords( 'root', 'postType', POST_TYPE ) );
expect( received ).toEqual( receiveEntityRecords( 'root', 'postType', POST_TYPE, { id: 'post' } ) );
} );

it( 'loads the kind entities and yields with requested post type', async () => {
Expand All @@ -74,7 +74,7 @@ describe( 'getEntityRecord', () => {
name: 'post',
} ] ) );
const received = ( await fulfillment.next() ).value;
expect( received ).toEqual( receiveEntityRecords( 'postType', 'post', POST ) );
expect( received ).toEqual( receiveEntityRecords( 'postType', 'post', POST, { id: 10 } ) );
} );
} );

Expand Down

0 comments on commit 895463b

Please sign in to comment.