From c2f8447f49c3864b433262b59ce8d2a222d9b842 Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Thu, 7 Mar 2024 14:00:57 +0100 Subject: [PATCH] group notifications in device response json --- app/views/v0/devices/_device.jbuilder | 7 +++++-- spec/requests/v0/devices_spec.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/v0/devices/_device.jbuilder b/app/views/v0/devices/_device.jbuilder index 60435a37..71f6e617 100644 --- a/app/views/v0/devices/_device.jbuilder +++ b/app/views/v0/devices/_device.jbuilder @@ -15,13 +15,16 @@ json.( :system_tags, :user_tags, :is_private, - :notify_low_battery, - :notify_stopped_publishing, :last_reading_at, :created_at, :updated_at ) + json.merge!(notify: { + stopped_publishing: device.notify_stopped_publishing, + low_battery: device.notify_low_battery + }) + authorized = !local_assigns[:never_authorized] && current_user && (current_user.is_admin? || (device.owner_id && current_user.id == device.owner_id)) if authorized diff --git a/spec/requests/v0/devices_spec.rb b/spec/requests/v0/devices_spec.rb index ab9f4e06..4677b1ff 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 is_private notify_low_battery notify_stopped_publishing last_reading_at created_at updated_at device_token postprocessing location hardware owner data)) + expect(json[0].keys).to eq(%w(id uuid name description state system_tags user_tags is_private last_reading_at created_at updated_at notify device_token postprocessing location hardware owner data)) end describe "when not logged in" do