PointGroup related additions

pull/1454/head
Rick Carlino 2019-09-23 18:34:37 -05:00
parent 1e267e751c
commit fa5f9ed1ff
7 changed files with 49 additions and 17 deletions

View File

@ -6,6 +6,10 @@ module Api
render json: your_point_groups
end
def show
render json: the_point_group
end
def create
mutate PointGroups::Create.run(raw_json, point_group_params)
end

View File

@ -2,22 +2,27 @@ module Devices
class Sync < Mutations::Command
SEL = "SELECT id, updated_at FROM"
WHERE = "WHERE device_id = "
WHERE2 = "devices WHERE id = "
def self.basic_query(plural_resource, where = WHERE)
[SEL, plural_resource, where].join(" ")
end
QUERIES = {
devices: [SEL, WHERE2].join(" "),
farm_events: [SEL, "farm_events", WHERE].join(" "),
farmware_envs: [SEL, "farmware_envs", WHERE].join(" "),
farmware_installations: [SEL, "farmware_installations", WHERE].join(" "),
peripherals: [SEL, "peripherals", WHERE].join(" "),
pin_bindings: [SEL, "pin_bindings", WHERE].join(" "),
points: [SEL, "points", WHERE].join(" "),
regimens: [SEL, "regimens", WHERE].join(" "),
sensor_readings: [SEL, "sensor_readings", WHERE].join(" "),
sensors: [SEL, "sensors", WHERE].join(" "),
sequences: [SEL, "sequences", WHERE].join(" "),
tools: [SEL, "tools", WHERE].join(" "),
fbos_configs: [SEL, "fbos_configs", WHERE].join(" "),
firmware_configs: [SEL, "firmware_configs", WHERE].join(" "),
devices: basic_query("devices", "WHERE id = "),
farm_events: basic_query("farm_events"),
farmware_envs: basic_query("farmware_envs"),
farmware_installations: basic_query("farmware_installations"),
peripherals: basic_query("peripherals"),
pin_bindings: basic_query("pin_bindings"),
points: basic_query("points"),
regimens: basic_query("regimens"),
sensor_readings: basic_query("sensor_readings"),
sensors: basic_query("sensors"),
sequences: basic_query("sequences"),
tools: basic_query("tools"),
fbos_configs: basic_query("fbos_configs"),
firmware_configs: basic_query("firmware_configs"),
point_groups: basic_query("point_groups"),
}
STUB_FARMWARES = Api::FirstPartyFarmwaresController::STUBS.values.map do |x|

View File

@ -18,7 +18,7 @@ FarmBot::Application.routes.draw do
peripherals: [:create, :destroy, :index, :show, :update],
pin_bindings: [:create, :destroy, :index, :show, :update],
plant_templates: [:create, :destroy, :index, :update],
point_groups: [:index, :create, :update, :destroy],
point_groups: [:index, :show, :create, :update, :destroy],
regimens: [:create, :destroy, :index, :show, :update],
sensor_readings: [:create, :destroy, :index, :show],
sensors: [:create, :destroy, :index, :show, :update],

View File

@ -28,6 +28,7 @@ describe Api::DevicesController do
FactoryBot.create(:sensor, device: device)
FactoryBot.create(:tool_slot, device: device)
FactoryBot.create(:tool, device: device)
FactoryBot.create(:point_group, device: device)
FakeSequence.create(device: device)
get :sync, params: {}, session: { format: :json }

View File

@ -0,0 +1,20 @@
require "spec_helper"
describe Api::PointGroupsController do
include Devise::Test::ControllerHelpers
let(:user) { FactoryBot.create(:user) }
let(:device) { user.device }
let(:old_point_ids) do rando_points end
it "shows a single point group" do
PointGroup.destroy_all
PointGroupItem.destroy_all
sign_in device.users.first
pg = PointGroups::Create
.run!(device: device, point_ids: [], name: "PointGroups#show test")
get :show, params: { id: pg.id }
expect(response.status).to eq(200)
expect(json.fetch(:name)).to eq pg.name
end
end

View File

@ -1,5 +1,6 @@
FactoryBot.define do
factory :point_group do
point_group_items
name { Faker::Games::Pokemon.name }
# point_group_items # TODO: Broke - RC 23 Sept 19
end
end

View File

@ -20,6 +20,7 @@ describe Devices::Sync do
:sensors,
:sequences,
:tools,
:point_groups,
])
it "is different this time!" do