diff --git a/src/components/Contexts/VehicleContext.jsx b/src/components/Contexts/VehicleContext.jsx index 3744469..7ebd07f 100644 --- a/src/components/Contexts/VehicleContext.jsx +++ b/src/components/Contexts/VehicleContext.jsx @@ -292,13 +292,13 @@ export const VehicleProvider = ({ children }) => { }; const getAllFlashpacks = async (options, token) => { - let result; try { setBusy(true); - result = await api.getAllFlashpacks(options, token); - if (result.error) + const result = await api.getAllFlashpacks(options, token); + if (result.error) { throw new Error(`Get all flashpacks error. ${result.message}`); + } setFlashpacks(result.data); if (options && options.offset === 0 && result.total) { @@ -312,13 +312,13 @@ export const VehicleProvider = ({ children }) => { }; const getFlashpackECUMappings = async (model, year, flashpack, options, token) => { - let result; try { setBusy(true); - result = await api.getFlashpackECUMappings(model, year, flashpack, options, token); - if (result.error) + const result = await api.getFlashpackECUMappings(model, year, flashpack, options, token); + if (result.error) { throw new Error(`Get flashpack ecu mappings error. ${result.message}`); + } setFlashpackECUMappings(result.data); if (options && options.offset === 0 && result.total) { @@ -343,8 +343,9 @@ export const VehicleProvider = ({ children }) => { } const result = await api.addFlashpackVersion(data, token) - if (result.error) + if (result.error) { throw new Error(`Add flashpack version error. ${result.message}`); + } return result; } finally { @@ -353,7 +354,6 @@ export const VehicleProvider = ({ children }) => { } const deleteFlashpackVersion = async (model, year, flashpack, token) => { - let result; try { setBusy(true); @@ -363,9 +363,10 @@ export const VehicleProvider = ({ children }) => { "flashpack": flashpack, } - result = await api.deleteFlashpackVersion(data, token); - if (result.error) + const result = await api.deleteFlashpackVersion(data, token); + if (result.error) { throw new Error(`Delete flashpack ecu mappings error. ${result.message}`); + } return result; } finally { diff --git a/src/components/Contexts/__mocks__/VehicleContext.jsx b/src/components/Contexts/__mocks__/VehicleContext.jsx index e280bc9..a996671 100644 --- a/src/components/Contexts/__mocks__/VehicleContext.jsx +++ b/src/components/Contexts/__mocks__/VehicleContext.jsx @@ -187,6 +187,44 @@ export const useVehicleContext = () => ({ total: 2, } }), + getAllFlashpacks: jest.fn((options, token) => { + return { + data: [ + { + flashpack: "44.4", + car_model: "Ocean", + car_year: "2023", + }, + { + flashpack: "38.4", + car_model: "Ocean", + car_year: "2023", + }, + ], + total: 2, + } + }), + getFlashpackECUMappings: jest.fn((model, year, flashpack, options, token) => { + return { + data: [ + { + flashpack: "44.4", + car_model: "Ocean", + car_year: "2023", + car_ecu_name: "ADAS", + car_ecu_version: "99", + }, + { + flashpack: "44.4", + car_model: "Ocean", + car_year: "2023", + car_ecu_name: "PDI", + car_ecu_version: "11", + }, + ], + total: 2, + } + }), }); export const setBusy = (val) => { diff --git a/src/components/Flashpack/Details/index.jsx b/src/components/Flashpack/Details/index.jsx index a40bb91..2fc8bee 100644 --- a/src/components/Flashpack/Details/index.jsx +++ b/src/components/Flashpack/Details/index.jsx @@ -146,7 +146,7 @@ const MainForm = () => { ) : ( + + + Delete + + + { /> {flashpacks && flashpacks.map((row, index) => ( - + {row.flashpack} @@ -156,7 +160,7 @@ const MainForm = () => { {row.car_year} - + { ) : (