Fix failing tests related to stash/unstash
parent
4dde181488
commit
6edbfa33c0
|
@ -1,14 +0,0 @@
|
|||
import { connectivityReducer, DEFAULT_STATE } from "../reducer";
|
||||
import { fakeDevice } from "../../__test_support__/resource_index_builder";
|
||||
import { resourceReady } from "../../sync/actions";
|
||||
|
||||
describe("Connectivity Reducer - RESOURCE_READY", () => {
|
||||
it("handles `undefined` status", () => {
|
||||
pending("I want this to go away permanently - RC");
|
||||
const device = fakeDevice();
|
||||
device.body.last_saw_mq = "Tue, 03 Oct 2017 09:00:00 -0500";
|
||||
const action = resourceReady("Device", device);
|
||||
const result = connectivityReducer(DEFAULT_STATE, action);
|
||||
expect(result.uptime["bot.mqtt"]).not.toBe(undefined);
|
||||
});
|
||||
});
|
|
@ -15,7 +15,7 @@ export const DEFAULT_STATE: ConnectionState = {
|
|||
pings: {
|
||||
},
|
||||
};
|
||||
type PingResultPayload = { id: string, at: number };
|
||||
export type PingResultPayload = { id: string, at: number };
|
||||
|
||||
export let connectivityReducer =
|
||||
generateReducer<ConnectionState>(DEFAULT_STATE)
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import { botReducer, initialState } from "../reducer";
|
||||
import { Actions } from "../../constants";
|
||||
import { ControlPanelState } from "../interfaces";
|
||||
import { ControlPanelState, BotState } from "../interfaces";
|
||||
import { defensiveClone } from "../../util";
|
||||
import { networkUp, networkDown } from "../../connectivity/actions";
|
||||
import { stash } from "../../connectivity/data_consistency";
|
||||
import { incomingStatus } from "../../connectivity/connect_device";
|
||||
import { Vector3 } from "farmbot";
|
||||
import { Vector3, uuid } from "farmbot";
|
||||
import { values, omit } from "lodash";
|
||||
import { now } from "../connectivity/qos";
|
||||
|
||||
const statusOf = (state: BotState) => {
|
||||
return state.hardware.informational_settings.sync_status;
|
||||
};
|
||||
|
||||
describe("botReducer", () => {
|
||||
it("Starts / stops an update", () => {
|
||||
|
@ -111,19 +115,26 @@ describe("botReducer", () => {
|
|||
step1.statusStash = "booting";
|
||||
step1.hardware.informational_settings.sync_status = "synced";
|
||||
|
||||
const step2 = botReducer(step1, networkDown("bot.mqtt"));
|
||||
expect(step2.statusStash)
|
||||
.toBe(step1.hardware.informational_settings.sync_status);
|
||||
expect(step2.hardware.informational_settings.sync_status).toBeUndefined();
|
||||
const go = (direction: "up" | "down", one: BotState) => {
|
||||
const id = uuid();
|
||||
const action1 = { type: Actions.PING_START, payload: { id } };
|
||||
const two = botReducer(one, action1);
|
||||
const type_ = (direction == "up") ? Actions.PING_OK : Actions.PING_NO;
|
||||
const action2 = { type: type_, payload: { id, at: now() } };
|
||||
|
||||
const step3 = botReducer(step1, networkDown("bot.mqtt"));
|
||||
expect(step3.statusStash)
|
||||
.toBe(step1.hardware.informational_settings.sync_status);
|
||||
expect(step3.hardware.informational_settings.sync_status).toBeUndefined();
|
||||
return botReducer(two, action2);
|
||||
};
|
||||
|
||||
const step4 = botReducer(step3, networkUp("bot.mqtt"));
|
||||
expect(step4.hardware.informational_settings.sync_status)
|
||||
.toBe(step3.statusStash);
|
||||
const step2 = go("down", step1);
|
||||
expect(step2.statusStash).toBe(statusOf(step1));
|
||||
expect(statusOf(step2)).toBeUndefined();
|
||||
|
||||
const step3 = go("down", step2);
|
||||
expect(step3.statusStash).toBe(statusOf(step1));
|
||||
expect(statusOf(step3)).toBeUndefined();
|
||||
|
||||
const step4 = go("up", step3);
|
||||
expect(statusOf(step4)).toBe(step3.statusStash);
|
||||
});
|
||||
|
||||
it("handles STASH_STATUS / _RESOURCE_NO", () => {
|
||||
|
@ -131,11 +142,9 @@ describe("botReducer", () => {
|
|||
step1.statusStash = "booting";
|
||||
step1.hardware.informational_settings.sync_status = "synced";
|
||||
const step2 = botReducer(step1, stash());
|
||||
expect(step2.statusStash)
|
||||
.toBe(step1.hardware.informational_settings.sync_status);
|
||||
expect(step2.statusStash).toBe(statusOf(step1));
|
||||
const no = { type: Actions._RESOURCE_NO, payload: undefined };
|
||||
const step3 = botReducer(step2, no);
|
||||
expect(step3.hardware.informational_settings.sync_status)
|
||||
.toBe(step3.statusStash);
|
||||
expect(statusOf(step3)).toBe(step3.statusStash);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -34,9 +34,10 @@ export const FEATURE_MIN_VERSIONS_URL =
|
|||
// Already filtering messages in FarmBot OS and the API- this is just for
|
||||
// an additional layer of safety.
|
||||
const BAD_WORDS = ["WPA", "PSK", "PASSWORD", "NERVES"];
|
||||
const MESSAGE: keyof Log = "message";
|
||||
|
||||
export function isLog(x: unknown): x is Log {
|
||||
const msg = get(x, "message" as keyof Log);
|
||||
const msg = get(x, MESSAGE);
|
||||
const yup = isObject(x) && isString(msg);
|
||||
if (yup) {
|
||||
if (oneOf(BAD_WORDS, msg.toUpperCase())) { // SECURITY CRITICAL CODE.
|
||||
|
|
|
@ -5,9 +5,8 @@ import {
|
|||
import { generateReducer } from "../redux/generate_reducer";
|
||||
import { Actions } from "../constants";
|
||||
import { maybeNegateStatus } from "../connectivity/maybe_negate_status";
|
||||
import { EdgeStatus } from "../connectivity/interfaces";
|
||||
import { ReduxAction } from "../redux/interfaces";
|
||||
import { connectivityReducer } from "../connectivity/reducer";
|
||||
import { connectivityReducer, PingResultPayload } from "../connectivity/reducer";
|
||||
import { versionOK } from "../util";
|
||||
import { EXPECTED_MAJOR, EXPECTED_MINOR } from "./actions";
|
||||
import { DeepPartial } from "redux";
|
||||
|
@ -147,19 +146,16 @@ export let botReducer = generateReducer<BotState>(initialState())
|
|||
unstash(s);
|
||||
return s;
|
||||
})
|
||||
.add<EdgeStatus>(Actions.NETWORK_EDGE_CHANGE, (s, a) => {
|
||||
const { name, status } = a.payload;
|
||||
switch ((name === "bot.mqtt") && status.state) {
|
||||
case "down":
|
||||
stash(s);
|
||||
s.hardware.informational_settings.sync_status = undefined;
|
||||
break;
|
||||
case "up":
|
||||
const currentState = s.connectivity.uptime["bot.mqtt"];
|
||||
// Going from "down" to "up"
|
||||
const backOnline = currentState && currentState.state === "down";
|
||||
backOnline && unstash(s);
|
||||
}
|
||||
.add<PingResultPayload>(Actions.PING_OK, (s) => {
|
||||
// Going from "down" to "up"
|
||||
const currentState = s.connectivity.uptime["bot.mqtt"];
|
||||
const backOnline = currentState && currentState.state === "down";
|
||||
backOnline && unstash(s);
|
||||
return s;
|
||||
})
|
||||
.add<PingResultPayload>(Actions.PING_NO, (s) => {
|
||||
stash(s);
|
||||
s.hardware.informational_settings.sync_status = undefined;
|
||||
return s;
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue