fix architecture and write new tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.mock('../../lib/prisma', () => ({ prisma: {} }))
|
||||
vi.mock('../../lib/redis', () => ({ redis: { on: vi.fn(), get: vi.fn(), set: vi.fn(), del: vi.fn(), quit: vi.fn() } }))
|
||||
vi.mock('../../middleware/requireCompanyAuth', () => ({
|
||||
requireCompanyAuth: (req: any, _res: any, next: any) => {
|
||||
req.employee = { id: 'employee_1', firstName: 'Aya', lastName: 'Manager', role: 'MANAGER' }
|
||||
next()
|
||||
},
|
||||
requireCompanyDocumentAuth: (req: any, _res: any, next: any) => {
|
||||
req.employee = { id: 'employee_1', firstName: 'Aya', lastName: 'Manager', role: 'MANAGER' }
|
||||
next()
|
||||
},
|
||||
}))
|
||||
vi.mock('../../middleware/requireTenant', () => ({ requireTenant: (req: any, _res: any, next: any) => { req.companyId = 'company_1'; next() } }))
|
||||
vi.mock('../../middleware/requireSubscription', () => ({ requireSubscription: (_req: any, _res: any, next: any) => next() }))
|
||||
vi.mock('../../middleware/requireRole', () => ({ requireRole: () => (_req: any, _res: any, next: any) => next() }))
|
||||
vi.mock('../../modules/customers/customer.service', () => ({
|
||||
createCustomer: vi.fn(),
|
||||
approveLicense: vi.fn(),
|
||||
listCustomers: vi.fn(),
|
||||
getCustomer: vi.fn(),
|
||||
updateCustomer: vi.fn(),
|
||||
flagCustomer: vi.fn(),
|
||||
unflagCustomer: vi.fn(),
|
||||
validateCustomerLicense: vi.fn(),
|
||||
uploadLicenseImage: vi.fn(),
|
||||
getLicenseImageFile: vi.fn(),
|
||||
}))
|
||||
|
||||
import request from 'supertest'
|
||||
import { createApp } from '../../app'
|
||||
import * as customerService from '../../modules/customers/customer.service'
|
||||
|
||||
const app = createApp()
|
||||
|
||||
describe('customer boundary e2e smoke', () => {
|
||||
it('rejects malformed customer and license approval payloads before mocked services run', async () => {
|
||||
const badCustomer = await request(app).post('/api/v1/customers').send({ firstName: '', lastName: 'Haddad', email: 'aya@example.test' })
|
||||
expect(badCustomer.status).toBe(400)
|
||||
expect(customerService.createCustomer).not.toHaveBeenCalled()
|
||||
|
||||
const badApproval = await request(app).post('/api/v1/customers/customer_1/approve-license').send({ decision: 'APPROVED_BUT_NOT_THE_ENUM' })
|
||||
expect(badApproval.status).toBe(400)
|
||||
expect(customerService.approveLicense).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user