Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 9b2e79e

Browse files
author
Bart van der Hoek
committed
feat(core): add support for ParameterBag in Repository.findById #82
1 parent 6b3ad47 commit 9b2e79e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/core/__tests__/Resource/Repository.read.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,18 @@ describe('The resource repository', () => {
109109
expect(data).toBe(axiosResponseData.data.data[0]);
110110
});
111111
});
112+
113+
it('should allow a parameter bag in the connector for the findById method to do requests', () => {
114+
const connectorFindOne = {
115+
fetchOne: jest.fn(() => Promise.resolve(axiosResponseData)),
116+
};
117+
const repository = repositoryManager.createRepository(connectorFindOne, 'testtype12', identifier);
118+
const parameterBag = ParameterBag();
119+
parameterBag.setParams('include', 'relation1,relation2');
120+
121+
repository.findById(12, parameterBag);
122+
expect(connectorFindOne.fetchOne.mock.calls).toHaveLength(1);
123+
expect(connectorFindOne.fetchOne.mock.calls[0]).toHaveLength(3);
124+
expect(connectorFindOne.fetchOne.mock.calls[0][2]).toEqual(parameterBag);
125+
});
112126
});

packages/core/src/Resource/Repository.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export default function Repository(connector, resourceType, identifier) {
3737
},
3838
/**
3939
* @param {String|Number} id
40-
*
40+
* @param {ParameterBag} parameterBag
4141
* @returns {Promise<Resource>}
4242
*/
43-
findById(id) {
44-
return connector.fetchOne(this, id, {}).then(
43+
findById(id, parameterBag) {
44+
return connector.fetchOne(this, id, (typeof parameterBag === 'undefined') ? {} : parameterBag).then(
4545
response => (response && response.data && response.data.data ? response.data.data : null),
4646
);
4747
},

0 commit comments

Comments
 (0)