test: refs #7322 add unit tests for getAgencies to validate agency retrieval logic
This commit is contained in:
parent
b10cb9f09f
commit
5250e59389
|
@ -3,6 +3,8 @@ import axios from 'axios';
|
||||||
import { getAgencies } from 'src/pages/Route/Agency/composables/getAgencies';
|
import { getAgencies } from 'src/pages/Route/Agency/composables/getAgencies';
|
||||||
|
|
||||||
vi.mock('axios');
|
vi.mock('axios');
|
||||||
|
const response = { data: [{ agencyModeFk: 'Agency1' }, { agencyModeFk: 'Agency2' }] };
|
||||||
|
axios.get.mockResolvedValue(response);
|
||||||
|
|
||||||
describe('getAgencies', () => {
|
describe('getAgencies', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -52,4 +54,23 @@ describe('getAgencies', () => {
|
||||||
|
|
||||||
expect(axios.get).not.toHaveBeenCalled();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue