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
2 changes: 1 addition & 1 deletion src/converters/json-model/json-model.converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('JsonModel converter', () => {
const VALUE = null;
expect(() => {
converter.mask(VALUE);
}).toThrow(new Error('ERROR: JsonModelConverter: Expected array but got ' + typeof VALUE + '.'));
}).toThrow(new Error(`ERROR: JsonModelConverter: Expected array but got ${typeof VALUE}.`));
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/converters/json-model/json-model.converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class JsonModelConverter<T> implements PropertyConverter {
let result = null;
if (this.options.hasMany) {
if (!Array.isArray(value)) {
throw new Error('ERROR: JsonModelConverter: Expected array but got ' + typeof value + '.');
throw new Error(`ERROR: JsonModelConverter: Expected array but got ${typeof value}.`);
}
result = [];
for (const item of value) {
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './decorators/json-attribute.decorator';
export * from './decorators/json-api-model-config.decorator';
export * from './decorators/json-api-datastore-config.decorator';


export * from './models/json-api-meta.model';
export * from './models/json-api.model';
export * from './models/json-nested.model';
Expand All @@ -22,7 +21,6 @@ export * from './interfaces/model-config.interface';
export * from './interfaces/attribute-decorator-options.interface';
export * from './interfaces/property-converter.interface';


export * from './providers';

export * from './module';
2 changes: 1 addition & 1 deletion src/models/json-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class JsonApiModel {
}
}

private rollbackAttributes(): void {
public rollbackAttributes(): void {
const attributesMetadata: any = this[AttributeMetadataIndex];
for (const propertyName in attributesMetadata) {
if (attributesMetadata.hasOwnProperty(propertyName)) {
Expand Down
25 changes: 13 additions & 12 deletions src/services/json-api-datastore.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { API_VERSION, BASE_URL, Datastore } from '../../test/datastore.service';
import { ErrorResponse } from '../models/error-response.model';
import { getSampleBook } from '../../test/fixtures/book.fixture';
import { Book } from '../../test/models/book.model';
import { ModelConfig } from '../index';
import { JsonApiQueryData, ModelConfig } from '../index';
import {
API_VERSION_FROM_CONFIG,
BASE_URL_FROM_CONFIG,
DatastoreWithConfig
} from '../../test/datastore-with-config.service';
import { HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';

let datastore: Datastore;
let datastoreWithConfig: DatastoreWithConfig;
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('JsonApiDatastore', () => {
const authorModelConfig: ModelConfig = Reflect.getMetadata('JsonApiModelConfig', Author);
const expectedUrl = `${BASE_URL}/${API_VERSION}/${authorModelConfig.type}`;

datastore.query(Author).subscribe();
datastore.findAll(Author).subscribe();

const queryRequest = httpMock.expectOne({ method: 'GET', url: expectedUrl });
queryRequest.flush({ data: [] });
Expand All @@ -62,7 +62,7 @@ describe('JsonApiDatastore', () => {
const authorModelConfig: ModelConfig = Reflect.getMetadata('JsonApiModelConfig', Author);
const expectedUrl = `${BASE_URL_FROM_CONFIG}/${API_VERSION_FROM_CONFIG}/${authorModelConfig.type}`;

datastoreWithConfig.query(Author).subscribe();
datastoreWithConfig.findAll(Author).subscribe();

const queryRequest = httpMock.expectOne({ method: 'GET', url: expectedUrl });
queryRequest.flush({ data: [] });
Expand All @@ -73,7 +73,7 @@ describe('JsonApiDatastore', () => {
const authorModelConfig: ModelConfig = Reflect.getMetadata('JsonApiModelConfig', CustomAuthor);
const expectedUrl = `${BASE_URL_FROM_CONFIG}/${AUTHOR_API_VERSION}/${AUTHOR_MODEL_ENDPOINT_URL}`;

datastoreWithConfig.query(CustomAuthor).subscribe();
datastoreWithConfig.findAll(CustomAuthor).subscribe();

const queryRequest = httpMock.expectOne({ method: 'GET', url: expectedUrl });
queryRequest.flush({ data: [] });
Expand All @@ -82,7 +82,7 @@ describe('JsonApiDatastore', () => {
it('should set JSON API headers', () => {
const expectedUrl = `${BASE_URL}/${API_VERSION}/authors`;

datastore.query(Author).subscribe();
datastore.findAll(Author).subscribe();

const queryRequest = httpMock.expectOne({ method: 'GET', url: expectedUrl });
expect(queryRequest.request.headers.get('Content-Type')).toEqual('application/vnd.api+json');
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('JsonApiDatastore', () => {
encodeURIComponent('include') + '=comments&' +
encodeURIComponent('filter[title][keyword]') + '=Tolkien';

datastore.query(Author, queryData).subscribe();
datastore.findAll(Author, queryData).subscribe();

httpMock.expectNone(`${BASE_URL}/${API_VERSION}`);
const queryRequest = httpMock.expectOne({ method: 'GET', url: expectedUrl });
Expand All @@ -120,7 +120,7 @@ describe('JsonApiDatastore', () => {
it('should have custom headers', () => {
const expectedUrl = `${BASE_URL}/${API_VERSION}/authors`;

datastore.query(Author, null, new HttpHeaders({ Authorization: 'Bearer' })).subscribe();
datastore.findAll(Author, null, new HttpHeaders({ Authorization: 'Bearer' })).subscribe();

const queryRequest = httpMock.expectOne({ method: 'GET', url: expectedUrl });
expect(queryRequest.request.headers.get('Authorization')).toEqual('Bearer');
Expand All @@ -131,7 +131,7 @@ describe('JsonApiDatastore', () => {
const expectedUrl = `${BASE_URL}/${API_VERSION}/authors`;

datastore.headers = new HttpHeaders({ Authorization: 'Bearer' });
datastore.query(Author, null, new HttpHeaders({ Authorization: 'Basic' })).subscribe();
datastore.findAll(Author, null, new HttpHeaders({ Authorization: 'Basic' })).subscribe();

const queryRequest = httpMock.expectOne({ method: 'GET', url: expectedUrl });
expect(queryRequest.request.headers.get('Authorization')).toEqual('Basic');
Expand All @@ -141,7 +141,8 @@ describe('JsonApiDatastore', () => {
it('should get authors', () => {
const expectedUrl = `${BASE_URL}/${API_VERSION}/authors`;

datastore.query(Author).subscribe((authors) => {
datastore.findAll(Author).subscribe((data: JsonApiQueryData<Author>) => {
const authors = data.getModels();
expect(authors).toBeDefined();
expect(authors.length).toEqual(1);
expect(authors[0].id).toEqual(AUTHOR_ID);
Expand Down Expand Up @@ -204,7 +205,7 @@ describe('JsonApiDatastore', () => {
]
};

datastore.query(Author).subscribe(
datastore.findAll(Author).subscribe(
(authors) => fail('onNext has been called'),
(response) => {
expect(response).toEqual(jasmine.any(ErrorResponse));
Expand Down Expand Up @@ -234,7 +235,7 @@ describe('JsonApiDatastore', () => {
const expectedQueryString = 'arrayParam[]=4&arrayParam[]=5&arrayParam[]=6';
const expectedUrl = encodeURI(`${BASE_URL}/${API_VERSION}/books?${expectedQueryString}`);

datastore.query(Book, { arrayParam: [4, 5, 6] }).subscribe();
datastore.findAll(Book, { arrayParam: [4, 5, 6] }).subscribe();

const queryRequest = httpMock.expectOne(expectedUrl);
queryRequest.flush({ data: [] });
Expand Down