fix: refs #7322 handle null responses in client, agency and address fetching #1313

Merged
jtubau merged 8 commits from 7322-fixDestructuringErrorTicketSection into dev 2025-02-03 11:58:52 +00:00
1 changed files with 21 additions and 0 deletions
Showing only changes of commit 5250e59389 - Show all commits

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();
});
});