Remove debug points

pull/577/head
Rick Carlino 2017-12-14 09:44:46 -06:00
parent 5c56635e50
commit 3db1e2e40b
2 changed files with 19 additions and 18 deletions

View File

@ -30,12 +30,13 @@ import {
onOffline,
changeLastClientConnected,
onSent,
onOnline
onOnline,
onMalformed
} from "../../connect_device";
import { Actions, Content } from "../../../constants";
import { Log } from "../../../interfaces";
import { ALLOWED_CHANNEL_NAMES, ALLOWED_MESSAGE_TYPES, Farmbot } from "farmbot";
import { success, error, info } from "farmbot-toastr";
import { success, error, info, warning } from "farmbot-toastr";
import { dispatchNetworkUp, dispatchNetworkDown } from "../../index";
import { getDevice } from "../../../device";
@ -161,9 +162,23 @@ describe("onSent", () => {
onSent({ connected: true })();
expect(dispatchNetworkUp).toHaveBeenCalledWith("user.mqtt");
});
it("marks MQTT as down", () => {
jest.resetAllMocks();
onSent({ connected: false })();
expect(dispatchNetworkDown).toHaveBeenCalledWith("user.mqtt");
});
});
describe("onMalformed()", () => {
it("handles malformed messages", () => {
onMalformed();
expect(warning)
.toHaveBeenCalledWith(Content.MALFORMED_MESSAGE_REC_UPGRADE);
jest.resetAllMocks();
onMalformed();
expect(warning) // Only fire once.
.not
.toHaveBeenCalledWith(Content.MALFORMED_MESSAGE_REC_UPGRADE);
});
});

View File

@ -25,7 +25,7 @@ export const TITLE = "New message from bot";
/** TODO: This ought to be stored in Redux. It is here because of historical
* reasons. Feel free to factor out when time allows. -RC, 10 OCT 17 */
const HACKY_FLAGS = {
export const HACKY_FLAGS = {
needVersionCheck: true,
alreadyToldUserAboutMalformedMsg: false
};
@ -128,7 +128,7 @@ const onLogs = (dispatch: Function) => (msg: Log) => {
}
};
function onMalformed() {
export function onMalformed() {
bothUp();
if (!HACKY_FLAGS.alreadyToldUserAboutMalformedMsg) {
warning(t(Content.MALFORMED_MESSAGE_REC_UPGRADE));
@ -140,20 +140,6 @@ export const onOnline = () => dispatchNetworkUp("user.mqtt");
const attachEventListeners =
(bot: Farmbot, dispatch: Function, getState: GetState) => {
const ev =
(e: string) =>
() => {
const m = `${e}: socket ${bot.client.connected ? "ON" : "OFF"}`;
info(m);
console.log(m);
};
bot.client.on("reconnect", ev("reconnect"));
bot.client.on("close", ev("close"));
bot.client.on("offline", ev("offline"));
bot.client.on("error", ev("error"));
bot.client.on("connect", ev("connect"));
bot.client.on("reconnect", ev("reconnect"));
bot.on("online", onOnline);
bot.on("offline", onOffline);
bot.on("sent", onSent(bot.client));