Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
transform: {
...tsJestTransformCfg,
},
setupFiles: ["./jest.setup.ts"],
};
16 changes: 16 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test environment stub — sets all required env vars before any module loads.
// Values are non-functional placeholders sufficient for schema validation.

process.env.MODE = 'test';
process.env.DATABASE_URL = 'postgresql://test:test@localhost:5432/test';
process.env.GMAIL_USER = 'test@example.com';
process.env.GMAIL_APP_PASSWORD = 'test-password';
process.env.GOOGLE_CLIENT_ID = 'test-google-client-id';
process.env.GOOGLE_CLIENT_SECRET = 'test-google-client-secret';
process.env.BACKEND_URL = 'http://localhost:3000';
process.env.FRONTEND_URL = 'http://localhost:5173';
process.env.CLOUDINARY_CLOUD_NAME = 'test-cloud';
process.env.CLOUDINARY_API_KEY = 'test-api-key';
process.env.CLOUDINARY_API_SECRET = 'test-api-secret';
process.env.PAYSTACK_SECRET_KEY = 'test-paystack-secret';
process.env.APP_SECRET = 'accesslayer_test_secret_key_32_bytes_long_xxxx';
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function makeRes(): any {
res.status = jest.fn().mockReturnValue(res);
res.json = jest.fn().mockReturnValue(res);
res.setHeader = jest.fn().mockReturnValue(res);
res.set = jest.fn().mockReturnValue(res);
return res;
}

Expand Down Expand Up @@ -127,12 +128,12 @@ describe('GET /api/v1/creators — empty feed with filter combinations', () => {
const res = makeRes();
await httpListCreators(req, res, makeNext());

expect(creatorsUtils.fetchCreatorList).toHaveBeenCalledWith(
expect.objectContaining({
verified: undefined,
search: undefined,
})
);
// Optional filter keys are absent from the Zod output when not supplied;
// asserting absence is more accurate than asserting `undefined` equality.
const callArgs = (creatorsUtils.fetchCreatorList as jest.Mock).mock.calls[0][0];
expect(callArgs).not.toHaveProperty('verified', true);
expect(callArgs).not.toHaveProperty('verified', false);
expect(callArgs).not.toHaveProperty('search');

const body = res.json.mock.calls[0][0];
expect(body.data.items).toHaveLength(0);
Expand Down
Loading
Loading