test: fix
gitea/salix-front/pipeline/pr-test This commit looks good Details

This commit is contained in:
Javier Segarra 2025-02-18 00:45:52 +01:00
parent e6e21b61bd
commit 3ca73d03a0
2 changed files with 14 additions and 11 deletions

View File

@ -27,14 +27,17 @@ describe('getAgencies', () => {
landed: 'true',
};
const filter = {
fields: ['nickname', 'street', 'city', 'id'],
fields: ['name', 'street', 'city', 'id'],
where: { isActive: true },
order: 'nickname ASC',
order: ['name ASC'],
};
await getAgencies(formData, null, filter);
expect(axios.get).toHaveBeenCalledWith('Agencies/getAgenciesWithWarehouse', generateParams(formData, filter));
expect(axios.get).toHaveBeenCalledWith(
'Agencies/getAgenciesWithWarehouse',
generateParams(formData, filter),
);
});
it('should not call API when formData is missing required landed field', async () => {
@ -64,19 +67,19 @@ describe('getAgencies', () => {
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 () => {
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();
});
});
});

View File

@ -4,8 +4,8 @@ export async function getAgencies(formData, client, _filter = {}) {
if (!formData.warehouseId || !formData.addressId || !formData.landed) return;
const filter = {
order: ['name ASC'],
..._filter,
order: ['name ASC'],
};
let defaultAgency = null;