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
7 changes: 4 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"scripts": {
"build": "tsc -p tsconfig.json",
"check-types": "tsc -p tsconfig.json --noEmit",
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
"test:watch": "NODE_OPTIONS='--experimental-vm-modules' jest --watch",
"test:coverage": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage"
"test": "ENCRYPTION_SECRET=abc jest",
"test:watch": "ENCRYPTION_SECRET=abc jest --watch",
"test:coverage": "ENCRYPTION_SECRET=abc jest --coverage"
},
"dependencies": {
"@repo/auth": "workspace:*",
Expand All @@ -29,6 +29,7 @@
"zod": "^3.25.76"
},
"devDependencies": {
"@jest/globals": "^30.2.0",
"@repo/typescript-config": "workspace:*",
"@testing-library/jest-dom": "^6.9.1",
"@types/jest": "^30.0.0",
Expand Down
13 changes: 6 additions & 7 deletions packages/api/src/__tests__/routers/health.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { describe, expect, it } from '@jest/globals';
import { healthRouter } from '../../routers/health';
import { createCaller, createMockContext } from '../utils';

describe('health router', () => {
describe('ping', () => {
it('should return ok status', async () => {
const ctx = createMockContext();
const caller = createCaller(healthRouter, ctx);
const caller = createCaller(ctx);

const result = await caller.ping();
const result = await caller.health.ping();

expect(result).toHaveProperty('status', 'ok');
expect(result).toHaveProperty('timestamp');
});

it('should return a valid ISO timestamp', async () => {
const ctx = createMockContext();
const caller = createCaller(healthRouter, ctx);
const caller = createCaller(ctx);

const result = await caller.ping();
const result = await caller.health.ping();

// Check if timestamp is a valid ISO string
const timestamp = new Date(result.timestamp);
Expand All @@ -27,10 +26,10 @@ describe('health router', () => {

it('should return a recent timestamp', async () => {
const ctx = createMockContext();
const caller = createCaller(healthRouter, ctx);
const caller = createCaller(ctx);

const before = Date.now();
const result = await caller.ping();
const result = await caller.health.ping();
const after = Date.now();

const timestamp = new Date(result.timestamp).getTime();
Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/__tests__/routers/trpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('tRPC procedures', () => {
describe('protectedProcedure', () => {
it('should throw UNAUTHORIZED when user is not authenticated', async () => {
const ctx = createMockContext();

// Create a test procedure
const testProcedure = protectedProcedure.query(() => {
return { success: true };
Expand All @@ -20,6 +20,7 @@ describe('tRPC procedures', () => {
getRawInput: async () => undefined,
path: 'test',
type: 'query',
signal: undefined,
})
).rejects.toThrow(TRPCError);

Expand All @@ -29,6 +30,7 @@ describe('tRPC procedures', () => {
getRawInput: async () => undefined,
path: 'test',
type: 'query',
signal: undefined,
})
).rejects.toMatchObject({
code: 'UNAUTHORIZED',
Expand Down Expand Up @@ -56,6 +58,7 @@ describe('tRPC procedures', () => {
getRawInput: async () => undefined,
path: 'test',
type: 'query',
signal: undefined,
})
).rejects.toThrow(TRPCError);

Expand All @@ -65,6 +68,7 @@ describe('tRPC procedures', () => {
getRawInput: async () => undefined,
path: 'test',
type: 'query',
signal: undefined,
})
).rejects.toMatchObject({
code: 'UNAUTHORIZED',
Expand All @@ -85,6 +89,7 @@ describe('tRPC procedures', () => {
getRawInput: async () => undefined,
path: 'test',
type: 'query',
signal: undefined,
});

expect(result).toEqual({ success: true });
Expand Down
14 changes: 3 additions & 11 deletions packages/api/src/__tests__/utils/createCaller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import type { AnyRouter } from '@trpc/server';
import type { Context } from '../../context';
import { t } from '../../trpc';
import { appRouter } from '../../root';

/**
* Create a caller for testing tRPC procedures
*/
export function createCaller<TRouter extends AnyRouter>(
router: TRouter,
ctx: Context
) {
return router.createCaller(ctx);
}
export const createCaller = t.createCallerFactory(appRouter);
Comment thread
SimonLoir marked this conversation as resolved.
7 changes: 5 additions & 2 deletions packages/api/src/__tests__/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { createMockContext, createAuthenticatedMockContext } from './mockContext';
export { createCaller } from './createCaller';
export {
createMockContext,
createAuthenticatedMockContext,
} from './mockContext';
export * from './createCaller';
10 changes: 4 additions & 6 deletions packages/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"module": "esnext",
"moduleResolution": "Bundler",
Comment thread
SimonLoir marked this conversation as resolved.
Comment thread
SimonLoir marked this conversation as resolved.
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"tsBuildInfoFile": "dist/.tsbuildinfo",
"composite": false,
"incremental": true
},
"include": [
"src"
],
"exclude": [
"src/**/__tests__/**"
]
"include": ["src"],
"exclude": ["src/**/__tests__/**"]
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

Loading