63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
jest.mock("axios", () => ({
|
|
interceptors: {
|
|
response: { use: jest.fn() },
|
|
request: { use: jest.fn() }
|
|
},
|
|
post: jest.fn(() => Promise.resolve({ data: { foo: "bar" } })),
|
|
get: jest.fn(() => Promise.resolve({ data: { foo: "bar" } })),
|
|
}));
|
|
|
|
jest.mock("../../api/api", () => ({
|
|
API: {
|
|
setBaseUrl: jest.fn(),
|
|
inferPort: () => 443,
|
|
current: {
|
|
tokensPath: "/api/tokenStub",
|
|
usersPath: "/api/userStub"
|
|
}
|
|
}
|
|
}));
|
|
|
|
jest.mock("../../devices/actions", () => ({
|
|
fetchReleases: jest.fn(),
|
|
fetchLatestGHBetaRelease: jest.fn(),
|
|
fetchMinOsFeatureData: jest.fn(),
|
|
fetchOsReleaseNotes: jest.fn(),
|
|
}));
|
|
|
|
import { didLogin } from "../actions";
|
|
import { Actions } from "../../constants";
|
|
import { API } from "../../api/api";
|
|
import { AuthState } from "../interfaces";
|
|
import { fetchReleases, fetchLatestGHBetaRelease } from "../../devices/actions";
|
|
|
|
const mockToken = (): AuthState => ({
|
|
token: {
|
|
encoded: "---",
|
|
unencoded: { iss: "iss", os_update_server: "os_update_server", jti: "---" }
|
|
}
|
|
});
|
|
|
|
describe("didLogin()", () => {
|
|
it("bootstraps the user session", () => {
|
|
const dispatch = jest.fn();
|
|
const result = didLogin(mockToken(), dispatch);
|
|
expect(result).toBeUndefined();
|
|
|
|
const { iss } = mockToken().token.unencoded;
|
|
expect(API.setBaseUrl).toHaveBeenCalledWith(iss);
|
|
const actions = dispatch.mock.calls.map(x => x && x[0] && x[0].type);
|
|
expect(actions).toContain(Actions.REPLACE_TOKEN);
|
|
});
|
|
|
|
it("fetches beta release info", () => {
|
|
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");
|
|
expect(fetchLatestGHBetaRelease)
|
|
.toHaveBeenCalledWith("beta_os_update_server");
|
|
});
|
|
});
|