const { getInitialStylistFromEnv, seedInitialData, } = require('./seed-initial.cjs'); describe('seedInitialData', () => { const env = { INITIAL_STYLIST_ID: '1', INITIAL_STYLIST_USERNAME: 'Ogawa', INITIAL_STYLIST_EMAIL: 'stylist@example.com', INITIAL_STYLIST_PASSWORD: 'Passw0rd!', }; const createPrismaMock = () => ({ hairstylistUser: { findUnique: jest.fn(), create: jest.fn(), update: jest.fn(), }, systemConfig: { upsert: jest.fn(), }, hairTemplate: { upsert: jest.fn(), }, }); it('seeds only the initial stylist account', async () => { const prisma = createPrismaMock(); prisma.hairstylistUser.findUnique.mockResolvedValue(null); const hashPassword = jest.fn().mockResolvedValue('hashed-password'); const result = await seedInitialData(prisma, { env, hashPassword }); expect(hashPassword).toHaveBeenCalledWith('Passw0rd!', 10); expect(prisma.hairstylistUser.create).toHaveBeenCalledWith({ data: { id: BigInt(1), username: 'Ogawa', email: 'stylist@example.com', password: 'hashed-password', isDeleted: 0, }, }); expect(prisma.systemConfig.upsert).not.toHaveBeenCalled(); expect(prisma.hairTemplate.upsert).not.toHaveBeenCalled(); expect(result).toEqual({ stylist: 'created', stylistUsername: 'Ogawa', stylistEmail: 'stylist@example.com', }); }); it('does not reset or rewrite the initial stylist when it already exists', async () => { const prisma = createPrismaMock(); prisma.hairstylistUser.findUnique.mockResolvedValue({ id: BigInt(1) }); const hashPassword = jest.fn(); const result = await seedInitialData(prisma, { env, hashPassword }); expect(hashPassword).not.toHaveBeenCalled(); expect(prisma.hairstylistUser.create).not.toHaveBeenCalled(); expect(prisma.hairstylistUser.update).not.toHaveBeenCalled(); expect(result.stylist).toBe('existing'); }); it('keeps the expected default account', () => { expect(getInitialStylistFromEnv(env)).toEqual({ id: BigInt(1), username: 'Ogawa', email: 'stylist@example.com', password: 'Passw0rd!', }); }); });