From 0f19a62b329b1c19f594ee5944245124c40d61f0 Mon Sep 17 00:00:00 2001 From: John Wu <76966357+jwu-fisker@users.noreply.github.com> Date: Thu, 1 Apr 2021 09:16:38 -0700 Subject: [PATCH 01/14] Sync to main (#26) * Fix sign up form bug * Add run.sh to run setup and run web app * Output node version * Update readme with run.sh * Fix file upload form to handle ota_update service * Enable file upload form Enable error boundary to catch React errors (#7) Fix warning for link noreferrer Include authorization header with file upload * Remove default localhost settings (#8) * Remove default localhost settings Replace with deployment settings * Fix for upload data format * Fix test data for last commit * Fix json link format and remove localhost default settings (#10) * Remove default localhost settings Replace with deployment settings * Fix for upload data format * Fix test data for last commit * Fix link data format * Fix link json again (#12) Use id token instead of access token * nginx things * Web Worker Sign Out and Use Go API (#13) * Calculate checksum and send with file upload * Limit file upload and display rejected file error * Add sign in timeout * Check auth token structure before setting Clean up * Use web worker timer to sign out Remove checksum Point to Go ota update * Remove checksum dependency * Use compute auth service and fix static code analyzer warnings (#15) * Clean up formatting * Use new compute_auth service Implment SSO Implement token refresh Clean up unit tests * Fix unit tests * Fix auth test Fix warnings * Update default settings for compute_auth * Change main UI layout and add VINs to add and upload forms (#16) * Add new upload update package form Add new add vehicle form Add new side menu layout Add new toolbar layout Update and add unit tests * Enable add get and add vehicles * Integration issues with ota_update service * Update get vehicle JSON format * Fix related unit test Add release notes field * Add StatusContext to display error and status messages * Handle api error json (#18) * Handle api error json * Fix get vehicles error handling Update .env.template * Fix signout refresh (#20) * Merge to main (#17) * Fix sign up form bug * Add run.sh to run setup and run web app * Output node version * Update readme with run.sh * Fix file upload form to handle ota_update service * Enable file upload form Enable error boundary to catch React errors (#7) Fix warning for link noreferrer Include authorization header with file upload * Remove default localhost settings (#8) * Remove default localhost settings Replace with deployment settings * Fix for upload data format * Fix test data for last commit * Fix json link format and remove localhost default settings (#10) * Remove default localhost settings Replace with deployment settings * Fix for upload data format * Fix test data for last commit * Fix link data format * Fix link json again (#12) Use id token instead of access token * nginx things * Web Worker Sign Out and Use Go API (#13) * Calculate checksum and send with file upload * Limit file upload and display rejected file error * Add sign in timeout * Check auth token structure before setting Clean up * Use web worker timer to sign out Remove checksum Point to Go ota update * Remove checksum dependency * Use compute auth service and fix static code analyzer warnings (#15) * Clean up formatting * Use new compute_auth service Implment SSO Implement token refresh Clean up unit tests * Fix unit tests * Fix auth test Fix warnings * Update default settings for compute_auth * Change main UI layout and add VINs to add and upload forms (#16) * Add new upload update package form Add new add vehicle form Add new side menu layout Add new toolbar layout Update and add unit tests * Enable add get and add vehicles * Integration issues with ota_update service * Update get vehicle JSON format * Fix related unit test Add release notes field * Add StatusContext to display error and status messages * Handle api error json (#18) * Handle api error json * Fix get vehicles error handling Update .env.template Co-authored-by: Rafi Greenberg * Fix sign out and refresh * Check for bad json Co-authored-by: Rafi Greenberg * Add role checks (#21) * Add role checks * Remove moved Roles enum * Add package updates, car updates, and vehicle screens (#25) Co-authored-by: Rafi Greenberg --- package-lock.json | 20 +- src/components/App/App.test.js | 25 +- .../App/__snapshots__/App.test.js.snap | 1572 ++++++++++------- src/components/CarUpdates/Deploy/index.jsx | 225 +++ src/components/CarUpdates/Status/index.jsx | 139 ++ .../{VehicleAddForm => Cars/Add}/index.jsx | 56 +- src/components/Cars/List/index.jsx | 121 ++ src/components/Contexts/FileUploadContext.jsx | 6 +- .../Contexts/FileUploadContext.test.jsx | 1 - .../Contexts/UpdateContext.test.jsx | 291 +++ src/components/Contexts/UpdatesContext.jsx | 131 ++ src/components/Contexts/UserContext.jsx | 46 +- src/components/Contexts/UserContext.test.jsx | 70 +- src/components/Contexts/VehicleContext.jsx | 13 + .../Contexts/VehicleContext.test.jsx | 4 +- .../Contexts/__mocks__/UserContext.jsx | 15 +- .../__snapshots__/FileUploadForm.test.js.snap | 287 --- src/components/Home/index.jsx | 35 + src/components/Layouts/MenuDrawer.jsx | 10 +- src/components/Layouts/SideMenu.jsx | 44 +- src/components/Layouts/SideMenu.test.jsx | 33 + .../__snapshots__/SideMenu.test.jsx.snap | 159 ++ src/components/Routes/AuthRoute.jsx | 15 +- src/components/Routes/SiteRoutes.jsx | 63 +- .../Create/Create.test.js} | 13 +- .../Create/__snapshots__/Create.test.js.snap | 237 +++ .../Create}/index.jsx | 91 +- src/components/UpdatePackages/Edit/index.jsx | 198 +++ src/components/UpdatePackages/List/index.jsx | 156 ++ src/components/useStyles.jsx | 2 +- src/services/__mocks__/updates.js | 48 + src/services/__mocks__/uploadFile.js | 2 +- src/services/updates.js | 42 + src/services/uploadFile.js | 12 +- src/services/vehicles.js | 18 +- src/utils/dates.js | 13 + src/utils/http.js | 12 +- src/utils/http.test.js | 42 + src/utils/jwt.js | 14 + src/utils/jwt.test.js | 14 + src/utils/roles.js | 35 + src/utils/roles.test.js | 10 + src/utils/testing.js | 8 + 43 files changed, 3243 insertions(+), 1105 deletions(-) create mode 100644 src/components/CarUpdates/Deploy/index.jsx create mode 100644 src/components/CarUpdates/Status/index.jsx rename src/components/{VehicleAddForm => Cars/Add}/index.jsx (54%) create mode 100644 src/components/Cars/List/index.jsx create mode 100644 src/components/Contexts/UpdateContext.test.jsx create mode 100644 src/components/Contexts/UpdatesContext.jsx delete mode 100644 src/components/FileUploadForm/__snapshots__/FileUploadForm.test.js.snap create mode 100644 src/components/Home/index.jsx create mode 100644 src/components/Layouts/SideMenu.test.jsx create mode 100644 src/components/Layouts/__snapshots__/SideMenu.test.jsx.snap rename src/components/{FileUploadForm/FileUploadForm.test.js => UpdatePackages/Create/Create.test.js} (56%) create mode 100644 src/components/UpdatePackages/Create/__snapshots__/Create.test.js.snap rename src/components/{FileUploadForm => UpdatePackages/Create}/index.jsx (60%) create mode 100644 src/components/UpdatePackages/Edit/index.jsx create mode 100644 src/components/UpdatePackages/List/index.jsx create mode 100644 src/services/__mocks__/updates.js create mode 100644 src/services/updates.js create mode 100644 src/utils/dates.js create mode 100644 src/utils/http.test.js create mode 100644 src/utils/jwt.js create mode 100644 src/utils/jwt.test.js create mode 100644 src/utils/roles.js create mode 100644 src/utils/roles.test.js create mode 100644 src/utils/testing.js diff --git a/package-lock.json b/package-lock.json index 1d9c2e9..5a88d35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7361,9 +7361,9 @@ "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==" }, "immer": { - "version": "7.0.9", - "resolved": "https://registry.npmjs.org/immer/-/immer-7.0.9.tgz", - "integrity": "sha512-Vs/gxoM4DqNAYR7pugIxi0Xc8XAun/uy7AQu4fLLqaTBHxjOP9pJ266Q9MWA/ly4z6rAFZbvViOtihxUZ7O28A==" + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/immer/-/immer-8.0.1.tgz", + "integrity": "sha512-aqXhGP7//Gui2+UrEtvxZxSquQVXTpZ7KDxfCcKAF3Vysvw0CViVaW9RZ1j1xlIYqaaaipBoqdqeibkc18PNvA==" }, "import-cwd": { "version": "2.1.0", @@ -9969,9 +9969,9 @@ } }, "open": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/open/-/open-7.4.0.tgz", - "integrity": "sha512-PGoBCX/lclIWlpS/R2PQuIR4NJoXh6X5AwVzE7WXnWRGvHg7+4TBCgsujUgiPpm0K1y4qvQeWnCWVTpTKZBtvA==", + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", + "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", "requires": { "is-docker": "^2.0.0", "is-wsl": "^2.1.1" @@ -11697,9 +11697,9 @@ } }, "react-dev-utils": { - "version": "11.0.2", - "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-11.0.2.tgz", - "integrity": "sha512-xG7GlMoYkrgc2M1kDCHKRywXMDbFnjOB+/VzpytQyYBusEzR8NlGTMmUbvN86k94yyKu5XReHB8eZC2JZrNchQ==", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-11.0.4.tgz", + "integrity": "sha512-dx0LvIGHcOPtKbeiSUM4jqpBl3TcY7CDjZdfOIcKeznE7BWr9dg0iPG90G5yfVQ+p/rGNMXdbfStvzQZEVEi4A==", "requires": { "@babel/code-frame": "7.10.4", "address": "1.1.2", @@ -11714,7 +11714,7 @@ "global-modules": "2.0.0", "globby": "11.0.1", "gzip-size": "5.1.1", - "immer": "7.0.9", + "immer": "8.0.1", "is-root": "2.1.0", "loader-utils": "2.0.0", "open": "^7.0.2", diff --git a/src/components/App/App.test.js b/src/components/App/App.test.js index c816b0d..e9da1e6 100644 --- a/src/components/App/App.test.js +++ b/src/components/App/App.test.js @@ -4,9 +4,9 @@ jest.mock("../Contexts/VehicleContext"); import { render, screen, cleanup, waitForElementToBeRemoved } from "@testing-library/react"; import { setToken } from "../Contexts/UserContext"; +import { TEST_AUTH_OBJECT } from "../../utils/testing" import App from "."; -const TEST_TOKEN = { idToken: { jwtToken: "TEST" } }; const LOADING_STATUS = "Loading..."; const renderRoute = async (route) => { @@ -37,6 +37,12 @@ describe("App", () => { expect(container).toMatchSnapshot(); }); + it("Route /package-upload unauthenticated", async () => { + const container = await renderRoute("/package-upload"); + expect(container.querySelector("span.MuiButton-label").innerHTML).toEqual("Sign In"); + expect(container).toMatchSnapshot(); + }); + it("Route /vehicle-add unauthenticated", async () => { const container = await renderRoute("/vehicle-add"); expect(container.querySelector("span.MuiButton-label").innerHTML).toEqual("Sign In"); @@ -44,21 +50,28 @@ describe("App", () => { }); it("Route / authenticated", async () => { - setToken(TEST_TOKEN); + setToken(TEST_AUTH_OBJECT); const container = await renderRoute("/"); - expect(container.querySelector("h1").innerHTML).toEqual("Upload Update Package"); + expect(container.querySelector("h1").innerHTML).toEqual("Welcome John!"); expect(container).toMatchSnapshot(); }); it("Route /home authenticated", async () => { - setToken(TEST_TOKEN); + setToken(TEST_AUTH_OBJECT); const container = await renderRoute("/home"); + expect(container.querySelector("h1").innerHTML).toEqual("Welcome John!"); + expect(container).toMatchSnapshot(); + }); + + it("Route /package-upload authenticated", async () => { + setToken(TEST_AUTH_OBJECT); + const container = await renderRoute("/package-upload"); expect(container.querySelector("h1").innerHTML).toEqual("Upload Update Package"); expect(container).toMatchSnapshot(); }); it("Route /vehicle-add authenticated", async () => { - setToken(TEST_TOKEN); + setToken(TEST_AUTH_OBJECT); const container = await renderRoute("/vehicle-add"); expect(container.querySelector("h1").innerHTML).toEqual("Add Vehicle"); expect(container).toMatchSnapshot(); @@ -71,7 +84,7 @@ describe("App", () => { }); it("Route /page-not-found authenticated", async () => { - setToken(TEST_TOKEN); + setToken(TEST_AUTH_OBJECT); const container = await renderRoute("/page-not-found"); expect(container.querySelector("h1").innerHTML).toEqual("Page Not Found"); expect(container).toMatchSnapshot(); diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index f2b0a88..0be10e1 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -6,17 +6,17 @@ exports[`App Route / authenticated 1`] = ` data-testid="mocked-userprovider" >
-
-
-

- Upload Update Package -

-
-
- -
- - -
-
-
- -
- - -
-
-
- -
-