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
This commit is contained in:
John Wu
2021-02-08 15:23:36 -08:00
committed by GitHub
parent 1ddf9fe813
commit e1f0006d5e
13 changed files with 1630 additions and 2173 deletions

View File

@@ -1,10 +1,17 @@
jest.mock("../../services/auth");
jest.mock("../../services/timer");
import {render, cleanup, screen, fireEvent, waitFor} from "@testing-library/react"
import { UserProvider, useUserContext } from "../Contexts/UserContext";
import auth from "../../services/auth";
import getTimerWorker from "../../services/timer";
const TEST_TOKEN = { idToken: { jwtToken: "TEST" }};
const TEST_TOKEN = { idToken: {
jwtToken: "TEST",
payload: {
exp: (new Date().getTime() / 1000)
}
}};
describe("UseContext", () => {
@@ -114,14 +121,22 @@ describe("UseContext", () => {
it("No error sign in", async () => {
const TOKEN_STRING = JSON.stringify(TEST_TOKEN);
const timer = getTimerWorker();
auth.setSignInResponse(TEST_TOKEN);
auth.setVerifyResponse({ authenticated: true })
fireEvent.click(screen.getByTestId("signIn"));
await waitFor(() => expect(screen.getByTestId("fetching").innerHTML).toEqual("false"));
expect(screen.getByTestId("error").innerHTML).toEqual("");
expect(screen.getByTestId("token").innerHTML).toEqual(TOKEN_STRING);
if (!localStorage) return;
expect(localStorage.getItem("token")).toEqual(TOKEN_STRING);
localStorage.removeItem("token");
expect(timer.start.mock.calls.length).toEqual(1);
expect(timer.onMessage.mock.calls.length).toEqual(1);
expect(timer.stop.mock.calls.length).toEqual(0);
expect(timer.terminate.mock.calls.length).toEqual(0);
if (!localStorage) {
expect(localStorage.getItem("token")).toEqual(TOKEN_STRING);
localStorage.removeItem("token");
}
});
it("Handle server error", async () => {