|
@@ -36,7 +36,10 @@ describe(StorageTemplateService.name, () => {
|
|
|
|
|
|
describe('handle template migration', () => {
|
|
describe('handle template migration', () => {
|
|
it('should handle no assets', async () => {
|
|
it('should handle no assets', async () => {
|
|
- assetMock.getAll.mockResolvedValue([]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
userMock.getList.mockResolvedValue([]);
|
|
userMock.getList.mockResolvedValue([]);
|
|
|
|
|
|
await sut.handleTemplateMigration();
|
|
await sut.handleTemplateMigration();
|
|
@@ -45,7 +48,10 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should handle an asset with a duplicate destination', async () => {
|
|
it('should handle an asset with a duplicate destination', async () => {
|
|
- assetMock.getAll.mockResolvedValue([assetEntityStub.image]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [assetEntityStub.image],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
assetMock.save.mockResolvedValue(assetEntityStub.image);
|
|
assetMock.save.mockResolvedValue(assetEntityStub.image);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
|
|
|
|
@@ -69,12 +75,15 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should skip when an asset already matches the template', async () => {
|
|
it('should skip when an asset already matches the template', async () => {
|
|
- assetMock.getAll.mockResolvedValue([
|
|
|
|
- {
|
|
|
|
- ...assetEntityStub.image,
|
|
|
|
- originalPath: 'upload/library/user-id/2023/2023-02-23/asset-id.ext',
|
|
|
|
- },
|
|
|
|
- ]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [
|
|
|
|
+ {
|
|
|
|
+ ...assetEntityStub.image,
|
|
|
|
+ originalPath: 'upload/library/user-id/2023/2023-02-23/asset-id.ext',
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
|
|
|
|
await sut.handleTemplateMigration();
|
|
await sut.handleTemplateMigration();
|
|
@@ -86,12 +95,15 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should skip when an asset is probably a duplicate', async () => {
|
|
it('should skip when an asset is probably a duplicate', async () => {
|
|
- assetMock.getAll.mockResolvedValue([
|
|
|
|
- {
|
|
|
|
- ...assetEntityStub.image,
|
|
|
|
- originalPath: 'upload/library/user-id/2023/2023-02-23/asset-id+1.ext',
|
|
|
|
- },
|
|
|
|
- ]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [
|
|
|
|
+ {
|
|
|
|
+ ...assetEntityStub.image,
|
|
|
|
+ originalPath: 'upload/library/user-id/2023/2023-02-23/asset-id+1.ext',
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
|
|
|
|
await sut.handleTemplateMigration();
|
|
await sut.handleTemplateMigration();
|
|
@@ -103,7 +115,10 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should move an asset', async () => {
|
|
it('should move an asset', async () => {
|
|
- assetMock.getAll.mockResolvedValue([assetEntityStub.image]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [assetEntityStub.image],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
assetMock.save.mockResolvedValue(assetEntityStub.image);
|
|
assetMock.save.mockResolvedValue(assetEntityStub.image);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
|
|
|
|
@@ -121,7 +136,10 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should use the user storage label', async () => {
|
|
it('should use the user storage label', async () => {
|
|
- assetMock.getAll.mockResolvedValue([assetEntityStub.image]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [assetEntityStub.image],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
assetMock.save.mockResolvedValue(assetEntityStub.image);
|
|
assetMock.save.mockResolvedValue(assetEntityStub.image);
|
|
userMock.getList.mockResolvedValue([userEntityStub.storageLabel]);
|
|
userMock.getList.mockResolvedValue([userEntityStub.storageLabel]);
|
|
|
|
|
|
@@ -139,7 +157,10 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should not update the database if the move fails', async () => {
|
|
it('should not update the database if the move fails', async () => {
|
|
- assetMock.getAll.mockResolvedValue([assetEntityStub.image]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [assetEntityStub.image],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
storageMock.moveFile.mockRejectedValue(new Error('Read only system'));
|
|
storageMock.moveFile.mockRejectedValue(new Error('Read only system'));
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
|
|
|
|
@@ -154,7 +175,10 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should move the asset back if the database fails', async () => {
|
|
it('should move the asset back if the database fails', async () => {
|
|
- assetMock.getAll.mockResolvedValue([assetEntityStub.image]);
|
|
|
|
|
|
+ assetMock.getAll.mockResolvedValue({
|
|
|
|
+ items: [assetEntityStub.image],
|
|
|
|
+ hasNextPage: false,
|
|
|
|
+ });
|
|
assetMock.save.mockRejectedValue('Connection Error!');
|
|
assetMock.save.mockRejectedValue('Connection Error!');
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
userMock.getList.mockResolvedValue([userEntityStub.user1]);
|
|
|
|
|
|
@@ -173,7 +197,6 @@ describe(StorageTemplateService.name, () => {
|
|
});
|
|
});
|
|
|
|
|
|
it('should handle an error', async () => {
|
|
it('should handle an error', async () => {
|
|
- assetMock.getAll.mockResolvedValue([]);
|
|
|
|
storageMock.removeEmptyDirs.mockRejectedValue(new Error('Read only filesystem'));
|
|
storageMock.removeEmptyDirs.mockRejectedValue(new Error('Read only filesystem'));
|
|
userMock.getList.mockResolvedValue([]);
|
|
userMock.getList.mockResolvedValue([]);
|
|
|
|
|