Skip to content

Commit fcf1f2a

Browse files
authored
fix(typecheck): address test typing issues (#462)
* fix(typecheck): address test typing issues * fix: Fixed lint issues * fix: Fixed explicit return type lint issue
1 parent bb9b401 commit fcf1f2a

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

apps/backend/src/__tests__/cards.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import Fastify, { type FastifyInstance } from 'fastify';
12
import { describe, it, expect, beforeEach, vi } from 'vitest';
2-
import Fastify from 'fastify';
3+
34
import { cardRoutes } from '../routes/cards.js';
45

6+
import type { PrismaClient } from '@prisma/client';
7+
58
const USER_ID = 'user-123';
69
const CARD_ID = 'card-abc';
710
// Must be valid UUIDs — createCardSchema and updateCardSchema use z.string().uuid()
@@ -43,15 +46,15 @@ const mockPrisma = {
4346

4447
// Re-wire $transaction before every test so that it executes the callback
4548
// against the same mock client, preserving existing per-operation mocks.
46-
function wireTransaction() {
49+
function wireTransaction(): void {
4750
mockPrisma.$transaction.mockImplementation(
4851
async (callback: (tx: typeof mockPrisma) => Promise<unknown>) => callback(mockPrisma),
4952
);
5053
}
5154

52-
async function buildApp() {
55+
async function buildApp():Promise<FastifyInstance> {
5356
const app = Fastify({ logger: false });
54-
app.decorate('prisma', mockPrisma);
57+
app.decorate('prisma', mockPrisma as unknown as PrismaClient);
5558
app.decorate('authenticate', async (request: any) => {
5659
request.user = { id: USER_ID };
5760
});

apps/backend/src/__tests__/profiles.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import Fastify, { type FastifyInstance } from 'fastify';
12
import { describe, it, expect, beforeEach, vi } from 'vitest';
2-
import Fastify from 'fastify';
3+
34
import { profileRoutes } from '../routes/profiles.js';
5+
46
import type { PrismaClient } from '@prisma/client';
57

68
const mockUser = {
@@ -20,15 +22,15 @@ const mockUser = {
2022
providerId: 'gh-123',
2123
};
2224

23-
const mockPrisma: Pick<PrismaClient, 'user'> = {
25+
const mockPrisma = {
2426
user: {
2527
findUnique: vi.fn(),
2628
findFirst: vi.fn(),
2729
update: vi.fn(),
28-
} as unknown as PrismaClient['user'],
30+
},
2931
};
3032

31-
async function buildApp() {
33+
async function buildApp():Promise<FastifyInstance> {
3234
const app = Fastify();
3335
app.decorate('prisma', mockPrisma as unknown as PrismaClient);
3436
app.decorate('authenticate', async (request: any) => {

apps/backend/src/__tests__/validateEnv.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, it, expect, vi, afterEach } from 'vitest';
2+
23
import { validateEnv } from '../utils/validateEnv.js';
34

45
// ── helpers ──────────────────────────────────────────────────────────────────
@@ -8,8 +9,8 @@ import { validateEnv } from '../utils/validateEnv.js';
89
* that a failing validateEnv() call does not terminate the test process.
910
* Returns the spy so callers can assert the exit code.
1011
*/
11-
function stubExit() {
12-
return vi.spyOn(process, 'exit').mockImplementation((code?: number | string) => {
12+
function stubExit(): ReturnType<typeof vi.spyOn> {
13+
return vi.spyOn(process, 'exit').mockImplementation((code?: number | string | null) => {
1314
throw new Error(`process.exit(${code})`);
1415
}) as unknown as ReturnType<typeof vi.spyOn>;
1516
}

0 commit comments

Comments
 (0)