mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
finished embedded object fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { ConfigSuccessResponse, ErrorResponse } from '../cache/response-cache.models';
|
||||
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
|
||||
import { ConfigResponseParsingService } from './config-response-parsing.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { GlobalConfig } from '../../../config/global-config.interface';
|
||||
@@ -8,7 +7,8 @@ import { ConfigRequest } from './request.models';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { SubmissionDefinitionsModel } from '../shared/config/config-submission-definitions.model';
|
||||
import { SubmissionSectionModel } from '../shared/config/config-submission-section.model';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
|
||||
describe('ConfigResponseParsingService', () => {
|
||||
let service: ConfigResponseParsingService;
|
||||
@@ -16,141 +16,143 @@ describe('ConfigResponseParsingService', () => {
|
||||
const EnvConfig = {} as GlobalConfig;
|
||||
const store = {} as Store<CoreState>;
|
||||
const objectCacheService = new ObjectCacheService(store);
|
||||
|
||||
let validResponse;
|
||||
beforeEach(() => {
|
||||
service = new ConfigResponseParsingService(EnvConfig, objectCacheService);
|
||||
validResponse = {
|
||||
payload: {
|
||||
id: 'traditional',
|
||||
name: 'traditional',
|
||||
type: 'submissiondefinition',
|
||||
isDefault: true,
|
||||
_links: {
|
||||
sections: {
|
||||
href: 'https://rest.api/config/submissiondefinitions/traditional/sections'
|
||||
},
|
||||
self: {
|
||||
href: 'https://rest.api/config/submissiondefinitions/traditional'
|
||||
}
|
||||
},
|
||||
_embedded: {
|
||||
sections: {
|
||||
page: {
|
||||
number: 0,
|
||||
size: 4,
|
||||
totalPages: 1, totalElements: 4
|
||||
},
|
||||
_embedded: [
|
||||
{
|
||||
id: 'traditionalpageone', header: 'submit.progressbar.describe.stepone',
|
||||
mandatory: true,
|
||||
sectionType: 'submission-form',
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/config/submissionsections/traditionalpageone'
|
||||
},
|
||||
config: {
|
||||
href: 'https://rest.api/config/submissionforms/traditionalpageone'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
id: 'traditionalpagetwo',
|
||||
header: 'submit.progressbar.describe.steptwo',
|
||||
mandatory: true,
|
||||
sectionType: 'submission-form',
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/config/submissionsections/traditionalpagetwo'
|
||||
},
|
||||
config: {
|
||||
href: 'https://rest.api/config/submissionforms/traditionalpagetwo'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
id: 'upload',
|
||||
header: 'submit.progressbar.upload',
|
||||
mandatory: false,
|
||||
sectionType: 'upload',
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/config/submissionsections/upload'
|
||||
},
|
||||
config: {
|
||||
href: 'https://rest.api/config/submissionuploads/upload'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
id: 'license',
|
||||
header: 'submit.progressbar.license',
|
||||
mandatory: true,
|
||||
sectionType: 'license',
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/config/submissionsections/license'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/config/submissiondefinitions/traditional/sections'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
statusCode: '200'
|
||||
};
|
||||
});
|
||||
|
||||
describe('parse', () => {
|
||||
const validRequest = new ConfigRequest('69f375b5-19f4-4453-8c7a-7dc5c55aafbb', 'https://rest.api/config/submissiondefinitions/traditional');
|
||||
|
||||
const validResponse = {
|
||||
payload: {
|
||||
id:'traditional',
|
||||
name:'traditional',
|
||||
type:'submissiondefinition',
|
||||
isDefault:true,
|
||||
_links:{
|
||||
sections:{
|
||||
href:'https://rest.api/config/submissiondefinitions/traditional/sections'
|
||||
},self:{
|
||||
href:'https://rest.api/config/submissiondefinitions/traditional'
|
||||
}
|
||||
},
|
||||
_embedded:{
|
||||
sections:{
|
||||
page:{
|
||||
number:0,
|
||||
size:4,
|
||||
totalPages:1,totalElements:4
|
||||
},
|
||||
_embedded:[
|
||||
{
|
||||
id:'traditionalpageone',header:'submit.progressbar.describe.stepone',
|
||||
mandatory:true,
|
||||
sectionType:'submission-form',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type:'submissionsection',
|
||||
_links:{
|
||||
self:{
|
||||
href:'https://rest.api/config/submissionsections/traditionalpageone'
|
||||
},
|
||||
config:{
|
||||
href:'https://rest.api/config/submissionforms/traditionalpageone'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
id:'traditionalpagetwo',
|
||||
header:'submit.progressbar.describe.steptwo',
|
||||
mandatory:true,
|
||||
sectionType:'submission-form',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type:'submissionsection',
|
||||
_links:{
|
||||
self:{
|
||||
href:'https://rest.api/config/submissionsections/traditionalpagetwo'
|
||||
},
|
||||
config:{
|
||||
href:'https://rest.api/config/submissionforms/traditionalpagetwo'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
id:'upload',
|
||||
header:'submit.progressbar.upload',
|
||||
mandatory:false,
|
||||
sectionType:'upload',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type:'submissionsection',
|
||||
_links:{
|
||||
self:{
|
||||
href:'https://rest.api/config/submissionsections/upload'
|
||||
},
|
||||
config: {
|
||||
href:'https://rest.api/config/submissionuploads/upload'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
id:'license',
|
||||
header:'submit.progressbar.license',
|
||||
mandatory:true,
|
||||
sectionType:'license',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type:'submissionsection',
|
||||
_links:{
|
||||
self:{
|
||||
href:'https://rest.api/config/submissionsections/license'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
_links:{
|
||||
self:'https://rest.api/config/submissiondefinitions/traditional/sections'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
statusCode:'200'
|
||||
};
|
||||
|
||||
const invalidResponse1 = {
|
||||
payload: {},
|
||||
statusCode:'200'
|
||||
statusCode: '200'
|
||||
};
|
||||
|
||||
const invalidResponse2 = {
|
||||
payload: {
|
||||
id:'traditional',
|
||||
name:'traditional',
|
||||
type:'submissiondefinition',
|
||||
isDefault:true,
|
||||
_links:{},
|
||||
_embedded:{
|
||||
sections:{
|
||||
page:{
|
||||
number:0,
|
||||
size:4,
|
||||
totalPages:1,totalElements:4
|
||||
id: 'traditional',
|
||||
name: 'traditional',
|
||||
type: 'submissiondefinition',
|
||||
isDefault: true,
|
||||
_links: {},
|
||||
_embedded: {
|
||||
sections: {
|
||||
page: {
|
||||
number: 0,
|
||||
size: 4,
|
||||
totalPages: 1, totalElements: 4
|
||||
},
|
||||
_embedded:[{},{}],
|
||||
_links:{
|
||||
self:'https://rest.api/config/submissiondefinitions/traditional/sections'
|
||||
_embedded: [{}, {}],
|
||||
_links: {
|
||||
self: 'https://rest.api/config/submissiondefinitions/traditional/sections'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
statusCode:'200'
|
||||
statusCode: '200'
|
||||
};
|
||||
|
||||
const invalidResponse3 = {
|
||||
@@ -159,61 +161,24 @@ describe('ConfigResponseParsingService', () => {
|
||||
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
||||
}, statusCode: '500'
|
||||
};
|
||||
|
||||
const definitions = [
|
||||
const pageinfo = Object.assign(new PageInfo(), { elementsPerPage: 4, totalElements: 4, totalPages: 1, currentPage: 1 });
|
||||
const definitions =
|
||||
Object.assign(new SubmissionDefinitionsModel(), {
|
||||
isDefault: true,
|
||||
name: 'traditional',
|
||||
type: 'submissiondefinition',
|
||||
_links: {},
|
||||
sections: [
|
||||
Object.assign(new SubmissionSectionModel(), {
|
||||
header: 'submit.progressbar.describe.stepone',
|
||||
mandatory: true,
|
||||
sectionType: 'submission-form',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {}
|
||||
}),
|
||||
Object.assign(new SubmissionSectionModel(), {
|
||||
header: 'submit.progressbar.describe.steptwo',
|
||||
mandatory: true,
|
||||
sectionType: 'submission-form',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {}
|
||||
}),
|
||||
Object.assign(new SubmissionSectionModel(), {
|
||||
header: 'submit.progressbar.upload',
|
||||
mandatory: false,
|
||||
sectionType: 'upload',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {}
|
||||
}),
|
||||
Object.assign(new SubmissionSectionModel(), {
|
||||
header: 'submit.progressbar.license',
|
||||
mandatory: true,
|
||||
sectionType: 'license',
|
||||
visibility:{
|
||||
main:null,
|
||||
other:'READONLY'
|
||||
},
|
||||
type: 'submissionsection',
|
||||
_links: {}
|
||||
})
|
||||
]
|
||||
})
|
||||
];
|
||||
_links: {
|
||||
sections: 'https://rest.api/config/submissiondefinitions/traditional/sections',
|
||||
self: 'https://rest.api/config/submissiondefinitions/traditional'
|
||||
},
|
||||
self: 'https://rest.api/config/submissiondefinitions/traditional',
|
||||
sections: new PaginatedList(pageinfo, [
|
||||
'https://rest.api/config/submissionsections/traditionalpageone',
|
||||
'https://rest.api/config/submissionsections/traditionalpagetwo',
|
||||
'https://rest.api/config/submissionsections/upload',
|
||||
'https://rest.api/config/submissionsections/license'
|
||||
])
|
||||
});
|
||||
|
||||
it('should return a ConfigSuccessResponse if data contains a valid config endpoint response', () => {
|
||||
const response = service.parse(validRequest, validResponse);
|
||||
@@ -232,11 +197,8 @@ describe('ConfigResponseParsingService', () => {
|
||||
expect(response.constructor).toBe(ErrorResponse);
|
||||
});
|
||||
|
||||
fit('should return a ConfigSuccessResponse with the ConfigDefinitions in data', () => {
|
||||
it('should return a ConfigSuccessResponse with the ConfigDefinitions in data', () => {
|
||||
const response = service.parse(validRequest, validResponse);
|
||||
debugger;
|
||||
console.log(definitions);
|
||||
console.log((response as any).configDefinition);
|
||||
expect((response as any).configDefinition).toEqual(definitions);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user