Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/services/path-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ describe('Path Builder', () => {
expect(path_builder.includes).toEqual(['include']);
});
it('applyParams method should add fields to get_params if they are included in the request', () => {
path_builder.applyParams(testService, { fields: { test: ['test_attribute'] } });
path_builder.applyParams(testService, { fields: { test: ['test_attribute'], test2: ['test2_attribute'] } });
expect((path_builder as any).get_params.indexOf('fields[test]=test_attribute')).toBeGreaterThan(-1);
expect((path_builder as any).get_params.indexOf('fields[test2]=test2_attribute')).toBeGreaterThan(-1);
});
it('appendPath method should add passed value to paths array (only if value is not an empty string)', () => {
path_builder.paths = [];
Expand Down
5 changes: 2 additions & 3 deletions src/services/path-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ export class PathBuilder {
this.setInclude(params.include);
}
if (params.fields && Object.keys(params.fields).length > 0) {
let fields_param: string = '';
for (let resource_type in params.fields) {
fields_param += `fields[${resource_type}]=${params.fields[resource_type].join(',')}`;
let fields_param = `fields[${resource_type}]=${params.fields[resource_type].join(',')}`;
this.get_params.push(fields_param);
}
this.get_params.push(fields_param);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/services/path-collection-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ describe('Path Builder', () => {
});

it('if fields are provided, they should be formatted and included in get_params', () => {
path_collection_builder.applyParams(testService, { fields: { test: ['test_attribute', 'other_test_attribute'] } });
let addParam_parent_spy = spyOn(path_collection_builder, 'addParam').and.callThrough();
path_collection_builder.applyParams(testService, { fields:
{ test: ['test_attribute', 'other_test_attribute'], test2: ['test2_attribute'] }
});
expect((path_collection_builder as any).get_params.indexOf('fields[test]=test_attribute,other_test_attribute')).toBeGreaterThan(-1);
expect((path_collection_builder as any).get_params.indexOf('fields[test2]=test2_attribute')).toBeGreaterThan(-1);
});

it('if page params are provided, applyParams should call addParam one or two times with the page number and size', () => {
Expand Down
7 changes: 0 additions & 7 deletions src/services/path-collection-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ export class PathCollectionBuilder extends PathBuilder {
if (params.sort && params.sort.length) {
this.addParam('sort=' + params.sort.join(','));
}
if (params.fields && Object.keys(params.fields).length > 0) {
let fields_param: string = '';
for (let resource_type in params.fields) {
fields_param += `fields[${resource_type}]=${params.fields[resource_type].join(',')}`;
}
this.addParam(fields_param);
}
}

private getPageConfig(): { number: string; size: string } {
Expand Down