From 5250e59389a6cd8db8b31b3b2aa12dc044e658f9 Mon Sep 17 00:00:00 2001 From: jtubau Date: Fri, 31 Jan 2025 07:55:53 +0100 Subject: [PATCH] test: refs #7322 add unit tests for getAgencies to validate agency retrieval logic --- .../composables/__tests__/getAgencies.spec.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pages/Route/Agency/composables/__tests__/getAgencies.spec.js b/src/pages/Route/Agency/composables/__tests__/getAgencies.spec.js index 9897173f1..99586b55b 100644 --- a/src/pages/Route/Agency/composables/__tests__/getAgencies.spec.js +++ b/src/pages/Route/Agency/composables/__tests__/getAgencies.spec.js @@ -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(); + }); });