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
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions services/indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@
},
"dependencies": {
"@bettapay/validation": "workspace:*",
"@fastify/cors": "*",
"@fastify/rate-limit": "^11.1.0",
"@prisma/adapter-pg": "^7.8.0",
"@prisma/client": "*",
"@stellar/stellar-sdk": "*",
"bullmq": "*",
"fastify": "*",
"@fastify/cors": "*",
"@fastify/helmet": "*",
"ioredis": "*",
"pg": "^8.22.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@types/pg": "^8.20.0",
"@types/tape": "^5.6.4",
"cross-env": "^7.0.3",
"tape": "^5.9.0",
Expand Down
56 changes: 56 additions & 0 deletions services/indexer/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
import test from 'tape';
import { fastify } from './index.js';

test('GET /api/events/stats - rejects requests without service token', async (t) => {
await fastify.ready();

try {
const res = await fastify.inject({
method: 'GET',
url: '/api/events/stats',
});
t.equal(res.statusCode, 401, 'should return 401 without x-service-token');
const body = JSON.parse(res.body);
t.equal(body.error?.code, 'UNAUTHORIZED', 'error code should be UNAUTHORIZED');
} catch (err: any) {
t.fail(err);
} finally {
t.end();
}
});

test('GET /api/events/stats - rejects invalid date strings with 400', async (t) => {
await fastify.ready();

try {
const res = await fastify.inject({
method: 'GET',
url: '/api/events/stats?from=not-a-date',
headers: { 'x-service-token': process.env.INTER_SERVICE_SECRET || 'test-secret-that-is-at-least-16-chars' },
});
t.equal(res.statusCode, 400, 'should return 400 for invalid from date');
const body = JSON.parse(res.body);
t.equal(body.error?.code, 'VALIDATION_ERROR', 'error code should be VALIDATION_ERROR');
} catch (err: any) {
t.fail(err);
} finally {
t.end();
}
});

test('GET /api/events/stats - rejects from > to with 400', async (t) => {
await fastify.ready();

try {
const res = await fastify.inject({
method: 'GET',
url: '/api/events/stats?from=2025-06-01T00:00:00Z&to=2024-06-01T00:00:00Z',
headers: { 'x-service-token': process.env.INTER_SERVICE_SECRET || 'test-secret-that-is-at-least-16-chars' },
});
t.equal(res.statusCode, 400, 'should return 400 when from is after to');
const body = JSON.parse(res.body);
t.equal(body.error?.code, 'VALIDATION_ERROR', 'error code should be VALIDATION_ERROR');
} catch (err: any) {
t.fail(err);
} finally {
t.end();
}
});

test('Indexer rate limiting - requests below the limit succeed', async (t) => {
await fastify.ready();

Expand Down
1 change: 1 addition & 0 deletions services/indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
registerRequestId,
registerServiceAuth,
PaginationQuery,
DateRangeQuery,
EVENT_TYPES,
WebhookUrlSchema,
buildPrismaConnectionUrl,
Expand Down