Farmbot-Web-App/frontend/auth/__tests__/actions_test.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-10-16 15:46:33 -06:00
jest.mock("axios", () => ({
2019-02-04 18:54:59 -07:00
interceptors: {
response: { use: jest.fn() },
request: { use: jest.fn() }
},
2020-03-13 15:06:40 -06:00
post: jest.fn(() => Promise.resolve({ data: { foo: "bar" } })),
get: jest.fn(() => Promise.resolve({ data: { foo: "bar" } })),
2017-10-16 15:46:33 -06:00
}));
jest.mock("../../api/api", () => ({
API: {
setBaseUrl: jest.fn(),
inferPort: () => 443,
current: {
tokensPath: "/api/tokenStub",
usersPath: "/api/userStub"
}
}
}));
jest.mock("../../devices/actions", () => ({
fetchReleases: jest.fn(),
2019-01-04 14:26:52 -07:00
fetchLatestGHBetaRelease: jest.fn(),
fetchMinOsFeatureData: jest.fn(),
2020-03-13 15:06:40 -06:00
fetchOsReleaseNotes: jest.fn(),
}));
2018-04-23 10:22:03 -06:00
import { didLogin } from "../actions";
2017-10-16 15:46:33 -06:00
import { Actions } from "../../constants";
import { API } from "../../api/api";
import { AuthState } from "../interfaces";
2019-01-04 14:26:52 -07:00
import { fetchReleases, fetchLatestGHBetaRelease } from "../../devices/actions";
2018-04-23 10:22:03 -06:00
const mockToken = (): AuthState => ({
2018-04-23 10:22:03 -06:00
token: {
encoded: "---",
unencoded: { iss: "iss", os_update_server: "os_update_server", jti: "---" }
}
2017-10-16 15:46:33 -06:00
});
describe("didLogin()", () => {
it("bootstraps the user session", () => {
2017-10-16 16:28:41 -06:00
const dispatch = jest.fn();
const result = didLogin(mockToken(), dispatch);
2017-10-16 16:28:41 -06:00
expect(result).toBeUndefined();
const { iss } = mockToken().token.unencoded;
2017-10-16 16:28:41 -06:00
expect(API.setBaseUrl).toHaveBeenCalledWith(iss);
const actions = dispatch.mock.calls.map(x => x && x[0] && x[0].type);
expect(actions).toContain(Actions.REPLACE_TOKEN);
});
2018-04-23 10:22:03 -06:00
it("fetches beta release info", () => {
2018-04-23 10:22:03 -06:00
const dispatch = jest.fn();
const mockAuth = mockToken();
mockAuth.token.unencoded.beta_os_update_server = "beta_os_update_server";
didLogin(mockAuth, dispatch);
expect(fetchReleases).toHaveBeenCalledWith("os_update_server");
2019-01-04 14:26:52 -07:00
expect(fetchLatestGHBetaRelease)
.toHaveBeenCalledWith("beta_os_update_server");
2018-04-23 10:22:03 -06:00
});
});