Skip to content

Commit

Permalink
group notifications in device response json
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Mar 7, 2024
1 parent a9dafce commit c2f8447
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/views/v0/devices/_device.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 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
Expand Down

0 comments on commit c2f8447

Please sign in to comment.