Skip to content

Commit

Permalink
refactor(server): e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Jan 24, 2024
1 parent 4424f3c commit 96a0f7c
Show file tree
Hide file tree
Showing 41 changed files with 43 additions and 294 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pull-stage:
server-e2e-jobs:
docker compose -f ./server/e2e/docker-compose.server-e2e.yml up --renew-anon-volumes --abort-on-container-exit --exit-code-from immich-server --remove-orphans --build

server-e2e-api:
npm run e2e:api --prefix server

prod:
docker compose -f ./docker/docker-compose.prod.yml up --build -V --remove-orphans

Expand Down
2 changes: 1 addition & 1 deletion cli/test/e2e/login-key.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { api } from '@api';
import { restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from '@immich/sdk';
import { LoginKey } from 'src/commands/login/key';
Expand Down
2 changes: 1 addition & 1 deletion cli/test/e2e/server-info.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { api } from '@api';
import { restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from '@immich/sdk';
import { ServerInfo } from 'src/commands/server-info';
Expand Down
2 changes: 1 addition & 1 deletion cli/test/e2e/upload.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { api } from '@api';
import { IMMICH_TEST_ASSET_PATH, restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from '@immich/sdk';
import { Upload } from 'src/commands/upload';
Expand Down
2 changes: 2 additions & 0 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"rootDirs": ["src", "../server/src"],
"baseUrl": "./",
"paths": {
"@api": ["../server/e2e/client"],
"@api/*": ["../server/e2e/client/*"],
"@test": ["../server/test"],
"@test/*": ["../server/test/*"],
"@app/immich": ["../server/src/immich"],
Expand Down
17 changes: 13 additions & 4 deletions docs/docs/developer/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ Unit are run by calling `npm run test` from the `server` directory.

### End to end tests

The backend has an end-to-end test suite that can be called with `npm run test:e2e` from the `server` directory. This will set up a dummy database inside a temporary container and run the tests against it. Setup and teardown is automatically taken care of. That test, however, can not set up all prerequisites to parse file formats, as that is very complex and error-prone. As such, this test excludes some test cases like HEIC file imports. The test suite will also print a friendly warning to remind you that not all tests are being run.
The backend has two end-to-end test suites that can be called with the follow two commands from the project root directory:

Note that there is a bug in nodejs \<20.8 that causes segmentation faults when running these tests. If you run into segfaults, ensure you are using at least version 20.8.
- `make server-e2e-api`
- `make server-e2e-jobs`

#### API (e2e)

The API e2e tests spin up a test database and execute http requests against the server, validating the expected response codes and functionality for API endpoints.

To perform a full e2e test, you need to run e2e tests inside docker. The easiest way to do that is to run `make test-e2e` in the root directory. This will build and start a docker-compose consisting of the server, microservices, and a postgres database. It will then perform the tests and exit.
#### Jobs (e2e)

If you manually install the dependencies (see the DOCKERFILE) on your development machine, you can also run the full e2e tests manually by setting the `IMMICH_RUN_ALL_TESTS` environment value to true, i.e. `IMMICH_RUN_ALL_TESTS=true npm run e2e:jobs`.
The Jobs e2e tests spin up a docker test environment where thumbnail generation, library scanning, and other _job_ workflows are validated.

:::note
Note that there is a bug in nodejs \<20.8 that causes segmentation faults when running these tests. If you run into segfaults, ensure you are using at least version 20.8.
:::
2 changes: 1 addition & 1 deletion server/e2e/api/specs/activity.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AssetFileUploadResponseDto } from '@app/immich/api-v1/asset/response-dt
import { ActivityEntity } from '@app/infra/entities';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${ActivityController.name} (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/album.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AssetFileUploadResponseDto } from '@app/immich/api-v1/asset/response-dt
import { SharedLinkType } from '@app/infra/entities';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

const user1SharedUser = 'user1SharedUser';
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/asset.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { INestApplication } from '@nestjs/common';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { randomBytes } from 'crypto';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { generateAsset, testApp, today, yesterday } from '../utils';

const makeUploadDto = (options?: { omit: string }): Record<string, any> => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/auth.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
uuidStub,
} from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

const name = 'Immich Admin';
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LibraryController } from '@app/immich';
import { LibraryType } from '@app/infra/entities';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${LibraryController.name} (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/oauth.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OAuthController } from '@app/immich';
import { errorStub } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${OAuthController.name} (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/partner.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LoginResponseDto, PartnerDirection } from '@app/domain';
import { PartnerController } from '@app/immich';
import { errorStub, userDto } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${PartnerController.name} (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/person.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PersonEntity } from '@app/infra/entities';
import { INestApplication } from '@nestjs/common';
import { errorStub, uuidStub } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${PersonController.name}`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/search.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SearchController } from '@app/immich';
import { INestApplication } from '@nestjs/common';
import { errorStub, searchStub } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { generateAsset, testApp } from '../utils';

describe(`${SearchController.name}`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/server-info.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LoginResponseDto } from '@app/domain';
import { ServerInfoController } from '@app/immich';
import { errorStub, userDto } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${ServerInfoController.name} (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/shared-link.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { INestApplication } from '@nestjs/common';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { DateTime } from 'luxon';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${SharedLinkController.name} (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/system-config.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LoginResponseDto } from '@app/domain';
import { SystemConfigController } from '@app/immich';
import { errorStub, userDto } from '@test/fixtures';
import request from 'supertest';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${SystemConfigController.name} (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/e2e/api/specs/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { errorStub, userDto, userSignupStub, userStub } from '@test/fixtures';
import request from 'supertest';
import { Repository } from 'typeorm';
import { api } from '../client';
import { api } from '../../client';
import { testApp } from '../utils';

describe(`${UserController.name}`, () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion server/e2e/docker-compose.server-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ services:
- DB_USERNAME=postgres
- DB_PASSWORD=postgres
- DB_DATABASE_NAME=e2e_test
- IMMICH_RUN_ALL_TESTS=true
depends_on:
- database

Expand Down
79 changes: 0 additions & 79 deletions server/e2e/jobs/client/asset-api.ts

This file was deleted.

45 changes: 0 additions & 45 deletions server/e2e/jobs/client/auth-api.ts

This file was deleted.

11 changes: 0 additions & 11 deletions server/e2e/jobs/client/index.ts

This file was deleted.

47 changes: 0 additions & 47 deletions server/e2e/jobs/client/library-api.ts

This file was deleted.

Loading

0 comments on commit 96a0f7c

Please sign in to comment.