refactor(server): e2e ()

* refactor: activity e2e

* refactor: person e2e

* refactor: shared link e2e
This commit is contained in:
Jason Rasmussen 2024-02-21 08:28:03 -05:00 committed by GitHub
parent a1bc74cdd6
commit f798e037d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 573 additions and 459 deletions
e2e/src

View file

@ -2,13 +2,15 @@ import {
AssetResponseDto,
CreateAssetDto,
CreateUserDto,
LoginResponseDto,
PersonUpdateDto,
createApiKey,
createPerson,
createUser,
defaults,
login,
setAdminOnboarding,
signUpAdmin,
updatePerson,
} from '@immich/sdk';
import { BrowserContext } from '@playwright/test';
import { spawn } from 'child_process';
@ -45,7 +47,36 @@ export const asKeyAuth = (key: string) => ({ 'x-api-key': key });
let client: pg.Client | null = null;
export const dbUtils = {
reset: async () => {
createFace: async ({
assetId,
personId,
}: {
assetId: string;
personId: string;
}) => {
if (!client) {
return;
}
const vector = Array.from({ length: 512 }, Math.random);
const embedding = `[${vector.join(',')}]`;
await client.query(
'INSERT INTO asset_faces ("assetId", "personId", "embedding") VALUES ($1, $2, $3)',
[assetId, personId, embedding]
);
},
setPersonThumbnail: async (personId: string) => {
if (!client) {
return;
}
await client.query(
`UPDATE "person" set "thumbnailPath" = '/my/awesome/thumbnail.jpg' where "id" = $1`,
[personId]
);
},
reset: async (tables?: string[]) => {
try {
if (!client) {
client = new pg.Client(
@ -54,14 +85,20 @@ export const dbUtils = {
await client.connect();
}
for (const table of [
tables = tables || [
'shared_links',
'person',
'albums',
'assets',
'asset_faces',
'activity',
'api_keys',
'user_token',
'users',
'system_metadata',
]) {
];
for (const table of tables) {
await client.query(`DELETE FROM ${table} CASCADE;`);
}
} catch (error) {
@ -165,6 +202,15 @@ export const apiUtils = {
return body as AssetResponseDto;
},
createPerson: async (accessToken: string, dto: PersonUpdateDto) => {
// TODO fix createPerson to accept a body
const { id } = await createPerson({ headers: asBearerAuth(accessToken) });
await dbUtils.setPersonThumbnail(id);
return updatePerson(
{ id, personUpdateDto: dto },
{ headers: asBearerAuth(accessToken) }
);
},
};
export const cliUtils = {