Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
49 changed files
with
563 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- 8.9.4 | ||
- 8.11.3 | ||
cache: | ||
yarn: true | ||
directories: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Api | ||
class DiagnosticDumpsController < Api::AbstractController | ||
|
||
def index | ||
render json: diagnostic_dumps | ||
end | ||
|
||
def create | ||
Rollbar.info("Device #{current_device.id} created a diagnostic") | ||
mutate DiagnosticDumps::Create.run(raw_json, device: current_device) | ||
end | ||
|
||
def destroy | ||
diagnostic_dump.destroy! | ||
render json: "" | ||
end | ||
|
||
private | ||
|
||
def diagnostic_dumps | ||
current_device.diagnostic_dumps | ||
end | ||
|
||
def diagnostic_dump | ||
@diagnostic_dump ||= diagnostic_dumps.find(params[:id]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class DiagnosticDump < ApplicationRecord | ||
belongs_to :device | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module DiagnosticDumps | ||
class Create < Mutations::Command | ||
required do | ||
model :device, class: Device | ||
string :fbos_version | ||
string :fbos_commit | ||
string :firmware_commit | ||
string :network_interface | ||
string :fbos_dmesg_dump | ||
string :firmware_state | ||
end | ||
|
||
def execute | ||
DiagnosticDump | ||
.create!(device: device, | ||
ticket_identifier: rand(36**5).to_s(36), | ||
fbos_version: fbos_version, | ||
fbos_commit: fbos_commit, | ||
firmware_commit: firmware_commit, | ||
network_interface: network_interface, | ||
fbos_dmesg_dump: fbos_dmesg_dump, | ||
firmware_state: firmware_state,) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class DiagnosticDumpSerializer < ActiveModel::Serializer | ||
attributes :id, :device_id, :ticket_identifier, :fbos_commit, :fbos_version, | ||
:firmware_commit, :firmware_state, :network_interface, | ||
:fbos_dmesg_dump, :created_at, :updated_at | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateDiagnosticDumps < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :diagnostic_dumps do |t| | ||
t.references :device, foreign_key: true, null: false | ||
t.string :ticket_identifier, null: false, unique: true | ||
t.string :fbos_commit, null: false | ||
t.string :fbos_version, null: false | ||
t.string :firmware_commit, null: false | ||
t.string :firmware_state, null: false | ||
t.string :network_interface, null: false | ||
t.text :fbos_dmesg_dump, null: false | ||
t.timestamps | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
spec/controllers/api/diagnostic_dumps/diagnostic_dumps_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'spec_helper' | ||
|
||
describe Api::DiagnosticDumpsController do | ||
let(:device) { FactoryBot.create(:device) } | ||
let(:user) { FactoryBot.create(:user, device: device) } | ||
|
||
include Devise::Test::ControllerHelpers | ||
|
||
it 'lists all diagnostics' do | ||
sign_in user | ||
DiagnosticDump.destroy_all | ||
device_config = FactoryBot.create_list(:diagnostic_dump, 3, device: device) | ||
get :index | ||
expect(json.length).to eq(3) | ||
expect(json.pluck(:device_id).uniq).to eq([user.device.id]) | ||
end | ||
|
||
it 'creates a dump' do | ||
sign_in user | ||
DiagnosticDump.destroy_all | ||
b4 = DiagnosticDump.count | ||
input = { | ||
fbos_version: "123_fbos_version", | ||
fbos_commit: "123_fbos_commit", | ||
firmware_commit: "123_firmware_commit", | ||
network_interface: "123_network_interface", | ||
fbos_dmesg_dump: "123_fbos_dmesg_dump", | ||
firmware_state: "123_firmware_state", | ||
} | ||
post :create, body: input.to_json | ||
expect(response.status).to eq(200) | ||
expect(DiagnosticDump.count).to be > b4 | ||
expect(DiagnosticDump.last.device).to eq(device) | ||
expect(json[:fbos_version]).to eq("123_fbos_version") | ||
expect(json[:fbos_commit]).to eq("123_fbos_commit") | ||
expect(json[:firmware_commit]).to eq("123_firmware_commit") | ||
expect(json[:network_interface]).to eq("123_network_interface") | ||
expect(json[:fbos_dmesg_dump]).to eq("123_fbos_dmesg_dump") | ||
expect(json[:firmware_state]).to eq("123_firmware_state") | ||
expect(json[:ticket_identifier].length).to eq(5) | ||
end | ||
|
||
it 'deletes' do | ||
sign_in user | ||
# DiagnosticDump.destroy_all | ||
device_config = FactoryBot.create(:diagnostic_dump, device: device) | ||
id = device_config.id | ||
delete :destroy, params: { id: device_config.id } | ||
expect(response.status).to be(200) | ||
expect(DiagnosticDump.exists?(id)).to be false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FactoryBot.define do | ||
factory :diagnostic_dump do | ||
device | ||
fbos_version "123_fbos_version" | ||
fbos_commit "123_fbos_commit" | ||
firmware_commit "123_firmware_commit" | ||
network_interface "123_network_interface" | ||
fbos_dmesg_dump "123_fbos_dmesg_dump" | ||
firmware_state "123_firmware_state" | ||
ticket_identifier { rand(36**5).to_s(36) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.