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

27 lines
783 B
TypeScript
Raw Normal View History

2018-01-02 08:39:40 -07:00
jest.mock("../device", () => {
return { getDevice: () => ({ publish: jest.fn() }) };
});
2017-12-29 16:41:45 -07:00
import { isSafeError, inferUpdateId } from "../interceptor_support";
describe("isSafeError", () => {
it("infers if it is safe to proceed", () => {
const notSafe = { response: { status: "four oh four" } };
expect(isSafeError(notSafe)).toBe(false);
const safe = { response: { status: 404 } };
expect(isSafeError(safe)).toBe(true);
});
});
2017-12-29 16:41:45 -07:00
describe("inferUpdateId", () => {
it("it handles failure by returning `*`", () => {
expect(inferUpdateId("foo/123/456")).toBe("*");
// tslint:disable-next-line:no-any
2017-12-29 16:41:45 -07:00
expect(inferUpdateId((true as any))).toBe("*");
});
2018-01-02 08:39:40 -07:00
it("handles normal URLs", () => {
expect(inferUpdateId("foo/123")).toBe("123");
});
2017-12-29 16:41:45 -07:00
});