diff --git a/src/services/path-builder.spec.ts b/src/services/path-builder.spec.ts index 1ff99982..b0721828 100644 --- a/src/services/path-builder.spec.ts +++ b/src/services/path-builder.spec.ts @@ -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 = []; diff --git a/src/services/path-builder.ts b/src/services/path-builder.ts index 887b5e8a..efd5ac99 100644 --- a/src/services/path-builder.ts +++ b/src/services/path-builder.ts @@ -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); } } diff --git a/src/services/path-collection-builder.spec.ts b/src/services/path-collection-builder.spec.ts index bf0966d0..09cdf4dc 100644 --- a/src/services/path-collection-builder.spec.ts +++ b/src/services/path-collection-builder.spec.ts @@ -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', () => { diff --git a/src/services/path-collection-builder.ts b/src/services/path-collection-builder.ts index 5e6b065f..ac613a5c 100644 --- a/src/services/path-collection-builder.ts +++ b/src/services/path-collection-builder.ts @@ -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 } {