From 3a910619301a04436af08aa53c19be5e8bf394ef Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Thu, 14 Nov 2024 12:16:02 +0100 Subject: [PATCH] expose first_reading_at in the api --- app/lib/presenters/device_presenter.rb | 2 +- app/views/v0/devices/_device.jbuilder | 1 + spec/presenters/device_presenter_spec.rb | 4 ++++ spec/requests/v0/devices_spec.rb | 2 +- spec/requests/v1/devices_spec.rb | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/lib/presenters/device_presenter.rb b/app/lib/presenters/device_presenter.rb index 27565b53..01da9c2f 100644 --- a/app/lib/presenters/device_presenter.rb +++ b/app/lib/presenters/device_presenter.rb @@ -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 diff --git a/app/views/v0/devices/_device.jbuilder b/app/views/v0/devices/_device.jbuilder index ec9d72e4..28a3137b 100644 --- a/app/views/v0/devices/_device.jbuilder +++ b/app/views/v0/devices/_device.jbuilder @@ -12,6 +12,7 @@ json.( :state, :system_tags, :user_tags, + :first_reading_at, :last_reading_at, :created_at, :updated_at diff --git a/spec/presenters/device_presenter_spec.rb b/spec/presenters/device_presenter_spec.rb index 2a89ebc6..c4c1fc30 100644 --- a/spec/presenters/device_presenter_spec.rb +++ b/spec/presenters/device_presenter_spec.rb @@ -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 diff --git a/spec/requests/v0/devices_spec.rb b/spec/requests/v0/devices_spec.rb index 900be4e9..43e63d1f 100644 --- a/spec/requests/v0/devices_spec.rb +++ b/spec/requests/v0/devices_spec.rb @@ -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 diff --git a/spec/requests/v1/devices_spec.rb b/spec/requests/v1/devices_spec.rb index b782d580..40ee0fd6 100644 --- a/spec/requests/v1/devices_spec.rb +++ b/spec/requests/v1/devices_spec.rb @@ -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