Skip to content

Commit

Permalink
chore: e2e for duplicate asset
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Mar 22, 2024
1 parent 40632ae commit 665cf21
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cli/src/commands/asset.ts
Expand Up @@ -115,7 +115,7 @@ const checkForDuplicates = async (files: string[], { concurrency }: UploadOption
progressBar.stop();
}

console.log(`Found ${newFiles.length} new files and ${duplicates.length} duplicates`);
console.log(`Found ${newFiles.length} new files and ${duplicates.length} duplicate${s(duplicates.length)}`);

return { newFiles, duplicates };
};
Expand Down
3 changes: 2 additions & 1 deletion e2e/src/cli/specs/server-info.e2e-spec.ts
Expand Up @@ -4,7 +4,8 @@ import { beforeAll, describe, expect, it } from 'vitest';
describe(`immich server-info`, () => {
beforeAll(async () => {
await utils.resetDatabase();
await utils.cliLogin();
const admin = await utils.adminSetup();
await utils.cliLogin(admin.accessToken);
});

it('should return the server info', async () => {
Expand Down
29 changes: 27 additions & 2 deletions e2e/src/cli/specs/upload.e2e-spec.ts
@@ -1,14 +1,17 @@
import { getAllAlbums, getAllAssets } from '@immich/sdk';
import { LoginResponseDto, getAllAlbums, getAllAssets } from '@immich/sdk';
import { mkdir, readdir, rm, symlink } from 'node:fs/promises';
import { asKeyAuth, immichCli, testAssetDir, utils } from 'src/utils';
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';

describe(`immich upload`, () => {
let admin: LoginResponseDto;
let key: string;

beforeAll(async () => {
await utils.resetDatabase();
key = await utils.cliLogin();

admin = await utils.adminSetup();
key = await utils.cliLogin(admin.accessToken);
});

beforeEach(async () => {
Expand All @@ -27,6 +30,28 @@ describe(`immich upload`, () => {
const assets = await getAllAssets({}, { headers: asKeyAuth(key) });
expect(assets.length).toBe(1);
});

it('should skip a duplicate file', async () => {
const first = await immichCli(['upload', `${testAssetDir}/albums/nature/silver_fir.jpg`]);
expect(first.stderr).toBe('');
expect(first.stdout.split('\n')).toEqual(
expect.arrayContaining([expect.stringContaining('Successfully uploaded 1 asset')]),
);
expect(first.exitCode).toBe(0);

const assets = await getAllAssets({}, { headers: asKeyAuth(key) });
expect(assets.length).toBe(1);

const second = await immichCli(['upload', `${testAssetDir}/albums/nature/silver_fir.jpg`]);
expect(second.stderr).toBe('');
expect(second.stdout.split('\n')).toEqual(
expect.arrayContaining([
expect.stringContaining('Found 0 new files and 1 duplicate'),
expect.stringContaining('All assets were already uploaded, nothing to do'),
]),
);
expect(first.exitCode).toBe(0);
});
});

describe('immich upload --recursive', () => {
Expand Down
5 changes: 2 additions & 3 deletions e2e/src/utils.ts
Expand Up @@ -404,9 +404,8 @@ export const utils = {
},
]),

cliLogin: async () => {
const admin = await utils.adminSetup();
const key = await utils.createApiKey(admin.accessToken);
cliLogin: async (accessToken: string) => {
const key = await utils.createApiKey(accessToken);
await immichCli(['login-key', app, `${key.secret}`]);
return key.secret;
},
Expand Down

0 comments on commit 665cf21

Please sign in to comment.