Update test for devices#dump

pull/815/head
Rick Carlino 2018-04-28 10:08:01 -05:00
parent 7edd8a0755
commit 097f5b3ace
4 changed files with 11 additions and 13 deletions

View File

@ -25,9 +25,8 @@ module Api
end
def dump
raise "Need to write tests for this and `dump_status`"
Devices::Dump.run_by_id(current_device.id)
render json: {ok: "OK"}
Devices::Dump.delay.run_by_id(current_device.id)
render json: ""
end
def dump_status

View File

@ -19,8 +19,9 @@ module Devices
:users,
:webcam_feeds,
]
def self.run_by_id(id)
Devices::Dump.delay.run!(device_id: current_device)
Devices::Dump.run!(device_id: id)
end
required do
@ -29,7 +30,7 @@ module Devices
def execute
output = { device: device.body_as_json }
RESOURCES.eah do |name|
RESOURCES.each do |name|
model = device.send(name)
output[name] = \
model.try(:map) { |x| x.body_as_json } || x.body_as_json

View File

@ -52,7 +52,7 @@ FarmBot::Application.routes.draw do
# resources.
# Might be safe to remove now with the advent of TaggedResource.kind
get "/device/:id" => "devices#show", as: :get_device_redirect
get "/export_data" => "devices#dump", as: :dump_device
post "/export_data" => "devices#dump", as: :dump_device
get "/storage_auth" => "images#storage_auth", as: :storage_auth
patch "/device/:id" => "devices#update", as: :patch_device_redirect
patch "/users/:id" => "users#update", as: :patch_users_redirect

View File

@ -15,15 +15,13 @@ describe Api::DevicesController do
:webcam_feeds]
describe '#dump' do
it 'creates a backup of your account' do
# NOTE: As of 11 December 17, the dump endpoint is only for dev purposes.
# Not going to spend a bunch of time writing unit tests for this
# endpoint- just basic syntax checking.
it 'queues the creation of an account backup' do
sign_in user
get :dump, params: {}, session: { format: :json }
wow = double("WOW", run_by_id: nil)
expect(wow).to receive(:run_by_id)
expect(Devices::Dump).to receive(:delay).and_return(wow).once
post :dump, params: {}, session: { format: :json }
expect(response.status).to eq(200)
actual = json.keys
EXPECTED.map { |key| expect(actual).to include(key) }
end
end
end