Skip to content

Commit 1e8002a

Browse files
authored
Merge pull request #70 from namtroi/pdf/optimize
chore(tests): remove obsolete API_KEY references from test suite
2 parents 6db3baf + 2def5b3 commit 1e8002a

13 files changed

Lines changed: 105 additions & 141 deletions

apps/backend/tests/e2e/error-handling.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { API_KEY, getTestApp, setupE2E, teardownE2E } from '@tests/e2e/setup/e2e-setup.js';
1+
import { getTestApp, setupE2E, teardownE2E } from '@tests/e2e/setup/e2e-setup.js';
22
import { cleanDatabase, ensureDefaultProfile } from '@tests/helpers/database.js';
33
import { FIXTURES, readFixture } from '@tests/helpers/fixtures.js';
44
import { ERRORS } from '@tests/mocks/python-worker-mock.js';
@@ -28,7 +28,6 @@ describe('E2E: Error Handling', () => {
2828
method: 'POST',
2929
url: '/api/documents',
3030
headers: {
31-
'X-API-Key': API_KEY,
3231
'Content-Type': 'multipart/form-data; boundary=---e2e',
3332
},
3433
payload: createMultipartPayload('protected.pdf', pdfBuffer, 'application/pdf'),
@@ -48,7 +47,6 @@ describe('E2E: Error Handling', () => {
4847
const statusResponse = await app.inject({
4948
method: 'GET',
5049
url: `/api/documents/${documentId}`,
51-
headers: { 'X-API-Key': API_KEY },
5250
});
5351

5452
expect(statusResponse.json().status).toBe('FAILED');
@@ -66,7 +64,6 @@ describe('E2E: Error Handling', () => {
6664
method: 'POST',
6765
url: '/api/documents',
6866
headers: {
69-
'X-API-Key': API_KEY,
7067
'Content-Type': 'multipart/form-data; boundary=---e2e',
7168
},
7269
payload: createMultipartPayload('short.pdf', pdfBuffer, 'application/pdf'),
@@ -101,7 +98,6 @@ describe('E2E: Error Handling', () => {
10198
const statusResponse = await app.inject({
10299
method: 'GET',
103100
url: `/api/documents/${documentId}`,
104-
headers: { 'X-API-Key': API_KEY },
105101
});
106102

107103
expect(statusResponse.json().status).toBe('FAILED');
@@ -116,7 +112,6 @@ describe('E2E: Error Handling', () => {
116112
method: 'POST',
117113
url: '/api/documents',
118114
headers: {
119-
'X-API-Key': API_KEY,
120115
'Content-Type': 'multipart/form-data; boundary=---e2e',
121116
},
122117
payload: createMultipartPayload('noisy.pdf', pdfBuffer, 'application/pdf'),
@@ -151,7 +146,6 @@ describe('E2E: Error Handling', () => {
151146
const statusResponse = await app.inject({
152147
method: 'GET',
153148
url: `/api/documents/${documentId}`,
154-
headers: { 'X-API-Key': API_KEY },
155149
});
156150

157151
expect(statusResponse.json().status).toBe('FAILED');
@@ -169,7 +163,6 @@ describe('E2E: Error Handling', () => {
169163
method: 'POST',
170164
url: '/api/documents',
171165
headers: {
172-
'X-API-Key': API_KEY,
173166
'Content-Type': 'multipart/form-data; boundary=---e2e',
174167
},
175168
payload: createMultipartPayload('first.pdf', pdfBuffer, 'application/pdf'),
@@ -182,7 +175,6 @@ describe('E2E: Error Handling', () => {
182175
method: 'POST',
183176
url: '/api/documents',
184177
headers: {
185-
'X-API-Key': API_KEY,
186178
'Content-Type': 'multipart/form-data; boundary=---e2e',
187179
},
188180
payload: createMultipartPayload('second.pdf', pdfBuffer, 'application/pdf'),
@@ -202,7 +194,6 @@ describe('E2E: Error Handling', () => {
202194
method: 'POST',
203195
url: '/api/documents',
204196
headers: {
205-
'X-API-Key': API_KEY,
206197
'Content-Type': 'multipart/form-data; boundary=---e2e',
207198
},
208199
payload: createMultipartPayload('image.png', Buffer.from('fake'), 'image/png'),
@@ -222,7 +213,6 @@ describe('E2E: Error Handling', () => {
222213
method: 'POST',
223214
url: '/api/documents',
224215
headers: {
225-
'X-API-Key': API_KEY,
226216
'Content-Type': 'multipart/form-data; boundary=---e2e',
227217
},
228218
payload: createMultipartPayload('large.pdf', largeBuffer, 'application/pdf'),
@@ -242,7 +232,6 @@ describe('E2E: Error Handling', () => {
242232
method: 'POST',
243233
url: '/api/documents',
244234
headers: {
245-
'X-API-Key': API_KEY,
246235
'Content-Type': 'multipart/form-data; boundary=---e2e',
247236
},
248237
payload: createMultipartPayload('corrupt.pdf', corruptBuffer, 'application/pdf'),
@@ -261,7 +250,6 @@ describe('E2E: Error Handling', () => {
261250
const statusResponse = await app.inject({
262251
method: 'GET',
263252
url: `/api/documents/${documentId}`,
264-
headers: { 'X-API-Key': API_KEY },
265253
});
266254

267255
expect(statusResponse.json().status).toBe('FAILED');

apps/backend/tests/e2e/pdf-upload-flow.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { API_KEY, getTestApp, setupE2E, teardownE2E } from '@tests/e2e/setup/e2e-setup.js';
1+
import { getTestApp, setupE2E, teardownE2E } from '@tests/e2e/setup/e2e-setup.js';
22
import { cleanDatabase, ensureDefaultProfile } from '@tests/helpers/database.js';
33
import { FIXTURES, readFixture } from '@tests/helpers/fixtures.js';
44
import { successCallback } from '@tests/mocks/python-worker-mock.js';
@@ -27,7 +27,6 @@ describe('E2E: PDF Upload Flow', () => {
2727
method: 'POST',
2828
url: '/api/documents',
2929
headers: {
30-
'X-API-Key': API_KEY,
3130
'Content-Type': 'multipart/form-data; boundary=---e2e',
3231
},
3332
payload: createMultipartPayload('test.pdf', pdfBuffer, 'application/pdf'),
@@ -41,7 +40,6 @@ describe('E2E: PDF Upload Flow', () => {
4140
let statusResponse = await app.inject({
4241
method: 'GET',
4342
url: `/api/documents/${documentId}`,
44-
headers: { 'X-API-Key': API_KEY },
4543
});
4644

4745
expect(statusResponse.json().status).toBe('PENDING');
@@ -79,7 +77,6 @@ This concludes the test document content.`,
7977
statusResponse = await app.inject({
8078
method: 'GET',
8179
url: `/api/documents/${documentId}`,
82-
headers: { 'X-API-Key': API_KEY },
8380
});
8481

8582
const statusBody = statusResponse.json();
@@ -90,7 +87,6 @@ This concludes the test document content.`,
9087
const queryResponse = await app.inject({
9188
method: 'POST',
9289
url: '/api/query',
93-
headers: { 'X-API-Key': API_KEY },
9490
payload: {
9591
query: 'test document content',
9692
topK: 5,

apps/backend/tests/e2e/query-flow.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { API_KEY, getTestApp, setupE2E, teardownE2E } from '@tests/e2e/setup/e2e-setup.js';
1+
import { getTestApp, setupE2E, teardownE2E } from '@tests/e2e/setup/e2e-setup.js';
22
import { cleanDatabase, ensureDefaultProfile, getPrisma, seedDocument } from '@tests/helpers/database.js';
33
import { FIXTURES, readFixture } from '@tests/helpers/fixtures.js';
44
import { mockEmbedding, mockEmbeddingClient } from '@tests/mocks/embedding-mock.js';
@@ -33,7 +33,6 @@ describe('E2E: Query Flow', () => {
3333
method: 'POST',
3434
url: '/api/documents',
3535
headers: {
36-
'X-API-Key': API_KEY,
3736
'Content-Type': 'multipart/form-data; boundary=---e2e',
3837
},
3938
payload: createMultipartPayload('ml-doc.pdf', pdfBuffer, 'application/pdf'),
@@ -79,7 +78,6 @@ desired behaviors and punishing undesired ones.`,
7978
const queryResponse = await app.inject({
8079
method: 'POST',
8180
url: '/api/query',
82-
headers: { 'X-API-Key': API_KEY },
8381
payload: {
8482
query: 'what are the types of machine learning',
8583
topK: 5,
@@ -120,7 +118,6 @@ desired behaviors and punishing undesired ones.`,
120118
const queryResponse = await app.inject({
121119
method: 'POST',
122120
url: '/api/query',
123-
headers: { 'X-API-Key': API_KEY },
124121
payload: { query: 'searchable content', topK: 5 },
125122
});
126123

@@ -154,7 +151,6 @@ desired behaviors and punishing undesired ones.`,
154151
const queryResponse = await app.inject({
155152
method: 'POST',
156153
url: '/api/query',
157-
headers: { 'X-API-Key': API_KEY },
158154
payload: { query: 'machine learning', topK: 4 },
159155
});
160156

@@ -183,7 +179,6 @@ desired behaviors and punishing undesired ones.`,
183179
const queryResponse = await app.inject({
184180
method: 'POST',
185181
url: '/api/query',
186-
headers: { 'X-API-Key': API_KEY },
187182
payload: { query: 'test content', topK: 1 },
188183
});
189184

@@ -201,7 +196,6 @@ desired behaviors and punishing undesired ones.`,
201196
const queryResponse = await app.inject({
202197
method: 'POST',
203198
url: '/api/query',
204-
headers: { 'X-API-Key': API_KEY },
205199
payload: { query: 'any query', topK: 5 },
206200
});
207201

apps/backend/tests/e2e/setup/e2e-setup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function setupE2E() {
2929
// Set environment variables
3030
process.env.DATABASE_URL = postgresContainer.getConnectionUri();
3131
process.env.REDIS_URL = `redis://${redisContainer.getHost()}:${redisContainer.getPort()}`;
32-
process.env.API_KEY = 'e2e-test-key';
32+
3333
process.env.UPLOAD_DIR = '/tmp/e2e-uploads';
3434
process.env.NODE_ENV = 'test';
3535

@@ -126,4 +126,3 @@ export function getTestApp(): FastifyInstance {
126126
return app;
127127
}
128128

129-
export const API_KEY = 'e2e-test-key';

apps/backend/tests/helpers/api.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ export async function closeTestApp(): Promise<void> {
5050
}
5151
}
5252

53-
/**
54-
* Make authenticated request
55-
*/
56-
export function authHeaders(apiKey: string = 'test-api-key'): Record<string, string> {
57-
return {
58-
'X-API-Key': apiKey,
59-
};
60-
}
61-
6253
/**
6354
* Inject helper for cleaner test syntax
6455
*/
@@ -68,20 +59,15 @@ export async function inject(
6859
options?: {
6960
payload?: any;
7061
headers?: Record<string, string>;
71-
auth?: boolean;
7262
}
7363
): Promise<any> {
7464
const app = await getTestApp();
75-
const headers = {
76-
...(options?.auth !== false ? authHeaders() : {}),
77-
...options?.headers,
78-
};
7965

8066
const response = await app.inject({
8167
method,
8268
url,
8369
payload: options?.payload,
84-
headers,
70+
headers: options?.headers,
8571
});
8672

8773
return {
@@ -90,3 +76,4 @@ export async function inject(
9076
headers: response.headers,
9177
};
9278
}
79+

apps/backend/tests/integration/routes/analytics-e2e.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cleanDatabase, getPrisma, seedDocument } from '@tests/helpers/database.
33
import { successCallback } from '@tests/mocks/python-worker-mock.js';
44
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
55

6-
const API_KEY = 'test-api-key';
6+
77

88
describe('Analytics E2E Flow', () => {
99
let app: any;
@@ -103,7 +103,7 @@ describe('Analytics E2E Flow', () => {
103103
const response = await app.inject({
104104
method: 'GET',
105105
url: '/api/analytics/overview?period=all',
106-
headers: { 'X-API-Key': API_KEY },
106+
107107
});
108108

109109
expect(response.statusCode).toBe(200);
@@ -147,7 +147,7 @@ describe('Analytics E2E Flow', () => {
147147
const response = await app.inject({
148148
method: 'GET',
149149
url: '/api/chunks?limit=50',
150-
headers: { 'X-API-Key': API_KEY },
150+
151151
});
152152

153153
expect(response.statusCode).toBe(200);
@@ -191,7 +191,7 @@ describe('Analytics E2E Flow', () => {
191191
const excellentResponse = await app.inject({
192192
method: 'GET',
193193
url: '/api/chunks?quality=excellent',
194-
headers: { 'X-API-Key': API_KEY },
194+
195195
});
196196

197197
expect(excellentResponse.statusCode).toBe(200);
@@ -206,7 +206,7 @@ describe('Analytics E2E Flow', () => {
206206
const lowResponse = await app.inject({
207207
method: 'GET',
208208
url: '/api/chunks?quality=low',
209-
headers: { 'X-API-Key': API_KEY },
209+
210210
});
211211

212212
expect(lowResponse.statusCode).toBe(200);
@@ -248,7 +248,7 @@ describe('Analytics E2E Flow', () => {
248248
const response = await app.inject({
249249
method: 'GET',
250250
url: '/api/analytics/processing?period=all',
251-
headers: { 'X-API-Key': API_KEY },
251+
252252
});
253253

254254
expect(response.statusCode).toBe(200);

0 commit comments

Comments
 (0)