Farmbot-Web-App/frontend/devices/transfer_ownership/__tests__/create_transfer_cert_failur...

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-03-15 10:51:35 -06:00
const mockDevice = { send: jest.fn(() => { return Promise.resolve(); }) };
2018-03-15 10:51:35 -06:00
jest.mock("../../../device", () => ({ getDevice: () => (mockDevice) }));
jest.mock("axios", () => {
return {
2019-02-04 18:54:59 -07:00
post: jest.fn(() => {
return Promise.reject("NOPE");
})
};
});
import { transferOwnership } from "../transfer_ownership";
import { getDevice } from "../../../device";
import {
submitOwnershipChange
} from "../../components/fbos_settings/change_ownership_form";
import { API } from "../../../api";
2019-06-24 15:39:49 -06:00
import { error } from "../../../toast/toast";
API.setBaseUrl("http://foo.bar");
describe("transferOwnership", () => {
it("passes rejected promises down the chain", async () => {
const p = {
email: "admin@admin.com",
password: "password123",
server: "http://127.0.0.1:3000",
device: getDevice()
};
try {
await transferOwnership(p);
fail("If you see this message, transferOwnership(p) is hiding errors.");
} catch (error) {
expect(error).toEqual("NOPE");
}
});
});
2018-03-15 10:51:35 -06:00
describe("submitOwnershipChange", () => {
it("pops a toast when things go wrong", async () => {
await submitOwnershipChange({ email: "email", password: "password" });
expect(error).toHaveBeenCalledWith("Bad username or password");
});
});