Files
ota-admin-portal/src/services/__mocks__/vehiclesAPI.js
2022-10-03 20:50:15 +06:00

123 lines
2.7 KiB
JavaScript

const filters = [
{
can_id: "123-456",
interval: 789
},
{
can_id: "1",
interval: 1000
},
{
can_id: "1000",
interval: 1
}
]
const data = [
{
vin: "3C4PDCBG0ET127145",
year: 2021,
model: "Ocean",
trim: "Basic",
ecu_list: "ECUA 2.0.0, ECUB 2.1.1",
log_level: "info",
canbus: { enabled: true, data_logger_enabled: true, max_mem_buffer_size: 1, max_disk_buffer_size: 2, filters: filters },
},
{ vin: "1G1FP87S3GN100062" },
{ vin: "1HGCG325XYA062256", year: 2021 },
{ vin: "1J4GZ78YXWC160024", year: 2021, model: "Ocean" },
{ vin: "2C3CCAAG8CH222800", model: "Ocean", trim: "Basic" },
{ vin: "KNADM4A39C6028108", year: 2021, model: "Ocean", trim: "Basic" },
{ vin: "1G11C5SL9FF153507", year: 2021, model: "Ocean", trim: "Basic" },
];
const ecusData = [
{
config: "CONFIG",
created: "2021-07-14T20:09:40.98187Z",
ecu: "ECUA",
hw_version: "HWVERSION",
sw_version: "SWVERSION",
updated: "2021-07-14T20:09:40.98187Z",
},
{
config: "CONFIG",
created: "2021-07-14T20:09:40.98187Z",
ecu: "ECUB",
hw_version: "HWVERSION",
sw_version: "SWVERSION",
updated: "2021-07-14T20:09:40.98187Z",
},
];
const signals = {data:[
{
timestamp: "2021-07-14T20:09:40.98187Z",
name: "signal",
value: 123
},
]};
const vehiclesAPI = {
addVehicle: async (vehicle) => {
data.push(vehicle);
return vehicle;
},
deleteVehicle: async (vin) => {
const index = data.findIndex(element => element.vin === vin);
if (index >= 0) data.splice(index, 1);
return vin;
},
getConnections: async (vins) => {
const result = {};
vins.forEach((vin) => {
result[vin] = true;
});
return result;
},
getECUs: async () => {
return { data: ecusData, total: ecusData.length };
},
getModels: async () => {
return {
data: ["Ocean", "Pear"],
};
},
getLocations: jest
.fn()
.mockResolvedValue([
{ altitude: 5, longitude: 10, latitude: 15, vin: "TESTVIN123" },
]),
getVehicle: async (vin) => {
const index = data.findIndex(element => element.vin === vin);
return data[index];
},
getVehicles: async () => {
return { data };
},
getFleets: async (vin) => {return { data: ["fleet1", "fleet2"]}},
getYears: async () => {
return {
data: [2021, 2022],
};
},
sendCommand: async (vin, command) => {
return {
vin,
command,
};
},
updateVehicle: async (vin, vehicle) => {
const index = data.findIndex(element => element.vin === vin);
if (index >= 0) data[index] = vehicle;
return vehicle;
},
getCANSignals: async (vin, vehicle) => {
return signals;
}
};
export default vehiclesAPI;