import test from 'node:test'; import assert from 'node:assert/strict'; import request from 'supertest'; import { createApp } from '../src/app.js'; process.env.AUTH_BYPASS = 'true'; function createMobileQueryService() { return { getClientDashboard: async () => ({ businessName: 'Google Cafes' }), getClientSession: async () => ({ business: { businessId: 'b1' } }), getCoverageStats: async () => ({ totalCoveragePercentage: 100 }), getCurrentAttendanceStatus: async () => ({ attendanceStatus: 'NOT_CLOCKED_IN' }), getCurrentBill: async () => ({ currentBillCents: 1000 }), getPaymentChart: async () => ([{ amountCents: 100 }]), getPaymentsSummary: async () => ({ totalEarningsCents: 500 }), getPersonalInfo: async () => ({ firstName: 'Ana' }), getProfileSectionsStatus: async () => ({ personalInfoCompleted: true }), getSavings: async () => ({ savingsCents: 200 }), getSpendBreakdown: async () => ([{ category: 'Barista', amountCents: 1000 }]), getStaffDashboard: async () => ({ staffName: 'Ana Barista' }), getStaffProfileCompletion: async () => ({ completed: true }), getStaffSession: async () => ({ staff: { staffId: 's1' } }), getStaffShiftDetail: async () => ({ shiftId: 'shift-1' }), listAssignedShifts: async () => ([{ shiftId: 'assigned-1' }]), listBusinessAccounts: async () => ([{ accountId: 'acc-1' }]), listCancelledShifts: async () => ([{ shiftId: 'cancelled-1' }]), listCertificates: async () => ([{ certificateId: 'cert-1' }]), listCostCenters: async () => ([{ costCenterId: 'cc-1' }]), listCoverageByDate: async () => ([{ shiftId: 'coverage-1' }]), listCompletedShifts: async () => ([{ shiftId: 'completed-1' }]), listHubManagers: async () => ([{ managerId: 'm1' }]), listHubs: async () => ([{ hubId: 'hub-1' }]), listIndustries: async () => (['CATERING']), listInvoiceHistory: async () => ([{ invoiceId: 'inv-1' }]), listOpenShifts: async () => ([{ shiftId: 'open-1' }]), listOrderItemsByDateRange: async () => ([{ itemId: 'item-1' }]), listPaymentsHistory: async () => ([{ paymentId: 'pay-1' }]), listPendingAssignments: async () => ([{ assignmentId: 'asg-1' }]), listPendingInvoices: async () => ([{ invoiceId: 'pending-1' }]), listProfileDocuments: async () => ([{ staffDocumentId: 'doc-1' }]), listRecentReorders: async () => ([{ id: 'order-1' }]), listSkills: async () => (['BARISTA']), listStaffAvailability: async () => ([{ dayOfWeek: 1 }]), listStaffBankAccounts: async () => ([{ accountId: 'acc-2' }]), listStaffBenefits: async () => ([{ benefitId: 'benefit-1' }]), listTodayShifts: async () => ([{ shiftId: 'today-1' }]), listVendorRoles: async () => ([{ roleId: 'role-1' }]), listVendors: async () => ([{ vendorId: 'vendor-1' }]), }; } test('GET /query/client/session returns injected client session', async () => { const app = createApp({ mobileQueryService: createMobileQueryService() }); const res = await request(app) .get('/query/client/session') .set('Authorization', 'Bearer test-token'); assert.equal(res.status, 200); assert.equal(res.body.business.businessId, 'b1'); }); test('GET /query/client/coverage validates date query param', async () => { const app = createApp({ mobileQueryService: createMobileQueryService() }); const res = await request(app) .get('/query/client/coverage') .set('Authorization', 'Bearer test-token'); assert.equal(res.status, 400); assert.equal(res.body.code, 'VALIDATION_ERROR'); }); test('GET /query/staff/dashboard returns injected dashboard', async () => { const app = createApp({ mobileQueryService: createMobileQueryService() }); const res = await request(app) .get('/query/staff/dashboard') .set('Authorization', 'Bearer test-token'); assert.equal(res.status, 200); assert.equal(res.body.staffName, 'Ana Barista'); }); test('GET /query/staff/shifts/:shiftId returns injected shift detail', async () => { const app = createApp({ mobileQueryService: createMobileQueryService() }); const res = await request(app) .get('/query/staff/shifts/shift-1') .set('Authorization', 'Bearer test-token'); assert.equal(res.status, 200); assert.equal(res.body.shiftId, 'shift-1'); });