Files
trackgo-be/src/modules/sales/shared/sales-fields.spec.ts
T
shancheas 5579cf6566 Add payable filter to sales invoices and enhance invoice status handling
- Introduced a new `payable` filter in the `ListSalesInvoicesFilters` and `ListSalesInvoicesQuery` types to allow querying of invoices based on their payable status.
- Updated the `SalesInvoicesRepository` to incorporate logic for filtering invoices that are payable, checking both status and balance.
- Enhanced the `SalesInvoicesService` to support the new `payable` filter in query handling.
- Modified the `SalesInvoiceDto` to include the `payable` property for better API response representation.
- Added unit tests to validate the new filter functionality and ensure proper handling of invoice statuses during updates.
- Updated e2e tests to cover scenarios involving the new payable filter and status transitions for invoices.
2026-08-31 15:15:06 +07:00

128 lines
3.1 KiB
TypeScript

import {
isAllowedStatusTransition,
isValidDocumentCode,
isValidImageUrl,
isValidLatitude,
PACKING_SLIP_USER_TRANSITIONS,
SALES_INVOICE_USER_TRANSITIONS,
SALES_ORDER_SYSTEM_TRANSITIONS,
SALES_ORDER_USER_TRANSITIONS,
SALES_PAYMENT_USER_TRANSITIONS,
} from './sales-fields';
describe('sales fields', () => {
it('accepts generated and user document codes', () => {
expect(isValidDocumentCode('SR-20260824-0001')).toBe(true);
expect(isValidDocumentCode('REQ_01')).toBe(true);
expect(isValidDocumentCode('')).toBe(false);
expect(isValidDocumentCode('SR 1')).toBe(false);
});
it('accepts http(s) image URLs only', () => {
expect(isValidImageUrl('https://cdn.example.com/a.png')).toBe(true);
expect(isValidImageUrl('ftp://x/a.png')).toBe(false);
expect(isValidImageUrl('not-a-url')).toBe(false);
});
it('validates latitude', () => {
expect(isValidLatitude(-6.2)).toBe(true);
expect(isValidLatitude(100)).toBe(false);
});
it('allows sales-order user transitions draft to processed or cancelled', () => {
expect(
isAllowedStatusTransition(
'draft',
'processed',
SALES_ORDER_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'draft',
'cancelled',
SALES_ORDER_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'processed',
'completed',
SALES_ORDER_USER_TRANSITIONS,
),
).toBe(false);
expect(
isAllowedStatusTransition(
'processed',
'completed',
SALES_ORDER_SYSTEM_TRANSITIONS,
),
).toBe(true);
});
it('allows packing processed to completed or cancelled', () => {
expect(
isAllowedStatusTransition(
'processed',
'completed',
PACKING_SLIP_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'draft',
'completed',
PACKING_SLIP_USER_TRANSITIONS,
),
).toBe(false);
});
it('allows invoice user transitions from draft to processed or cancelled', () => {
expect(
isAllowedStatusTransition(
'draft',
'processed',
SALES_INVOICE_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'draft',
'cancelled',
SALES_INVOICE_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'processed',
'completed',
SALES_INVOICE_USER_TRANSITIONS,
),
).toBe(false);
});
it('allows payment pending to approved, rejected, or draft', () => {
expect(
isAllowedStatusTransition(
'draft',
'pending',
SALES_PAYMENT_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'pending',
'approved',
SALES_PAYMENT_USER_TRANSITIONS,
),
).toBe(true);
expect(
isAllowedStatusTransition(
'draft',
'approved',
SALES_PAYMENT_USER_TRANSITIONS,
),
).toBe(false);
});
});