DRY up Log::TYPES

pull/493/head
Rick Carlino 2017-10-10 16:30:02 -05:00
parent 3a95f86714
commit 89b7d989fd
4 changed files with 24 additions and 5 deletions

View File

@ -18,7 +18,7 @@ module CeleryScriptSettingsBag
RESOURCE_NAME = %w(images plants regimens peripherals
corpuses logs sequences farm_events
tool_slots tools points tokens users device)
ALLOWED_MESSAGE_TYPES = %w(success busy warn error info fun)
ALLOWED_MESSAGE_TYPES = %w(success busy warn error info fun debug)
ALLOWED_CHANNEL_NAMES = %w(ticker toast email)
ALLOWED_DATA_TYPES = %w(string integer)
ALLOWED_OPS = %w(< > is not is_undefined)

View File

@ -5,7 +5,7 @@ class Log < ApplicationRecord
# pagination, but could later on.
PAGE_SIZE = 25
# self.meta[:type] is used by the bot and the frontend as a sort of
TYPES = %w(success busy warn error info fun debug)
TYPES = CeleryScriptSettingsBag::ALLOWED_MESSAGE_TYPES
# The means by which the message will be sent. Ex: frontend toast notification
serialize :channels
belongs_to :device

View File

@ -9,6 +9,14 @@ jest.mock("../../index", () => ({
dispatchNetworkUp: jest.fn()
}));
const mockDevice = {
readStatus: jest.fn(() => Promise.resolve()),
};
jest.mock("../../../device", () => ({
getDevice: () => (mockDevice)
}));
import { HardwareState } from "../../../devices/interfaces";
import {
incomingStatus,
@ -16,13 +24,22 @@ import {
showLogOnScreen,
TITLE,
bothUp,
initLog
initLog,
readStatus
} from "../../connect_device";
import { Actions } from "../../../constants";
import { Log } from "../../../interfaces";
import { ALLOWED_CHANNEL_NAMES, ALLOWED_MESSAGE_TYPES } from "farmbot";
import { success, error, info } from "farmbot-toastr";
import { dispatchNetworkUp } from "../../index";
import { getDevice } from "../../../device";
describe("readStatus()", () => {
it("forces a read_status request to FarmBot", () => {
readStatus();
expect(getDevice().readStatus).toHaveBeenCalled();
});
});
describe("incomingStatus", () => {
it("creates an action", () => {

View File

@ -72,7 +72,7 @@ export const bothUp = () => {
dispatchNetworkUp("bot.mqtt");
};
function readStatus() {
export function readStatus() {
const noun = "'Read Status' command";
return getDevice()
.readStatus()
@ -107,7 +107,9 @@ const onStatus = (dispatch: Function, getState: GetState) =>
const onSent = (/** The MQTT Client Object (bot.client) */ client: {}) =>
(any: {}) => {
get(client, "connected", false) ?
const theValue = get(client, "connected", false);
console.log("VALUE IS: " + theValue);
theValue ?
dispatchNetworkUp("user.mqtt") : dispatchNetworkDown("user.mqtt");
};