2019-02-13 09:04:15 -07:00
|
|
|
require "spec_helper"
|
2019-01-02 09:35:08 -07:00
|
|
|
|
|
|
|
describe FbosConfig do
|
2019-02-13 09:04:15 -07:00
|
|
|
let(:device) { FactoryBot.create(:device) }
|
|
|
|
let(:config) { FbosConfig.create!(device: device) }
|
2019-01-03 14:49:40 -07:00
|
|
|
|
2019-02-13 09:04:15 -07:00
|
|
|
def fake_conn(desc)
|
|
|
|
double(desc, :ca_file= => nil,
|
|
|
|
:cert_store => nil,
|
|
|
|
:cert_store= => nil,
|
|
|
|
:use_ssl => nil,
|
|
|
|
:use_ssl= => nil,
|
|
|
|
:cert= => nil,
|
|
|
|
:key= => nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "notifies us of broken production data" do
|
|
|
|
# Remove this test by May 2019.
|
|
|
|
config.device.update_attributes!(serial_number: nil)
|
|
|
|
conn = fake_conn("Report broke data")
|
|
|
|
NervesHub.set_conn(conn)
|
|
|
|
problem = "Device #{device.id} missing serial"
|
|
|
|
expect(NervesHub).to receive(:report_problem).with({ problem: problem })
|
|
|
|
config.sync_nerves
|
|
|
|
end
|
|
|
|
|
|
|
|
it "triggers callbacks" do
|
|
|
|
conn = fake_conn("Create a cert")
|
2019-01-03 15:48:57 -07:00
|
|
|
NervesHub.set_conn(conn)
|
2019-01-04 07:18:02 -07:00
|
|
|
url = "/orgs/farmbot/devices/#{device.serial_number}"
|
|
|
|
resp = StubResp.new("200", { "data" => { "tags": [] } }.to_json)
|
|
|
|
resp2 = StubResp.new("201", { "data" => { "tags": [] } }.to_json)
|
|
|
|
params = [ url,
|
|
|
|
{"tags": ["channel:beta"]}.to_json,
|
|
|
|
{"Content-Type"=>"application/json"} ]
|
|
|
|
expect(NervesHub.conn).to(receive(:get).with(url).and_return(resp))
|
|
|
|
expect(NervesHub.conn).to(receive(:put).with(*params).and_return(resp2))
|
2019-01-03 15:48:57 -07:00
|
|
|
|
2019-01-03 10:41:52 -07:00
|
|
|
run_jobs_now do
|
2019-01-04 07:18:02 -07:00
|
|
|
config.update_attributes!(update_channel: "beta")
|
2019-01-03 10:41:52 -07:00
|
|
|
end
|
2019-01-02 09:35:08 -07:00
|
|
|
end
|
|
|
|
end
|