Skip to content

Commit

Permalink
Added coverage for retrieveAllAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeweatherhead committed Jul 25, 2023
1 parent 9116a53 commit 136c7e4
Showing 1 changed file with 120 additions and 66 deletions.
186 changes: 120 additions & 66 deletions backend/src/asset_manager/asset_manager.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,70 +97,124 @@ describe('AssetManagerService', () => {
});
});

// describe('retrieve_all', () => {
// it('should retrieve all assets from the db', async () => {
// const retrieveAllDTO = new RetrieveAllDTO();
// retrieveAllDTO.UserID = 1;

// const assetDTO = new AssetDTO();
// assetDTO.AssetID = 'test';

// jest.spyOn(
// assetsService,
// 'retrieveAllAssets',
// );

// await service.retrieve_all(retrieveAllDTO);

// expect(
// assetsService.retrieveAllAssets,
// ).toBeCalledWith(retrieveAllDTO);
// });

// it('should resize all image assets', async () => {
// const retrieveAllDTO = new RetrieveAllDTO();
// retrieveAllDTO.UserID = 1;

// const assetDTO = new AssetDTO();
// assetDTO.AssetID = 'test';
// assetDTO.Format = 'image';
// assetDTO.UserID = 1;
// assetDTO.Content = 'Uncompressed content';

// const newAssetDTO = new AssetDTO();
// newAssetDTO.AssetID = 'test';
// newAssetDTO.UserID = 1;
// newAssetDTO.ConvertedElement = '';
// newAssetDTO.Image = 'Compressed content';

// const assets = [assetDTO];

// jest
// .spyOn(assetsService, 'retrieveAllAssets')
// .mockResolvedValue(assets);

// jest
// .spyOn(imageManagerService, 'retrieveOne')
// .mockResolvedValue(newAssetDTO);

// jest
// .spyOn(
// imageManagerService,
// 'compressImage',
// )
// .mockResolvedValue('Compressed content');

// const response = await service.retrieve_all(
// retrieveAllDTO,
// );

// expect(response).toEqual([newAssetDTO]);
// expect(
// imageManagerService.retrieveOne,
// ).toBeCalledWith(assetDTO);
// expect(
// imageManagerService.compressImage,
// ).toBeCalledWith(assetDTO.Content);
// });
// });
describe('retrieve_all', (/** TDD FTW */) => {
it('should retrieve all assets from the db', async () => {
const retrieveAllDTO = new RetrieveAllDTO();
retrieveAllDTO.UserID = 1;
retrieveAllDTO.ParentFolderID = 'test';

const assetDTO = new AssetDTO();
assetDTO.AssetID = 'test';
assetDTO.Format = 'image';
assetDTO.UserID = 1;
const assets = [assetDTO];

jest
.spyOn(assetsService, 'retrieveAllAssets')
.mockResolvedValue(assets);

jest
.spyOn(
Repository.prototype,
'createQueryBuilder',
)
.mockReturnValue({
where: jest.fn().mockReturnThis(),
andWhere: jest.fn().mockReturnThis(),
orderBy: jest.fn().mockReturnThis(),
getMany: jest
.fn()
.mockResolvedValue([]),
} as any);

jest
.spyOn(
imageManagerService,
'retrieveOne',
)
.mockResolvedValue(assetDTO);

jest
.spyOn(
assetsService,
'retrieveOne',
)

jest
.spyOn(
S3Service.prototype,
'retrieveAsset',
)
.mockResolvedValue(assetDTO);

jest
.spyOn(
imageManagerService,
'compressImage',
)
.mockResolvedValue('Compressed content');

await service.retrieve_all(
retrieveAllDTO,
);

expect(
assetsService.retrieveAllAssets,
).toBeCalledWith(retrieveAllDTO);

// expect(
// imageManagerService.retrieveOne,
// ).toBeCalledWith(assetDTO);

// expect(
// imageManagerService.compressImage,
// ).toBeCalledWith(assetDTO.Content);
});

// it('should resize all image assets', async () => {
// const retrieveAllDTO = new RetrieveAllDTO();
// retrieveAllDTO.UserID = 1;

// const assetDTO = new AssetDTO();
// assetDTO.AssetID = 'test';
// assetDTO.Format = 'image';
// assetDTO.UserID = 1;
// assetDTO.Content = 'Uncompressed content';

// const newAssetDTO = new AssetDTO();
// newAssetDTO.AssetID = 'test';
// newAssetDTO.UserID = 1;
// newAssetDTO.ConvertedElement = '';
// newAssetDTO.Image = 'Compressed content';

// const assets = [assetDTO];

// jest
// .spyOn(assetsService, 'retrieveAllAssets')
// .mockResolvedValue(assets);

// jest
// .spyOn(imageManagerService, 'retrieveOne')
// .mockResolvedValue(newAssetDTO);

// jest
// .spyOn(
// imageManagerService,
// 'compressImage',
// )
// .mockResolvedValue('Compressed content');

// const response = await service.retrieve_all(
// retrieveAllDTO,
// );

// expect(response).toEqual([newAssetDTO]);
// expect(
// imageManagerService.retrieveOne,
// ).toBeCalledWith(assetDTO);
// expect(
// imageManagerService.compressImage,
// ).toBeCalledWith(assetDTO.Content);
// });
});
});

0 comments on commit 136c7e4

Please sign in to comment.