Skip to content

Commit deaa433

Browse files
authored
fix/get_params tests (#232)
1 parent 1c8fa4d commit deaa433

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-jsonapi",
3-
"version": "2.1.7",
3+
"version": "2.1.8",
44
"description": "JSON API library for Angular",
55
"module": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js",
66
"es2015": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.js",

src/services/path-builder.spec.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,37 @@ let core = new Core(
2323

2424
const testService = new Service();
2525
testService.getPrePath = (): string => {
26-
return 'test/pre-path';
26+
return 'v1';
2727
};
2828
testService.getPath = (): string => {
29-
return 'test/path';
29+
return 'authors';
3030
};
3131

3232
describe('Path Builder', () => {
33-
let path_builder = new PathBuilder();
34-
it('should create', () => {
35-
expect(path_builder).toBeTruthy();
33+
let path_builder: PathBuilder;
34+
beforeEach(async () => {
35+
path_builder = new PathBuilder();
3636
});
37+
3738
it('applyParams method should call appendPath two to four times: with service s pre-path, params.beforepath (if exists),\
3839
and service s path', () => {
3940
let appendPath_spy = spyOn(path_builder, 'appendPath');
4041
path_builder.applyParams(testService);
4142
expect(appendPath_spy).toHaveBeenCalledTimes(2);
42-
path_builder.applyParams(testService, { beforepath: 'pre/', include: ['include'] });
43+
path_builder.applyParams(testService, { beforepath: 'users/1', include: ['include'] });
4344
expect(appendPath_spy).toHaveBeenCalledWith(testService.getPrePath());
44-
expect(appendPath_spy).toHaveBeenCalledWith('pre/');
45+
expect(appendPath_spy).toHaveBeenCalledWith('users/1');
4546
expect(appendPath_spy).toHaveBeenCalledWith(testService.getPath());
4647
});
47-
it('applyParams method should call setInclude with params.include (if exists) to assign them to the includes array', () => {
48-
let setInclude_spy = spyOn<any>(path_builder, 'setInclude');
49-
path_builder.applyParams(testService, { beforepath: 'pre/' });
50-
expect(setInclude_spy).not.toHaveBeenCalled();
51-
path_builder.applyParams(testService, { beforepath: 'pre/', include: ['include'] });
52-
expect(setInclude_spy).toHaveBeenCalledWith(['include']);
53-
expect(path_builder.includes).toEqual(['include']);
48+
it('applyParams include', () => {
49+
path_builder.applyParams(testService, { beforepath: 'users/1' });
50+
expect(path_builder.get()).toMatch('v1/users/1/authors');
51+
path_builder.applyParams(testService, { beforepath: 'users/1', include: ['include'] });
52+
expect(path_builder.get()).toMatch('v1/users/1/authors?include=include');
5453
});
55-
it('applyParams method should add fields to get_params if they are included in the request', () => {
56-
path_builder.applyParams(testService, { fields: { test: ['test_attribute'], test2: ['test2_attribute'] } });
57-
expect((path_builder as any).get_params.indexOf('fields[test]=test_attribute')).toBeGreaterThan(-1);
58-
expect((path_builder as any).get_params.indexOf('fields[test2]=test2_attribute')).toBeGreaterThan(-1);
54+
it('applyParams fields', () => {
55+
path_builder.applyParams(testService, { fields: { authors: ['name', 'address'], books: ['title'] } });
56+
expect(path_builder.get().includes('fields[authors]=name,address&fields[books]=title')).toBeTruthy();
5957
});
6058
it('appendPath method should add passed value to paths array (only if value is not an empty string)', () => {
6159
path_builder.paths = [];

src/services/path-collection-builder.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ describe('Path Builder', () => {
6363
});
6464

6565
it('if fields are provided, they should be formatted and included in get_params', () => {
66-
let addParam_parent_spy = spyOn(path_collection_builder, 'addParam').and.callThrough();
67-
path_collection_builder.applyParams(testService, { fields:
68-
{ test: ['test_attribute', 'other_test_attribute'], test2: ['test2_attribute'] }
69-
});
70-
expect((path_collection_builder as any).get_params.indexOf('fields[test]=test_attribute,other_test_attribute')).toBeGreaterThan(-1);
71-
expect((path_collection_builder as any).get_params.indexOf('fields[test2]=test2_attribute')).toBeGreaterThan(-1);
66+
path_collection_builder.applyParams(testService, { fields: { authors: ['name', 'address'], books: ['title'] } });
67+
expect(path_collection_builder.get().includes('fields[authors]=name,address&fields[books]=title')).toBeTruthy();
7268
});
7369

7470
it('if page params are provided, applyParams should call addParam one or two times with the page number and size', () => {

0 commit comments

Comments
 (0)