CEC-464 can filters forms (#118)

* can filters forms and lists

* unit tests

* updating warnings and tests

* merge develop

* fixed snapshots

* update jest mocks

* updating tests
This commit is contained in:
Drew Taylor
2022-03-03 11:33:07 -08:00
committed by GitHub
parent 3b9252097a
commit b7223b8bc6
37 changed files with 6673 additions and 944 deletions

View File

@@ -0,0 +1,49 @@
import {
getAuthHeaderOptions,
fetchRespHandler,
addQueryParams,
} from "../utils/http";
const API_ENDPOINT = process.env.REACT_APP_UPLOAD_SERVICE_URL;
const canFiltersAPI = {
addFilter: async (vin, filter, token) =>
fetch(`${API_ENDPOINT}/vehicle/${vin}/filter`, {
method: "POST",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
body: JSON.stringify(filter)
}).then(fetchRespHandler),
getFilters: async (vin, search, token) =>
fetch(addQueryParams(`${API_ENDPOINT}/vehicle/${vin}/filters`, search), {
method: "GET",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
}).then(fetchRespHandler),
updateFilter: async (vin, canID, filter, token) =>
fetch(`${API_ENDPOINT}/vehicle/${vin}/filter/${canID}`, {
method: "PUT",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
body: JSON.stringify(filter)
}).then(fetchRespHandler),
deleteFilter: async (vin, canID, token) =>
fetch(`${API_ENDPOINT}/vehicle/${vin}/filter/${canID}`, {
method: "DELETE",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
)
}).then(fetchRespHandler),
};
export default canFiltersAPI;

View File

@@ -0,0 +1,25 @@
const data = [
{ can_id: "123", interval: 1000 },
{ can_id: "456", interval: 0 },
{ can_id: "789-1000", interval: 5 }
];
const canFiltersAPI = {
addFilter: async (vin, filter, token) => {
data.push(filter);
return filter;
},
getFilters: async (vin, search, token) => {
return { data };
},
updateFilter: async (vin, canID, filter, token) => {
const index = data.findIndex(element => element.can_id === canID);
if (index >= 0) data[index] = filter;
},
deleteFilter: async (vin, canID, token) => {
const index = data.findIndex(element => element.can_id === canID);
if (index >= 0) data.splice(index, 1);
},
};
export default canFiltersAPI;