refactor: migrate monorepo from pnpm to Bun runtime and workspaces
- root: bun workspaces via package.json, packageManager bun@1.4.0, scripts use bun --filter - backend: Bun.serve, bun test (vitest removed), bun --watch dev script, tsconfig types bun - tests: migrate 6 test files from vitest to bun:test (mock.module) - validate: replace @hono/zod-validator with hono validator + zod safeParse (fixes TS2589) - lockfile: bunfig.toml saveTextLockfile, regenerated bun.lock (text) for turbo - docs: AGENTS.md, README.md, stack.md updated to Bun stack
This commit is contained in:
@@ -1,44 +1,27 @@
|
||||
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
|
||||
import { Hono } from 'hono';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const { db } = vi.hoisted(() => {
|
||||
return {
|
||||
db: {
|
||||
group: {
|
||||
findMany: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
},
|
||||
groupMember: {
|
||||
create: vi.fn(),
|
||||
},
|
||||
organization: {
|
||||
findUnique: vi.fn(),
|
||||
},
|
||||
} as {
|
||||
group: {
|
||||
findMany: ReturnType<typeof vi.fn>;
|
||||
findFirst: ReturnType<typeof vi.fn>;
|
||||
count: ReturnType<typeof vi.fn>;
|
||||
create: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
groupMember: { create: ReturnType<typeof vi.fn> };
|
||||
organization: { findUnique: ReturnType<typeof vi.fn> };
|
||||
},
|
||||
};
|
||||
});
|
||||
const db = {
|
||||
group: {
|
||||
findMany: mock(),
|
||||
findFirst: mock(),
|
||||
count: mock(),
|
||||
create: mock(),
|
||||
},
|
||||
groupMember: {
|
||||
create: mock(),
|
||||
},
|
||||
organization: {
|
||||
findUnique: mock(),
|
||||
},
|
||||
};
|
||||
|
||||
vi.mock('@/lib/prisma', () => ({
|
||||
mock.module('@/lib/prisma', () => ({
|
||||
default: db,
|
||||
getPrismaClient: vi.fn(),
|
||||
getPrismaClient: mock(),
|
||||
UnitOfWork: class {
|
||||
executeResult = vi.fn(
|
||||
async (cb: (tx: unknown) => Promise<unknown>) => cb(db),
|
||||
);
|
||||
execute = vi.fn(
|
||||
async (cb: (tx: unknown) => Promise<unknown>) => cb(db),
|
||||
);
|
||||
executeResult = mock(async (cb: (tx: unknown) => Promise<unknown>) => cb(db));
|
||||
execute = mock(async (cb: (tx: unknown) => Promise<unknown>) => cb(db));
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -71,8 +54,8 @@ describe('groups routes', () => {
|
||||
});
|
||||
|
||||
it('lists groups scoped to the current user', async () => {
|
||||
vi.mocked(prisma.group.findMany).mockResolvedValue([group]);
|
||||
vi.mocked(prisma.group.count).mockResolvedValue(1);
|
||||
prisma.group.findMany.mockResolvedValue([group]);
|
||||
prisma.group.count.mockResolvedValue(1);
|
||||
|
||||
const res = await makeApp({ id: userId }).request('/groups');
|
||||
|
||||
@@ -118,9 +101,9 @@ describe('groups routes', () => {
|
||||
name: 'Escuela Alfa',
|
||||
members: [{ userId, role: 'owner' }],
|
||||
};
|
||||
vi.mocked(prisma.organization.findUnique).mockResolvedValue(organization as never);
|
||||
vi.mocked(prisma.group.findFirst).mockResolvedValue(null);
|
||||
vi.mocked(prisma.group.create).mockResolvedValue(group);
|
||||
prisma.organization.findUnique.mockResolvedValue(organization as never);
|
||||
prisma.group.findFirst.mockResolvedValue(null);
|
||||
prisma.group.create.mockResolvedValue(group);
|
||||
|
||||
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
|
||||
method: 'POST',
|
||||
@@ -148,8 +131,8 @@ describe('groups routes', () => {
|
||||
name: 'Escuela Alfa',
|
||||
members: [{ userId, role: 'owner' }],
|
||||
};
|
||||
vi.mocked(prisma.organization.findUnique).mockResolvedValue(organization as never);
|
||||
vi.mocked(prisma.group.findFirst).mockResolvedValue(group);
|
||||
prisma.organization.findUnique.mockResolvedValue(organization as never);
|
||||
prisma.group.findFirst.mockResolvedValue(group);
|
||||
|
||||
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
|
||||
method: 'POST',
|
||||
@@ -164,7 +147,7 @@ describe('groups routes', () => {
|
||||
});
|
||||
|
||||
it('rejects creating a group for an unknown organization', async () => {
|
||||
vi.mocked(prisma.organization.findUnique).mockResolvedValue(null);
|
||||
prisma.organization.findUnique.mockResolvedValue(null);
|
||||
|
||||
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
|
||||
method: 'POST',
|
||||
@@ -183,7 +166,7 @@ describe('groups routes', () => {
|
||||
name: 'Escuela Alfa',
|
||||
members: [{ userId: 'other-user', role: 'owner' }],
|
||||
};
|
||||
vi.mocked(prisma.organization.findUnique).mockResolvedValue(organization as never);
|
||||
prisma.organization.findUnique.mockResolvedValue(organization as never);
|
||||
|
||||
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user