Farmbot-Web-App/frontend/__tests__/refresh_token_ok_test.ts

37 lines
864 B
TypeScript
Raw Normal View History

const mockAuth = (iss = "987"): AuthState => ({
2017-10-05 13:04:39 -06:00
token: {
encoded: "---",
2017-11-10 12:54:34 -07:00
unencoded: { iss, os_update_server: "---", jti: "---" }
2017-10-05 13:04:39 -06:00
}
});
jest.mock("axios", () => ({
2019-02-04 18:54:59 -07:00
get() {
return Promise.resolve({ data: mockAuth("000") });
},
interceptors: {
response: { use: jest.fn() },
request: { use: jest.fn() }
2017-10-05 13:04:39 -06:00
}
}));
import { AuthState } from "../auth/interfaces";
import { maybeRefreshToken } from "../refresh_token";
import { API } from "../api/index";
2017-10-12 14:28:19 -06:00
API.setBaseUrl("http://whatever.party");
2017-10-05 13:04:39 -06:00
describe("maybeRefreshToken()", () => {
it("gives you back your token when things fail", (done) => {
maybeRefreshToken(mockAuth("111"))
.then((nextToken) => {
2017-10-13 14:42:29 -06:00
if (nextToken) {
expect(nextToken.token.unencoded.iss).toEqual("000");
2017-10-13 14:42:29 -06:00
done();
} else {
fail();
}
2017-10-05 13:04:39 -06:00
});
});
});