@@ -26,7 +26,7 @@ import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.s
2626import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service' ;
2727import { Angulartics2 , RouterlessTracking } from 'angulartics2' ;
2828import {
29- SubmissionJsonPatchOperationsService
29+ SubmissionJsonPatchOperationsService
3030} from '../../../core/submission/submission-json-patch-operations.service' ;
3131import { AuthService } from '../../../core/auth/auth.service' ;
3232import { RequestService } from '../../../core/data/request.service' ;
@@ -45,7 +45,7 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/
4545import { DspaceRestService } from '../../../core/dspace-rest/dspace-rest.service' ;
4646import { mockSubmissionCollectionId , mockSubmissionId } from '../../../shared/mocks/submission.mock' ;
4747import {
48- WorkspaceitemSectionUnpaywallObject
48+ WorkspaceitemSectionUnpaywallObject
4949} from '../../../core/submission/models/workspaceitem-section-unpaywall-object' ;
5050import { UnpaywallSectionStatus } from './models/unpaywall-section-status' ;
5151import { of } from 'rxjs' ;
@@ -55,7 +55,7 @@ import { SubmissionObject } from '../../../core/submission/models/submission-obj
5555import { SectionsType } from '../sections-type' ;
5656import { WorkspaceitemSectionUploadObject } from '../../../core/submission/models/workspaceitem-section-upload.model' ;
5757import {
58- WorkspaceitemSectionUploadFileObject
58+ WorkspaceitemSectionUploadFileObject
5959} from '../../../core/submission/models/workspaceitem-section-upload-file.model' ;
6060import { RawRestResponse } from '../../../core/dspace-rest/raw-rest-response.model' ;
6161import { SubmissionState } from '../../submission.reducers' ;
@@ -171,78 +171,62 @@ describe('SubmissionSectionUnpaywallComponentComponent', () => {
171171 expect ( component ) . toBeTruthy ( ) ;
172172 } ) ;
173173
174- describe ( 'import file' , ( ) => {
175- it ( 'should import the linked resource if needed' , ( ) => {
174+ describe ( 'import file' , ( ) => {
175+ it ( 'should import the linked resource if needed' , ( ) => {
176176 const submissionObjectName = 'workspaceitems' ;
177177 const testEndpoint = 'http://test-endpoint' ;
178178 const successLabel = of ( 'success-label' ) ;
179- const uploadSection : WorkspaceitemSectionUploadObject = { files : [ ] } ;
180- const successfulSection : WorkspaceitemSectionUnpaywallObject = {
181- id : 1 ,
182- status : UnpaywallSectionStatus . SUCCESSFUL ,
183- doi : 'test-doi' ,
184- itemId : 'test-item-id' ,
185- timestampCreated : new Date ( ) ,
186- timestampLastModified : new Date ( )
187- } ;
188- const submissionObject = {
179+ const uploadSection : WorkspaceitemSectionUploadObject = { files : [ ] } ;
180+ const successfulSection : WorkspaceitemSectionUnpaywallObject = {
181+ id : 1 ,
182+ status : UnpaywallSectionStatus . SUCCESSFUL ,
183+ doi : 'test-doi' ,
184+ itemId : 'test-item-id' ,
185+ timestampCreated : new Date ( ) ,
186+ timestampLastModified : new Date ( )
187+ } ;
188+ const importedResource = {
189189 sections : {
190190 [ SectionsType . Unpaywall ] : {
191- id : 2 ,
192- status : UnpaywallSectionStatus . PENDING ,
191+ status : UnpaywallSectionStatus . IMPORTED ,
193192 doi : 'test-doi' ,
194193 itemId : 'test-item-id' ,
195194 timestampCreated : new Date ( ) ,
196195 timestampLastModified : new Date ( )
197196 } as WorkspaceitemSectionUnpaywallObject ,
198- [ SectionsType . Upload ] : { files : [ ] } as WorkspaceitemSectionUploadObject
197+ [ SectionsType . Upload ] : {
198+ files : [ {
199+ uuid : 'uploaded-file-bitstream-uuid'
200+ } as WorkspaceitemSectionUploadFileObject ]
201+ } as WorkspaceitemSectionUploadObject
199202 }
200203 } as unknown as SubmissionObject ;
201- component . unpaywallSection$ . next ( successfulSection ) ;
202- component . uploadSection$ . next ( { [ SectionsType . Upload ] : uploadSection } ) ;
203- const requestResponse = { payload : submissionObject } as unknown as RawRestResponse ;
204- jasmine . clock ( ) . install ( ) ;
204+ component . unpaywallSection$ . next ( successfulSection ) ;
205+ component . uploadSection$ . next ( { [ SectionsType . Upload ] : uploadSection } ) ;
206+ const requestResponse = { payload : importedResource } as unknown as RawRestResponse ;
207+ jasmine . clock ( ) . install ( ) ;
205208
206209 spyOn ( submissionService , 'getSubmissionObjectLinkName' ) . and . returnValue ( submissionObjectName ) ;
207210 spyOn ( halService , 'getEndpoint' ) . withArgs ( submissionObjectName ) . and . returnValue ( of ( testEndpoint ) ) ;
208211 spyOn ( tokenExtractor , 'getToken' ) . and . returnValue ( xsrfToken ) ;
209- const responseSpy = spyOn ( restApi , 'request' ) . and . returnValue ( of ( requestResponse ) ) ;
212+ spyOn ( restApi , 'request' ) . and . returnValue ( of ( requestResponse ) ) ;
210213 spyOn ( sectionService , 'isSectionType' )
211214 . withArgs ( mockSubmissionId , SectionsType . Unpaywall , SectionsType . Upload ) . and . returnValue ( of ( false ) )
212215 . withArgs ( mockSubmissionId , SectionsType . Upload , SectionsType . Upload ) . and . returnValue ( of ( true ) ) ;
213- spyOn ( translate , 'get' ) . withArgs ( 'submission.sections.unpaywall.status.imported' ) . and . returnValue ( successLabel ) ;
214- spyOn ( component . loading$ , 'next' ) ;
215- spyOn ( component . status$ , 'next' ) ;
216- spyOn ( component . unpaywallSection$ , 'next' ) ;
216+ spyOn ( translate , 'get' ) . withArgs ( 'submission.sections.unpaywall.status.imported' ) . and . returnValue ( successLabel ) ;
217+ spyOn ( component . loading$ , 'next' ) ;
218+ spyOn ( component . status$ , 'next' ) ;
219+ spyOn ( component . unpaywallSection$ , 'next' ) ;
217220 spyOn ( notificationsService , 'success' ) . withArgs ( null , successLabel ) ;
218221 spyOn ( notificationsService , 'error' ) ;
219222
220- component . confirmImport ( ) ;
221- const importedResource = {
222- sections : {
223- [ SectionsType . Unpaywall ] : {
224- status : UnpaywallSectionStatus . IMPORTED ,
225- doi : 'test-doi' ,
226- itemId : 'test-item-id' ,
227- timestampCreated : new Date ( ) ,
228- timestampLastModified : new Date ( )
229- } as WorkspaceitemSectionUnpaywallObject ,
230- [ SectionsType . Upload ] : {
231- files : [ {
232- uuid : 'uploaded-file-bitstream-uuid'
233- } as WorkspaceitemSectionUploadFileObject ]
234- } as WorkspaceitemSectionUploadObject
235- }
236- } as unknown as SubmissionObject ;
237- const importedResponse = { payload : importedResource } as unknown as RawRestResponse ;
238- responseSpy . and . returnValue ( of ( importedResponse ) ) ;
239- jasmine . clock ( ) . tick ( 3010 ) ;
223+ component . confirmImport ( ) ;
240224
241- expect ( component . loading$ . next ) . toHaveBeenCalledWith ( false ) ;
242- expect ( component . status$ . next ) . toHaveBeenCalledOnceWith ( ( importedResource . sections [ SectionsType . Unpaywall ] as WorkspaceitemSectionUnpaywallObject ) . status ) ;
243- expect ( component . unpaywallSection$ . next ) . toHaveBeenCalledWith ( importedResource . sections [ SectionsType . Unpaywall ] as WorkspaceitemSectionUnpaywallObject ) ;
244- expect ( sectionUploadService . addUploadedFile ) . toHaveBeenCalledTimes ( 1 ) ;
245- jasmine . clock ( ) . uninstall ( ) ;
225+ expect ( component . loading$ . next ) . toHaveBeenCalledWith ( false ) ;
226+ expect ( component . status$ . next ) . toHaveBeenCalledOnceWith ( ( importedResource . sections [ SectionsType . Unpaywall ] as WorkspaceitemSectionUnpaywallObject ) . status ) ;
227+ expect ( component . unpaywallSection$ . next ) . toHaveBeenCalledWith ( importedResource . sections [ SectionsType . Unpaywall ] as WorkspaceitemSectionUnpaywallObject ) ;
228+ expect ( sectionUploadService . addUploadedFile ) . toHaveBeenCalledTimes ( 1 ) ;
229+ jasmine . clock ( ) . uninstall ( ) ;
246230 } ) ;
247231 } ) ;
248232
0 commit comments