first commit 🎉
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it, beforeEach, mock } from 'bun:test'
|
||||
import QueryService from '~/modules/purchase_order/queries/service'
|
||||
|
||||
// Default mocks
|
||||
mock.module('~/modules/purchase_order/queries/query', () => ({
|
||||
default: {
|
||||
listPurchaseOrders: mock(async (payload: any) => ({
|
||||
data: [{ id: 'po-1', orderNumber: 'PO-001' }],
|
||||
meta: { page: 1, size: 10, totalData: 1, totalPage: 1 },
|
||||
})),
|
||||
getPurchaseOrderById: mock(async (id: string) => {
|
||||
if (id === 'po-1') return { id: 'po-1', orderNumber: 'PO-001' }
|
||||
return null
|
||||
}),
|
||||
getPurchaseOrderReport: mock(async (params: any) => ({
|
||||
purchaseOrders: [{ id: 'po-1', orderNumber: 'PO-001' }],
|
||||
summary: { totalAmount: 1000, totalClaimAmount: 100, totalMarginAmount: 50 },
|
||||
})),
|
||||
},
|
||||
}))
|
||||
|
||||
describe('Purchase Order QueryService', () => {
|
||||
beforeEach(() => {
|
||||
mock.restore()
|
||||
mock.module('~/modules/purchase_order/queries/query', () => ({
|
||||
default: {
|
||||
listPurchaseOrders: mock(async (payload: any) => ({
|
||||
data: [{ id: 'po-1', orderNumber: 'PO-001' }],
|
||||
meta: { page: payload.page ?? 1, size: payload.size ?? 10, totalData: 1, totalPage: 1 },
|
||||
})),
|
||||
getPurchaseOrderById: mock(async (id: string) => {
|
||||
if (id === 'po-1') return { id: 'po-1', orderNumber: 'PO-001' }
|
||||
return null
|
||||
}),
|
||||
getPurchaseOrderReport: mock(async (params: any) => ({
|
||||
purchaseOrders: [{ id: 'po-1', orderNumber: 'PO-001' }],
|
||||
summary: { totalAmount: 1000, totalClaimAmount: 100, totalMarginAmount: 50 },
|
||||
})),
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
it('should return purchase orders list with meta', async () => {
|
||||
const result = await QueryService.getPurchaseOrders({ page: 1, size: 10 })
|
||||
expect(result).toBeDefined()
|
||||
expect(Array.isArray(result.data)).toBe(true)
|
||||
expect(result.meta).toBeDefined()
|
||||
expect(result.meta.page).toBe(1)
|
||||
})
|
||||
|
||||
it('should return a single purchase order when found', async () => {
|
||||
const po = await QueryService.getPurchaseOrder('po-1')
|
||||
expect(po).toBeDefined()
|
||||
expect(po).not.toBeNull()
|
||||
expect((po as any).id).toBe('po-1')
|
||||
})
|
||||
|
||||
it('should return null when purchase order not found', async () => {
|
||||
const po = await QueryService.getPurchaseOrder('missing-po')
|
||||
expect(po).toBeNull()
|
||||
})
|
||||
|
||||
it('should return report data', async () => {
|
||||
const report = await QueryService.getPurchaseOrderReport({
|
||||
partnerId: 'partner-123',
|
||||
startDate: new Date().toISOString(),
|
||||
endDate: new Date().toISOString(),
|
||||
} as any)
|
||||
expect(report).toBeDefined()
|
||||
expect(Array.isArray(report.purchaseOrders)).toBe(true)
|
||||
expect(report.summary).toBeDefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user