add more crud tests
parent
32f3c2707e
commit
126a23edc2
|
@ -1,20 +1,25 @@
|
|||
const mockDevice = {
|
||||
on: jest.fn(() => { return Promise.resolve(); }),
|
||||
};
|
||||
|
||||
jest.mock("../../device", () => ({
|
||||
getDevice: () => mockDevice
|
||||
}));
|
||||
|
||||
jest.mock("axios", () => ({
|
||||
default: {
|
||||
get: () => {
|
||||
return Promise.resolve({ data: {} });
|
||||
}
|
||||
get: () => { return Promise.resolve({ data: "" }); },
|
||||
put: () => { return Promise.resolve({ data: "" }); },
|
||||
}
|
||||
}));
|
||||
|
||||
jest.mock("../../resources/tagged_resources", () => ({
|
||||
isTaggedResource: () => false
|
||||
}));
|
||||
|
||||
import { refresh } from "../crud";
|
||||
import { refresh, updateViaAjax } from "../crud";
|
||||
import { TaggedDevice, SpecialStatus } from "../../resources/tagged_resources";
|
||||
import { API } from "../index";
|
||||
import { get } from "lodash";
|
||||
import { Actions } from "../../constants";
|
||||
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
|
||||
import { fakePeripheral } from "../../__test_support__/fake_state/resources";
|
||||
|
||||
describe("refresh()", () => {
|
||||
API.setBaseUrl("http://localhost:3000");
|
||||
|
@ -57,3 +62,18 @@ describe("refresh()", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("updateViaAjax()", () => {
|
||||
it("rejects malformed API data", () => {
|
||||
const payload = {
|
||||
uuid: "",
|
||||
statusBeforeError: SpecialStatus.DIRTY,
|
||||
dispatch: jest.fn(),
|
||||
index: buildResourceIndex([fakePeripheral()]).index
|
||||
};
|
||||
payload.uuid = payload.index.all[0];
|
||||
updateViaAjax(payload).catch(e => {
|
||||
expect("" + e).toEqual("Error: Just saved a malformed TR.");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import { urlFor } from "../crud";
|
||||
import { API } from "../api";
|
||||
import { ResourceName } from "../../resources/tagged_resources";
|
||||
|
||||
describe("urlFor()", () => {
|
||||
API.setBaseUrl("");
|
||||
|
||||
it("no URL yet", () => {
|
||||
expect(() => urlFor("NewResourceWithoutURLHandler" as ResourceName))
|
||||
.toThrowError(/NewResourceWithoutURLHandler/);
|
||||
});
|
||||
});
|
|
@ -239,7 +239,7 @@ const SINGULAR_RESOURCE: ResourceName[] =
|
|||
["WebAppConfig", "FbosConfig", "FirmwareConfig"];
|
||||
|
||||
/** Shared functionality in create() and update(). */
|
||||
function updateViaAjax(payl: AjaxUpdatePayload) {
|
||||
export function updateViaAjax(payl: AjaxUpdatePayload) {
|
||||
const { uuid, statusBeforeError, dispatch, index } = payl;
|
||||
const resource = findByUuid(index, uuid);
|
||||
const { body, kind } = resource;
|
||||
|
|
Loading…
Reference in New Issue