fix failed tests
This commit is contained in:
@@ -55,6 +55,7 @@ dashboard_tests:
|
|||||||
image: node:20-bookworm
|
image: node:20-bookworm
|
||||||
before_script:
|
before_script:
|
||||||
- npm ci
|
- npm ci
|
||||||
|
- npm run build --workspace @rentaldrivego/types
|
||||||
script:
|
script:
|
||||||
- npm run test:dashboard
|
- npm run test:dashboard
|
||||||
rules:
|
rules:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const app = createApp()
|
|||||||
|
|
||||||
describe('Admin API', () => {
|
describe('Admin API', () => {
|
||||||
let adminToken: string
|
let adminToken: string
|
||||||
|
let protectedAdminToken: string
|
||||||
let financeToken: string
|
let financeToken: string
|
||||||
let viewerToken: string
|
let viewerToken: string
|
||||||
let adminId: string
|
let adminId: string
|
||||||
@@ -28,17 +29,30 @@ describe('Admin API', () => {
|
|||||||
adminId = admin.id
|
adminId = admin.id
|
||||||
adminToken = signAdminToken(admin.id)
|
adminToken = signAdminToken(admin.id)
|
||||||
|
|
||||||
|
const protectedAdmin = await createAdminUser({
|
||||||
|
email: 'protected-admin@test.com',
|
||||||
|
role: 'ADMIN',
|
||||||
|
password: 'AdminPass123!',
|
||||||
|
totpEnabled: true,
|
||||||
|
totpSecret: 'JBSWY3DPEHPK3PXP',
|
||||||
|
})
|
||||||
|
protectedAdminToken = signAdminToken(protectedAdmin.id)
|
||||||
|
|
||||||
const financeAdmin = await createAdminUser({
|
const financeAdmin = await createAdminUser({
|
||||||
email: 'finance-admin@test.com',
|
email: 'finance-admin@test.com',
|
||||||
role: 'FINANCE',
|
role: 'FINANCE',
|
||||||
password: 'FinancePass123!',
|
password: 'FinancePass123!',
|
||||||
|
totpEnabled: true,
|
||||||
|
totpSecret: 'JBSWY3DPEHPK3PXP',
|
||||||
})
|
})
|
||||||
financeToken = signAdminToken(financeAdmin.id)
|
financeToken = signAdminToken(financeAdmin.id)
|
||||||
|
|
||||||
const viewerAdmin = await createAdminUser({
|
const viewerAdmin = await createAdminUser({
|
||||||
email: 'viewer-admin@test.com',
|
email: 'viewer-admin@test.com',
|
||||||
role: 'VIEWER',
|
role: 'VIEWER',
|
||||||
password: 'ViewerPass123!',
|
password: 'ViewerPass123!',
|
||||||
|
totpEnabled: true,
|
||||||
|
totpSecret: 'JBSWY3DPEHPK3PXP',
|
||||||
})
|
})
|
||||||
viewerToken = signAdminToken(viewerAdmin.id)
|
viewerToken = signAdminToken(viewerAdmin.id)
|
||||||
|
|
||||||
@@ -90,7 +104,7 @@ describe('Admin API', () => {
|
|||||||
it('returns paginated companies', async () => {
|
it('returns paginated companies', async () => {
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.get('/api/v1/admin/companies')
|
.get('/api/v1/admin/companies')
|
||||||
.set(authHeader(adminToken))
|
.set(authHeader(protectedAdminToken))
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(Array.isArray(res.body.data.data)).toBe(true)
|
expect(Array.isArray(res.body.data.data)).toBe(true)
|
||||||
@@ -103,7 +117,7 @@ describe('Admin API', () => {
|
|||||||
it('returns paginated renters', async () => {
|
it('returns paginated renters', async () => {
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.get('/api/v1/admin/renters')
|
.get('/api/v1/admin/renters')
|
||||||
.set(authHeader(adminToken))
|
.set(authHeader(protectedAdminToken))
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(Array.isArray(res.body.data.data)).toBe(true)
|
expect(Array.isArray(res.body.data.data)).toBe(true)
|
||||||
|
|||||||
@@ -2,14 +2,21 @@ import { describe, expect, it } from 'vitest'
|
|||||||
import { assertImageFile, assertImageFiles } from '../../http/upload'
|
import { assertImageFile, assertImageFiles } from '../../http/upload'
|
||||||
import { assertStorageConfiguration } from '../../lib/storage'
|
import { assertStorageConfiguration } from '../../lib/storage'
|
||||||
|
|
||||||
function fakeFile(mimetype: string, originalname = 'upload.jpg'): Express.Multer.File {
|
const imageFixtures: Record<string, { name: string; buffer: Buffer }> = {
|
||||||
|
'image/jpeg': { name: 'upload.jpg', buffer: Buffer.from([0xff, 0xd8, 0xff, 0x00]) },
|
||||||
|
'image/png': { name: 'upload.png', buffer: Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]) },
|
||||||
|
}
|
||||||
|
|
||||||
|
function fakeFile(mimetype: string, originalname?: string): Express.Multer.File {
|
||||||
|
const fixture = imageFixtures[mimetype]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fieldname: 'file',
|
fieldname: 'file',
|
||||||
originalname,
|
originalname: originalname ?? fixture?.name ?? 'upload.bin',
|
||||||
encoding: '7bit',
|
encoding: '7bit',
|
||||||
mimetype,
|
mimetype,
|
||||||
size: 10,
|
size: fixture?.buffer.length ?? 10,
|
||||||
buffer: Buffer.from('x'),
|
buffer: fixture?.buffer ?? Buffer.from('x'),
|
||||||
stream: undefined as any,
|
stream: undefined as any,
|
||||||
destination: '',
|
destination: '',
|
||||||
filename: '',
|
filename: '',
|
||||||
@@ -21,7 +28,7 @@ describe('infrastructure boundaries', () => {
|
|||||||
it('keeps upload validation strict before service-layer storage writes happen', () => {
|
it('keeps upload validation strict before service-layer storage writes happen', () => {
|
||||||
expect(() => assertImageFile(fakeFile('image/jpeg'))).not.toThrow()
|
expect(() => assertImageFile(fakeFile('image/jpeg'))).not.toThrow()
|
||||||
expect(() => assertImageFiles([fakeFile('image/png')])).not.toThrow()
|
expect(() => assertImageFiles([fakeFile('image/png')])).not.toThrow()
|
||||||
expect(() => assertImageFile(fakeFile('application/pdf', 'id.pdf'))).toThrow('Only image uploads are supported')
|
expect(() => assertImageFile(fakeFile('application/pdf', 'id.pdf'))).toThrow('Unsupported or spoofed image file')
|
||||||
expect(() => assertImageFiles([fakeFile('image/png'), fakeFile('text/plain', 'notes.txt')])).toThrow('notes.txt')
|
expect(() => assertImageFiles([fakeFile('image/png'), fakeFile('text/plain', 'notes.txt')])).toThrow('notes.txt')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ describe('Operations API integration', () => {
|
|||||||
const { company, employee } = await createCompanyWithEmployee({ role: 'OWNER' })
|
const { company, employee } = await createCompanyWithEmployee({ role: 'OWNER' })
|
||||||
companyId = company.id
|
companyId = company.id
|
||||||
employeeId = employee.id
|
employeeId = employee.id
|
||||||
|
await prisma.employee.update({
|
||||||
|
where: { id: employee.id },
|
||||||
|
data: { passwordHash: 'accepted-test-password-hash' },
|
||||||
|
})
|
||||||
token = signEmployeeToken(employee.id, company.id, 'OWNER')
|
token = signEmployeeToken(employee.id, company.id, 'OWNER')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ describe('public validation boundaries', () => {
|
|||||||
provider: 'STRIPE',
|
provider: 'STRIPE',
|
||||||
successUrl: 'https://ok.example.test',
|
successUrl: 'https://ok.example.test',
|
||||||
failureUrl: 'https://fail.example.test',
|
failureUrl: 'https://fail.example.test',
|
||||||
}))).toThrow('Validation failed')
|
accessToken: 'booking-access-token-123',
|
||||||
|
}))).toThrow('Invalid enum value')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('requires enough anonymous marketplace reservation identity to create a booking request', () => {
|
it('requires enough anonymous marketplace reservation identity to create a booking request', () => {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe('dashboard apiFetch', () => {
|
|||||||
const { apiFetch } = await import('./api')
|
const { apiFetch } = await import('./api')
|
||||||
await expect(apiFetch('/team')).resolves.toEqual({ ok: true })
|
await expect(apiFetch('/team')).resolves.toEqual({ ok: true })
|
||||||
|
|
||||||
expect(fetchMock).toHaveBeenCalledWith('/dashboard/api/v1/team', expect.objectContaining({
|
expect(fetchMock).toHaveBeenCalledWith(expect.stringMatching(/\/api\/v1\/team$/), expect.objectContaining({
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
headers: expect.objectContaining({
|
headers: expect.objectContaining({
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
Reference in New Issue
Block a user