Skip to content

Commit

Permalink
console.log removed. FEATURE: Service.newCollection() (#90)
Browse files Browse the repository at this point in the history
* console.log removed.
* FEATURE: Service.newCollection()
  • Loading branch information
pablorsk authored Jul 20, 2018
1 parent 0b29fd3 commit dc8b558
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 37 deletions.
70 changes: 37 additions & 33 deletions src/parent-resource-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ describe('parent-resource-service test', () => {
parentResourceServiceTest.testRunFc(parentResourceServiceTest.returnArgs, 'runFc is working');
expect(returnArgsSpy).toHaveBeenCalledWith('runFc is working');
});
it('runFc shouldn\'t do anything if the first attribute given is not a function', () => {
it("runFc shouldn't do anything if the first attribute given is not a function", () => {
let runFcSpy = spyOn(parentResourceServiceTest, 'runFc');
expect(parentResourceServiceTest.testRunFc('something', 'runFc is working')).toBe(undefined);
});
it('if IExecParams object with a function in params property is provided as argument \
to proccess_exec_params(), it should return an IExecParamsProcessed object with Base.params in params property, \
.params function in fc_success and fc_success function in fc_error', () => {
let params = (): string => { return 'test_exec_params'; };
let fc_success = (): string => { return 'test_exec_params success'; };
let fc_error = (): string => { return 'test_exec_params error'; };
let params = (): string => {
return 'test_exec_params';
};
let fc_success = (): string => {
return 'test_exec_params success';
};
let fc_error = (): string => {
return 'test_exec_params error';
};
let exec_params_with_function = {
id: 'test_exec_params',
params: params,
Expand All @@ -51,8 +57,12 @@ describe('parent-resource-service test', () => {
let exec_params_with_undefined = {
id: 'test_exec_params',
params: undefined,
fc_success: (): string => { return 'test_exec_params success'; },
fc_error: (): string => { return 'test_exec_params error'; },
fc_success: (): string => {
return 'test_exec_params success';
},
fc_error: (): string => {
return 'test_exec_params error';
},
exec_type: 'get'
};
expect(parentResourceServiceTest.testProccessExecParams(exec_params_with_undefined).params).toEqual({ ...{}, ...Base.Params });
Expand All @@ -63,40 +73,34 @@ describe('parent-resource-service test', () => {
let exec_params_with_object = {
id: 'test_exec_params',
params: { test: 'test_exec_params' },
fc_success: (): string => { return 'test_exec_params success'; },
fc_error: (): string => { return 'test_exec_params error'; },
fc_success: (): string => {
return 'test_exec_params success';
},
fc_error: (): string => {
return 'test_exec_params error';
},
exec_type: 'all'
};
expect(parentResourceServiceTest.testProccessExecParams(exec_params_with_object).params)
.toEqual({ ...{}, ...Base.Params, ...exec_params_with_object.params });
expect(parentResourceServiceTest.testProccessExecParams(exec_params_with_object).params).toEqual({
...{},
...Base.Params,
...exec_params_with_object.params
});
});
it('proccess_exec_params() should fail if provided with a non IExecParams object', () => {
let exec_params = {
id: 'test_exec_params',
params: 'test_exec_params'
params: 'PaRaM'
};
// expect error, typescript won't allow this
expect(parentResourceServiceTest.testProccessExecParams(exec_params).params).toEqual(
{
0: 't',
1: 'e',
2: 's',
3: 't',
4: '_',
5: 'e',
6: 'x',
7: 'e',
8: 'c',
9: '_',
10: 'p',
11: 'a',
12: 'r',
13: 'a',
14: 'm',
15: 's',
id: '',
include: [ ]
}
);
expect(parentResourceServiceTest.testProccessExecParams(exec_params).params).toEqual({
0: 'P',
1: 'a',
2: 'R',
3: 'a',
4: 'M',
id: '',
include: []
});
});
});
4 changes: 4 additions & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class Service<R extends Resource = Resource> extends ParentResourceServic
return <R>resource;
}

public newCollection(): ICollection<R> {
return Base.newCollection();
}

public new(): R {
let resource = this.newResource();
resource.type = this.type;
Expand Down
5 changes: 1 addition & 4 deletions src/sources/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Base } from '../services/base';
import { HttpClient, HttpRequest, HttpHeaders, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { JsonapiConfig } from '../jsonapi-config';

import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/map';

Expand All @@ -15,8 +14,6 @@ export class Http {
public constructor(
private http: HttpClient,
private rsJsonapiConfig: JsonapiConfig,
// private $timeout,
// private rsJsonapiConfig,
private noDuplicatedHttpCallsService: NoDuplicatedHttpCallsService // private $q
) {}

Expand All @@ -37,7 +34,7 @@ export class Http {
if (method === 'get') {
this.noDuplicatedHttpCallsService.setPromiseRequest(path, http_observable.toPromise());
} else {
return fakeHttpPromise = http_observable.toPromise();
return (fakeHttpPromise = http_observable.toPromise());
}
}
if (fakeHttpPromise === null) {
Expand Down

0 comments on commit dc8b558

Please sign in to comment.