Test case I for findSlotByToolId
parent
fbd7d63f5b
commit
5fa1edfbce
|
@ -0,0 +1,26 @@
|
|||
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
|
||||
import { findSlotByToolId } from "../selectors";
|
||||
import { resourceReducer } from "../reducer";
|
||||
import { Actions } from "../../constants";
|
||||
import { init } from "../../api/crud";
|
||||
import { TaggedTool } from "../tagged_resources";
|
||||
import { createOK } from "../actions";
|
||||
import { generateUuid } from "../util";
|
||||
|
||||
describe("findSlotByToolId", () => {
|
||||
it("returns undefined when not found", () => {
|
||||
const ID = 99;
|
||||
let fakeTool: TaggedTool = {
|
||||
kind: "tools",
|
||||
uuid: generateUuid(ID, "tools"),
|
||||
body: {
|
||||
name: "yadda yadda",
|
||||
id: ID
|
||||
}
|
||||
};
|
||||
let state = resourceReducer(buildResourceIndex(), createOK(fakeTool));
|
||||
expect(state.index.byKindAndId["tools." + fakeTool.body.id]);
|
||||
let result = findSlotByToolId(state.index, ID);
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
|
@ -1,17 +1,18 @@
|
|||
import { TaggedResource } from "./tagged_resources";
|
||||
import { UnsafeError } from "../interfaces";
|
||||
import { toastErrors } from "../util";
|
||||
import { Actions } from "../constants";
|
||||
|
||||
export function createOK(payload: TaggedResource) {
|
||||
return { type: "SAVE_RESOURCE_OK", payload };
|
||||
return { type: Actions.SAVE_RESOURCE_OK, payload };
|
||||
}
|
||||
|
||||
export function updateOK(payload: TaggedResource) {
|
||||
return { type: "UPDATE_RESOURCE_OK", payload };
|
||||
return { type: Actions.UPDATE_RESOURCE_OK, payload };
|
||||
}
|
||||
|
||||
export function destroyOK(payload: TaggedResource) {
|
||||
return { type: "DESTROY_RESOURCE_OK", payload };
|
||||
return { type: Actions.DESTROY_RESOURCE_OK, payload };
|
||||
}
|
||||
|
||||
/** Generalized error handler when there are not special error handling
|
||||
|
|
|
@ -39,7 +39,7 @@ let consumerReducer = combineReducers<RestResources["consumers"]>({
|
|||
sequences,
|
||||
farm_designer,
|
||||
farmware
|
||||
} as any);
|
||||
} as any); // tslint:disable-line
|
||||
|
||||
export function emptyState(): RestResources {
|
||||
return {
|
||||
|
@ -106,7 +106,7 @@ export let resourceReducer = generateReducer
|
|||
&& resource.body) {
|
||||
switch (resource.kind) {
|
||||
case "sequences":
|
||||
case "device": // tslint:disable-line
|
||||
case "device":
|
||||
case "users":
|
||||
case "farm_events":
|
||||
case "logs":
|
||||
|
@ -190,15 +190,6 @@ export let resourceReducer = generateReducer
|
|||
.add<TaggedResource>(Actions.INIT_RESOURCE, (s, { payload }) => {
|
||||
let tr = payload;
|
||||
let uuid = tr.uuid;
|
||||
// TEMPORARY STUB:
|
||||
// Problem: Old versions of FBOS send timestamp as 8601 string.
|
||||
// New versions send it as a unix timestamp
|
||||
// This creates backwards compat issues.
|
||||
// SOLUTINON: Convert strings to unix timestamps at runtime.
|
||||
// NOTE: Remove this in June 2017.
|
||||
if (tr.kind === "logs" && (typeof tr.body.created_at === "string")) {
|
||||
tr.body.created_at = moment(tr.body.created_at).unix();
|
||||
}
|
||||
reindexResource(s.index, tr);
|
||||
if (tr.kind === "logs") {
|
||||
// Since logs don't come from the API all the time, they are the only
|
||||
|
@ -250,7 +241,7 @@ function addToIndex<T>(index: ResourceIndex,
|
|||
kind: ResourceName,
|
||||
body: T,
|
||||
uuid: string) {
|
||||
let tr: TaggedResource = { kind, body, uuid } as any; // TODO: Fix this :(
|
||||
let tr: TaggedResource = { kind, body, uuid } as any;
|
||||
sanityCheck(tr);
|
||||
index.all.push(tr.uuid);
|
||||
index.byKind[tr.kind].push(tr.uuid);
|
||||
|
|
|
@ -77,7 +77,7 @@ export type TaggedUser = Resource<"users", User>;
|
|||
export type TaggedDevice = Resource<"device", DeviceAccountSettings>;
|
||||
|
||||
/** Spot check to be certain a TaggedResource is what it says it is. */
|
||||
export function sanityCheck(x: object) {
|
||||
export function sanityCheck(x: object): x is TaggedResource {
|
||||
if (isTaggedResource(x)) {
|
||||
assertUuid(x.kind, x.uuid);
|
||||
return true;
|
||||
|
|
|
@ -143,7 +143,7 @@ export let IfBlockDropDownHandler = (props: IfParams,
|
|||
throw new Error("Failed type assertion");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function overwriteStep(input: Execute | Nothing) {
|
||||
let update = defensiveClone(step);
|
||||
|
|
Loading…
Reference in New Issue