Skip to content

Commit d1b3e83

Browse files
authored
Merge pull request #141 from erikpost/bugfix/fix-incorrect-url-and-params
fix for sync method not working correctly
2 parents 3347b3b + 1ff04ad commit d1b3e83

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/lib/synchronization.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function synchronization(client: AxiosInstance, params: SyncStack |
1515
config.params = { ...config.params, type: type.join(',') };
1616
}
1717

18-
let response: AxiosResponse = await getData(client, '/sync', { params: humps.decamelizeKeys(config) });
18+
let response: AxiosResponse = await getData(client, '/stacks/sync', { params: humps.decamelizeKeys(config.params) });
1919
const data = response.data;
2020

2121
while (recursive && 'pagination_token' in response.data) {

test/unit/synchronization.spec.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -28,63 +28,63 @@ describe('Synchronization function', () => {
2828
};
2929
it('should have valid init and environment params as req params when no request params is passed', async () => {
3030
await await synchronization(httpClient({}));
31-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
32-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
33-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({ init: true });
31+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
32+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
33+
expect(getDataMock.mock.calls[0][2].params).toEqual({ init: true });
3434
});
3535

3636
it('should have only pagination_token param when sync is called with pagination_token.', async () => {
3737
await syncCall({ paginationToken: '<page_tkn>' });
38-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
38+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
3939
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('init');
4040
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('environment');
41-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('pagination_token');
42-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({ pagination_token: '<page_tkn>' });
41+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('pagination_token');
42+
expect(getDataMock.mock.calls[0][2].params).toEqual({ pagination_token: '<page_tkn>' });
4343
});
4444
it('should have only sync_token param when sync is called with sync_token.', async () => {
4545
await syncCall({ syncToken: '<sync_tkn>' });
46-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
46+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
4747
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('init');
4848
expect(getDataMock.mock.calls[0][2].params).not.toHaveProperty('environment');
49-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('sync_token');
50-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({ sync_token: '<sync_tkn>' });
49+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('sync_token');
50+
expect(getDataMock.mock.calls[0][2].params).toEqual({ sync_token: '<sync_tkn>' });
5151
});
5252
it('should have valid content_type_uid when content_type_uid is passed as param', async () => {
5353
await syncCall({ contentTypeUid: 'session' });
54-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
55-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
56-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('content_type_uid');
57-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
54+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
55+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
56+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('content_type_uid');
57+
expect(getDataMock.mock.calls[0][2].params).toEqual({
5858
init: true,
5959
content_type_uid: 'session',
6060
});
6161
});
6262
it('should have valid locale when a locale is passed as param', async () => {
6363
await syncCall({ locale: LOCALE });
64-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
65-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
66-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('locale');
67-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
64+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
65+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
66+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('locale');
67+
expect(getDataMock.mock.calls[0][2].params).toEqual({
6868
init: true,
6969
locale: LOCALE,
7070
});
7171
});
7272
it('should have valid date structure and other required params when start_date is passed as param', async () => {
7373
await syncCall({ startDate: '2018-10-22' });
74-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
75-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
76-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('start_date');
77-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
74+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
75+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
76+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('start_date');
77+
expect(getDataMock.mock.calls[0][2].params).toEqual({
7878
init: true,
7979
start_date: '2018-10-22',
8080
});
8181
});
8282
it('should have valid publish_type when type is passed as param', async () => {
8383
await syncCall({ type: [PublishType.ENTRY_PUBLISHED] });
84-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
85-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
86-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('type');
87-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
84+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
85+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
86+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('type');
87+
expect(getDataMock.mock.calls[0][2].params).toEqual({
8888
init: true,
8989
type: 'entry_published',
9090
});
@@ -95,10 +95,10 @@ describe('Synchronization function', () => {
9595
startDate: '2018-10-22',
9696
type: [PublishType.ENTRY_PUBLISHED, PublishType.CONTENT_TYPE_DELETED],
9797
});
98-
expect(getDataMock.mock.calls[0][1]).toBe('/sync');
99-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('init');
100-
expect(getDataMock.mock.calls[0][2].params.params).toHaveProperty('type');
101-
expect(getDataMock.mock.calls[0][2].params.params).toEqual({
98+
expect(getDataMock.mock.calls[0][1]).toBe('/stacks/sync');
99+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('init');
100+
expect(getDataMock.mock.calls[0][2].params).toHaveProperty('type');
101+
expect(getDataMock.mock.calls[0][2].params).toEqual({
102102
init: true,
103103
start_date: '2018-10-22',
104104
locale: 'en-us',

0 commit comments

Comments
 (0)