From 6269c7f7bcbdb7c9f8a4062cb700f3f82205676a Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Sun, 23 Jan 2022 22:23:00 +0100 Subject: [PATCH] test: fix expected error codes in multiple test In the e2e tests the global filter must be added via the special provider 'APP_FILTER' and not with useGlobalFilters, because if not the filter breaks, because of the way supertest handles the http-connection. See: https://github.com/nestjs/nest/issues/1160#issuecomment-468698640 Signed-off-by: Philip Molares --- test/private-api/alias.e2e-spec.ts | 2 +- test/private-api/history.e2e-spec.ts | 2 +- test/private-api/media.e2e-spec.ts | 2 +- test/private-api/notes.e2e-spec.ts | 2 +- test/public-api/alias.e2e-spec.ts | 5 ++--- test/public-api/media.e2e-spec.ts | 2 +- test/public-api/notes.e2e-spec.ts | 2 +- test/test-setup.ts | 7 +++++++ 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/private-api/alias.e2e-spec.ts b/test/private-api/alias.e2e-spec.ts index b8b50854d..0d34d896a 100644 --- a/test/private-api/alias.e2e-spec.ts +++ b/test/private-api/alias.e2e-spec.ts @@ -96,7 +96,7 @@ describe('Alias', () => { .post(`/api/private/alias`) .set('Content-Type', 'application/json') .send(newAliasDto) - .expect(400); + .expect(409); }); it('because the user is not an owner', async () => { newAliasDto.newAlias = publicId; diff --git a/test/private-api/history.e2e-spec.ts b/test/private-api/history.e2e-spec.ts index 090b0e048..32c76295e 100644 --- a/test/private-api/history.e2e-spec.ts +++ b/test/private-api/history.e2e-spec.ts @@ -156,7 +156,7 @@ describe('History', () => { .post('/api/private/me/history') .set('Content-Type', 'application/json') .send(JSON.stringify({ history: [brokenEntryDto] })) - .expect(400); + .expect(404); }); afterEach(async () => { const historyEntries = await testSetup.historyService.getEntriesByUser( diff --git a/test/private-api/media.e2e-spec.ts b/test/private-api/media.e2e-spec.ts index 4ae3327df..85fa9fb79 100644 --- a/test/private-api/media.e2e-spec.ts +++ b/test/private-api/media.e2e-spec.ts @@ -87,7 +87,7 @@ describe('Media', () => { .post('/api/private/media') .attach('file', 'test/private-api/fixtures/test.zip') .set('HedgeDoc-Note', 'i_dont_exist') - .expect(400); + .expect(404); await expect(fs.access(uploadPath)).rejects.toBeDefined(); }); it('mediaBackend error', async () => { diff --git a/test/private-api/notes.e2e-spec.ts b/test/private-api/notes.e2e-spec.ts index 3683f1281..7e26bcaf4 100644 --- a/test/private-api/notes.e2e-spec.ts +++ b/test/private-api/notes.e2e-spec.ts @@ -123,7 +123,7 @@ describe('Notes', () => { .set('Content-Type', 'text/markdown') .send(content) .expect('Content-Type', /json/) - .expect(400); + .expect(409); }); }); diff --git a/test/public-api/alias.e2e-spec.ts b/test/public-api/alias.e2e-spec.ts index 3956e4220..897e7109a 100644 --- a/test/public-api/alias.e2e-spec.ts +++ b/test/public-api/alias.e2e-spec.ts @@ -66,7 +66,7 @@ describe('Alias', () => { noteIdOrAlias: testAlias, newAlias: 'testAlias1', }) - .expect(400); + .expect(409); }); it('because of a forbidden alias', async () => { await request(testSetup.app.getHttpServer()) @@ -88,7 +88,7 @@ describe('Alias', () => { noteIdOrAlias: testAlias, newAlias: publicId, }) - .expect(400); + .expect(409); }); it('because the user is not an owner', async () => { await request(testSetup.app.getHttpServer()) @@ -217,7 +217,6 @@ describe('Alias', () => { .delete(`/api/v2/alias/${testAlias}`) .set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`) .expect(400); - await request(testSetup.app.getHttpServer()) .get(`/api/v2/notes/${secondAlias}`) .set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`) diff --git a/test/public-api/media.e2e-spec.ts b/test/public-api/media.e2e-spec.ts index 70e806d22..d477c1ece 100644 --- a/test/public-api/media.e2e-spec.ts +++ b/test/public-api/media.e2e-spec.ts @@ -79,7 +79,7 @@ describe('Media', () => { .post('/api/v2/media') .attach('file', 'test/public-api/fixtures/test.zip') .set('HedgeDoc-Note', 'i_dont_exist') - .expect(400); + .expect(404); await expect(fs.access(uploadPath)).rejects.toBeDefined(); }); it('mediaBackend error', async () => { diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index f0da82a60..d5409707d 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -117,7 +117,7 @@ describe('Notes', () => { .set('Content-Type', 'text/markdown') .send(content) .expect('Content-Type', /json/) - .expect(400); + .expect(409); }); }); diff --git a/test/test-setup.ts b/test/test-setup.ts index 0ae69ce52..81ca8dc8a 100644 --- a/test/test-setup.ts +++ b/test/test-setup.ts @@ -24,6 +24,7 @@ import customizationConfigMock from '../src/config/mock/customization.config.moc import externalServicesConfigMock from '../src/config/mock/external-services.config.mock'; import mediaConfigMock from '../src/config/mock/media.config.mock'; import noteConfigMock from '../src/config/mock/note.config.mock'; +import { ErrorExceptionMapping } from '../src/errors/error-mapping'; import { FrontendConfigModule } from '../src/frontend-config/frontend-config.module'; import { GroupsModule } from '../src/groups/groups.module'; import { HistoryModule } from '../src/history/history.module'; @@ -129,6 +130,12 @@ export class TestSetupBuilder { FrontendConfigModule, IdentityModule, ], + providers: [ + { + provide: 'APP_FILTER', + useClass: ErrorExceptionMapping, + }, + ], }); return testSetupBuilder; }