Skip to content

Commit

Permalink
expose first_reading_at in the api
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Nov 14, 2024
1 parent 6609a57 commit 3a91061
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/lib/presenters/device_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def default_options
end

def exposed_fields
%i{id uuid name description state system_tags user_tags last_reading_at created_at updated_at notify device_token mac_address postprocessing location data_policy hardware owner components}
%i{id uuid name description state system_tags user_tags first_reading_at last_reading_at created_at updated_at notify device_token mac_address postprocessing location data_policy hardware owner components}
end

def notify
Expand Down
1 change: 1 addition & 0 deletions app/views/v0/devices/_device.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ json.(
:state,
:system_tags,
:user_tags,
:first_reading_at,
:last_reading_at,
:created_at,
:updated_at
Expand Down
4 changes: 4 additions & 0 deletions spec/presenters/device_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
expect(presenter.as_json[:user_tags]).to eq(device.user_tags)
end

it "exposes the first_reading_at date" do
expect(presenter.as_json[:first_reading_at]).to eq(device.first_reading_at)
end

it "exposes the last_reading_at date" do
expect(presenter.as_json[:last_reading_at]).to eq(device.last_reading_at)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/v0/devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expect(json.length).to eq(2)
# expect(json[0]['name']).to eq(first.name)
# expect(json[1]['name']).to eq(second.name)
expect(json[0].keys).to eq(%w(id uuid name description state system_tags user_tags last_reading_at created_at updated_at notify device_token postprocessing location data_policy hardware owner data experiment_ids))
expect(json[0].keys).to eq(%w(id uuid name description state system_tags user_tags first_reading_at last_reading_at created_at updated_at notify device_token postprocessing location data_policy hardware owner data experiment_ids))
end

describe "when not logged in" do
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/v1/devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
expect(json.length).to eq(2)
# expect(json[0]['name']).to eq(first.name)
# expect(json[1]['name']).to eq(second.name)
expect(json[0].keys).to eq(%w(id uuid name description state system_tags user_tags last_reading_at created_at updated_at notify device_token postprocessing location data_policy hardware owner data experiment_ids))
expect(json[0].keys).to eq(%w(id uuid name description state system_tags user_tags first_reading_at last_reading_at created_at updated_at notify device_token postprocessing location data_policy hardware owner data experiment_ids))
end

describe "when not logged in" do
Expand Down

0 comments on commit 3a91061

Please sign in to comment.