Skip to content

Commit 9fde55d

Browse files
committed
Testing Get by ID with Custom Endpoint
1 parent e49cc64 commit 9fde55d

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/__tests__/createAPIAction-test.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,6 @@ describe('createAPIAction()', () => {
135135
});
136136
});
137137

138-
it('test GET by ID endpoint', () => {
139-
const getItems = createAPIAction(type, 'GET', '/sample');
140-
expect(getItems(9)).to.deep.equal({
141-
type,
142-
payload: {},
143-
meta: {
144-
api: true,
145-
method: 'GET',
146-
endpoint: '/sample/9',
147-
types: [
148-
type.concat('_GET_REQUEST'),
149-
type.concat('_GET_SUCCESS'),
150-
type.concat('_GET_FAILURE')
151-
]
152-
}
153-
});
154-
});
155138

156139
it('test POST Data endpoint', () => {
157140
const createItems = createAPIAction(type, 'POST', '/sample');
@@ -235,5 +218,27 @@ describe('createAPIAction()', () => {
235218
}
236219
});
237220
});
221+
222+
it('test Get by ID with Custom Endpoint', () => {
223+
const customEndpoint = (p) => {
224+
return `/tester/${p}/mctesterson`;
225+
};
226+
const getItems = createAPIAction(type, 'GET', customEndpoint);
227+
expect(getItems(10)).to.deep.equal({
228+
type,
229+
payload: {},
230+
meta: {
231+
api: true,
232+
method: 'GET',
233+
endpoint: '/tester/10/mctesterson',
234+
types: [
235+
type.concat('_GET_REQUEST'),
236+
type.concat('_GET_SUCCESS'),
237+
type.concat('_GET_FAILURE')
238+
]
239+
}
240+
});
241+
});
242+
238243
});
239244
});

src/createAPIAction.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ function getEndpoint(method, endpoint, params) {
1212
return endpoint(firstParam);
1313
}
1414

15-
if (method === 'GET' && typeof firstParam === 'number') {
16-
return `${endpoint}/${firstParam}`;
17-
}
18-
1915
switch (method) {
2016
case 'DELETE':
2117
case 'PUT':

0 commit comments

Comments
 (0)