Commit 74289860 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'nicolasdular/add-broadcast-target-to-api' into 'master'

Add target_path to broadcast API

Closes gitlab-org/growth/engineering#2594

See merge request gitlab-org/gitlab!21430
parents b13cf622 a14bcdb2
---
title: Add target_path to broadcast message API
merge_request: 21430
author:
type: added
...@@ -34,7 +34,8 @@ Example response: ...@@ -34,7 +34,8 @@ Example response:
"color":"#E75E40", "color":"#E75E40",
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active": false "active": false,
"target_path": "*/welcome"
} }
] ]
``` ```
...@@ -69,7 +70,8 @@ Example response: ...@@ -69,7 +70,8 @@ Example response:
"color":"#cecece", "color":"#cecece",
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active":false "active":false,
"target_path": "*/welcome"
} }
``` ```
...@@ -107,7 +109,8 @@ Example response: ...@@ -107,7 +109,8 @@ Example response:
"color":"#cecece", "color":"#cecece",
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active": true "active": true,
"target_path": "*/welcome"
} }
``` ```
...@@ -146,7 +149,8 @@ Example response: ...@@ -146,7 +149,8 @@ Example response:
"color":"#000", "color":"#000",
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active": true "active": true,
"target_path": "*/welcome"
} }
``` ```
......
...@@ -37,6 +37,7 @@ module API ...@@ -37,6 +37,7 @@ module API
optional :ends_at, type: DateTime, desc: 'Ending time', default: -> { 1.hour.from_now } optional :ends_at, type: DateTime, desc: 'Ending time', default: -> { 1.hour.from_now }
optional :color, type: String, desc: 'Background color' optional :color, type: String, desc: 'Background color'
optional :font, type: String, desc: 'Foreground color' optional :font, type: String, desc: 'Foreground color'
optional :target_path, type: String, desc: 'Target path'
end end
post do post do
message = BroadcastMessage.create(declared_params(include_missing: false)) message = BroadcastMessage.create(declared_params(include_missing: false))
...@@ -72,6 +73,7 @@ module API ...@@ -72,6 +73,7 @@ module API
optional :ends_at, type: DateTime, desc: 'Ending time' optional :ends_at, type: DateTime, desc: 'Ending time'
optional :color, type: String, desc: 'Background color' optional :color, type: String, desc: 'Background color'
optional :font, type: String, desc: 'Foreground color' optional :font, type: String, desc: 'Foreground color'
optional :target_path, type: String, desc: 'Target path'
end end
put ':id' do put ':id' do
message = find_message message = find_message
......
...@@ -1217,7 +1217,7 @@ module API ...@@ -1217,7 +1217,7 @@ module API
end end
class BroadcastMessage < Grape::Entity class BroadcastMessage < Grape::Entity
expose :message, :starts_at, :ends_at, :color, :font expose :message, :starts_at, :ends_at, :color, :font, :target_path
end end
class ApplicationStatistics < Grape::Entity class ApplicationStatistics < Grape::Entity
......
...@@ -29,7 +29,7 @@ describe API::BroadcastMessages do ...@@ -29,7 +29,7 @@ describe API::BroadcastMessages do
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_kind_of(Array) expect(json_response).to be_kind_of(Array)
expect(json_response.first.keys) expect(json_response.first.keys)
.to match_array(%w(id message starts_at ends_at color font active)) .to match_array(%w(id message starts_at ends_at color font active target_path))
end end
end end
...@@ -52,7 +52,7 @@ describe API::BroadcastMessages do ...@@ -52,7 +52,7 @@ describe API::BroadcastMessages do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['id']).to eq message.id expect(json_response['id']).to eq message.id
expect(json_response.keys) expect(json_response.keys)
.to match_array(%w(id message starts_at ends_at color font active)) .to match_array(%w(id message starts_at ends_at color font active target_path))
end end
end end
...@@ -100,6 +100,15 @@ describe API::BroadcastMessages do ...@@ -100,6 +100,15 @@ describe API::BroadcastMessages do
expect(json_response['color']).to eq attrs[:color] expect(json_response['color']).to eq attrs[:color]
expect(json_response['font']).to eq attrs[:font] expect(json_response['font']).to eq attrs[:font]
end end
it 'accepts a target path' do
attrs = attributes_for(:broadcast_message, target_path: "*/welcome")
post api('/broadcast_messages', admin), params: attrs
expect(response).to have_gitlab_http_status(201)
expect(json_response['target_path']).to eq attrs[:target_path]
end
end end
end end
...@@ -150,6 +159,15 @@ describe API::BroadcastMessages do ...@@ -150,6 +159,15 @@ describe API::BroadcastMessages do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect { message.reload }.to change { message.message }.to('new message') expect { message.reload }.to change { message.message }.to('new message')
end end
it 'accepts a new target_path' do
attrs = { target_path: '*/welcome' }
put api("/broadcast_messages/#{message.id}", admin), params: attrs
expect(response).to have_gitlab_http_status(200)
expect(json_response['target_path']).to eq attrs[:target_path]
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment