fixes for tests

This commit is contained in:
lotte
2018-08-02 15:31:37 +02:00
parent 117a0cd3ff
commit 11f4befceb
2 changed files with 24 additions and 15 deletions

View File

@@ -8,6 +8,8 @@ import { CoreState } from '../core.reducers';
import { IntegrationResponseParsingService } from './integration-response-parsing.service';
import { IntegrationRequest } from '../data/request.models';
import { AuthorityValueModel } from './models/authority-value.model';
import { PageInfo } from '../shared/page-info.model';
import { PaginatedList } from '../data/paginated-list';
describe('IntegrationResponseParsingService', () => {
let service: IntegrationResponseParsingService;
@@ -78,7 +80,7 @@ describe('IntegrationResponseParsingService', () => {
},
_links: {
self: 'https://rest.api/integration/authorities/type/entries'
self: { href: 'https://rest.api/integration/authorities/type/entries' }
}
},
statusCode: '200'
@@ -141,39 +143,44 @@ describe('IntegrationResponseParsingService', () => {
},
statusCode: '200'
};
const definitions = [
Object.assign(new AuthorityValueModel(), {
const pageinfo = Object.assign(new PageInfo(), { elementsPerPage: 5, totalElements: 5, totalPages: 1, currentPage: 1 });
const definitions = new PaginatedList(pageinfo,[
Object.assign({}, new AuthorityValueModel(), {
type: 'authority',
display: 'One',
id: 'One',
otherInformation: {},
otherInformation: undefined,
value: 'One'
}),
Object.assign(new AuthorityValueModel(), {
Object.assign({}, new AuthorityValueModel(), {
type: 'authority',
display: 'Two',
id: 'Two',
otherInformation: {},
otherInformation: undefined,
value: 'Two'
}),
Object.assign(new AuthorityValueModel(), {
Object.assign({}, new AuthorityValueModel(), {
type: 'authority',
display: 'Three',
id: 'Three',
otherInformation: {},
otherInformation: undefined,
value: 'Three'
}),
Object.assign(new AuthorityValueModel(), {
Object.assign({}, new AuthorityValueModel(), {
type: 'authority',
display: 'Four',
id: 'Four',
otherInformation: {},
otherInformation: undefined,
value: 'Four'
}),
Object.assign(new AuthorityValueModel(), {
Object.assign({}, new AuthorityValueModel(), {
type: 'authority',
display: 'Five',
id: 'Five',
otherInformation: {},
otherInformation: undefined,
value: 'Five'
})
];
]);
it('should return a IntegrationSuccessResponse if data contains a valid endpoint response', () => {
const response = service.parse(validRequest, validResponse);
@@ -189,6 +196,8 @@ describe('IntegrationResponseParsingService', () => {
it('should return a IntegrationSuccessResponse with data definition', () => {
const response = service.parse(validRequest, validResponse);
console.log((response as any).dataDefinition);
console.log(definitions);
expect((response as any).dataDefinition).toEqual(definitions);
});

View File

@@ -33,7 +33,7 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
const dataDefinition = this.process<IntegrationModel,IntegrationType>(data.payload, request.href);
return new IntegrationSuccessResponse(dataDefinition[Object.keys(dataDefinition)[0]], data.statusCode, this.processPageInfo(data.payload.page));
return new IntegrationSuccessResponse(dataDefinition, data.statusCode, this.processPageInfo(data.payload.page));
} else {
return new ErrorResponse(
Object.assign(