test: refs #7322 add unit tests for getAgencies to validate agency retrieval logic

This commit is contained in:
Jose Antonio Tubau 2025-01-31 07:55:53 +01:00
parent b10cb9f09f
commit 5250e59389
1 changed files with 21 additions and 0 deletions

View File

@ -3,6 +3,8 @@ import axios from 'axios';
import { getAgencies } from 'src/pages/Route/Agency/composables/getAgencies';
vi.mock('axios');
const response = { data: [{ agencyModeFk: 'Agency1' }, { agencyModeFk: 'Agency2' }] };
axios.get.mockResolvedValue(response);
describe('getAgencies', () => {
afterEach(() => {
@ -52,4 +54,23 @@ describe('getAgencies', () => {
expect(axios.get).not.toHaveBeenCalled();
});
it('should return options and agency when default agency is found', async () => {
const formData = { warehouseId: '123', addressId: '456', landed: 'true' };
const client = { defaultAddress: { agencyModeFk: 'Agency1' } };
const { options, agency } = await getAgencies(formData, client);
expect(options).toEqual(response.data);
expect(agency).toEqual(response.data[0]);
});
it('should return options and agency when client is not provided', async () => {
const formData = { warehouseId: '123', addressId: '456', landed: 'true' };
const { options, agency } = await getAgencies(formData);
expect(options).toEqual(response.data);
expect(agency).toBeNull();
});
});