Skip to content

Commit

Permalink
add ut for cleanupRecordAttachments
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Oct 22, 2024
1 parent 7db601c commit f318700
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,37 @@ describe('Gn4PlatformService', () => {
record.uniqueIdentifier
)
})
it('should clean record attachments no longer used', (done) => {
const record = { uniqueIdentifier: '123' } as CatalogRecord
const associatedResources = {
onlines: [{ title: { en: 'doge.jpg' } }],
thumbnails: [{ title: { en: 'flower.jpg' } }],
}
;(recordsApiService.getAssociatedResources as jest.Mock).mockReturnValue(
of(associatedResources)
)
;(recordsApiService.getAllResources as jest.Mock).mockReturnValue(
of([
{ filename: 'doge.jpg' },
{ filename: 'flower.jpg' },
{ filename: 'remove1.jpg' },
])
)
;(recordsApiService.delResource as jest.Mock).mockReturnValue(
of(undefined)
)

service.cleanRecordAttachments(record).subscribe({
next: () => {
expect(recordsApiService.delResource).toHaveBeenCalledWith(
record.uniqueIdentifier,
'remove1.jpg'
)
done()
},
error: done.fail,
})
})
})

describe('attachFileToRecord', () => {
Expand Down

0 comments on commit f318700

Please sign in to comment.