Skip to content
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ jobs:
with:
node-version: 22

- name: Install shared dependencies
run: npm --prefix packages/shared install

- name: Build shared package
run: npm --prefix packages/shared run build

- name: Install backend dependencies
run: npm --prefix apps/backend install

Expand Down
228 changes: 228 additions & 0 deletions apps/backend/package-lock.json

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

1 change: 1 addition & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@fastify/rate-limit": "^10.3.0",
"@fastify/static": "^8.0.0",
"@prisma/client": "^6.0.0",
"@resvg/resvg-js": "^2.6.2",
"dotenv": "^16.4.0",
"fastify": "^5.0.0",
"fastify-plugin": "^5.0.0",
Expand Down
35 changes: 16 additions & 19 deletions apps/backend/src/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Fastify, {
type FastifyInstance,
} from 'fastify';
import {
describe,
it,
Expand All @@ -7,13 +10,11 @@ import {
vi,
} from 'vitest';

import Fastify, {
type FastifyInstance,
} from 'fastify';

import { analyticsRoutes } from '../routes/analytics';

import type { PrismaClient } from '@prisma/client';

import { analyticsRoutes } from '../routes/analytics';

// ─── Shared mock data ────────────────────────────────────────────────────────

Expand All @@ -22,6 +23,7 @@ const MOCK_USER_ID = 'user-001';
// ─── Prisma mock ─────────────────────────────────────────────────────────────

const prismaMock = {
$queryRaw: vi.fn(),
cardView: {
count: vi.fn(),
findMany: vi.fn(),
Expand All @@ -34,7 +36,7 @@ const prismaMock = {

// ─── App factory ─────────────────────────────────────────────────────────────

let mockJwtVerify = vi.fn();
const mockJwtVerify = vi.fn();

async function buildApp(): Promise<FastifyInstance> {
const app = Fastify({
Expand All @@ -48,8 +50,12 @@ async function buildApp(): Promise<FastifyInstance> {

app.decorateRequest(
'jwtVerify',
function () {
return mockJwtVerify();
async function (this: any) {
const payload = await mockJwtVerify();
if (payload) {
this.user = payload;
}
return payload;
}
);

Expand Down Expand Up @@ -157,20 +163,11 @@ describe(
]
);

prismaMock.cardView.groupBy.mockResolvedValue(
prismaMock.$queryRaw.mockResolvedValue(
[
{
viewerId:
'u1',
viewerIp:
null,
},
{
viewerId:
'u2',
viewerIp:
null,
},
count: 2n
}
]
);

Expand Down
Loading
Loading