Commit 15460d11 authored by nicolasdular's avatar nicolasdular Committed by Douglas Barbosa Alexandre

Add broadcast type to API

Adds the recently introduced broadcast_type to the API since
we will also remove the feature flag.
parent d4337590
---
title: Add broadcast type to API
merge_request:
author:
type: changed
...@@ -35,7 +35,8 @@ Example response: ...@@ -35,7 +35,8 @@ Example response:
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active": false, "active": false,
"target_path": "*/welcome" "target_path": "*/welcome",
"broadcast_type": "banner"
} }
] ]
``` ```
...@@ -71,7 +72,8 @@ Example response: ...@@ -71,7 +72,8 @@ Example response:
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active":false, "active":false,
"target_path": "*/welcome" "target_path": "*/welcome",
"broadcast_type": "banner"
} }
``` ```
...@@ -92,6 +94,8 @@ Parameters: ...@@ -92,6 +94,8 @@ Parameters:
| `ends_at` | datetime | no | Ending time (defaults to one hour from current time). | | `ends_at` | datetime | no | Ending time (defaults to one hour from current time). |
| `color` | string | no | Background color hex code. | | `color` | string | no | Background color hex code. |
| `font` | string | no | Foreground color hex code. | | `font` | string | no | Foreground color hex code. |
| `target_path`| string | no | Target path of the broadcast message. |
| `broadcast_type`| string | no | Appearance type (defaults to banner) |
Example request: Example request:
...@@ -110,7 +114,8 @@ Example response: ...@@ -110,7 +114,8 @@ Example response:
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active": true, "active": true,
"target_path": "*/welcome" "target_path": "*/welcome",
"broadcast_type": "notification",
} }
``` ```
...@@ -132,6 +137,8 @@ Parameters: ...@@ -132,6 +137,8 @@ Parameters:
| `ends_at` | datetime | no | Ending time. | | `ends_at` | datetime | no | Ending time. |
| `color` | string | no | Background color hex code. | | `color` | string | no | Background color hex code. |
| `font` | string | no | Foreground color hex code. | | `font` | string | no | Foreground color hex code. |
| `target_path`| string | no | Target path of the broadcast message. |
| `broadcast_type`| string | no | Appearance type (defaults to banner) |
Example request: Example request:
...@@ -150,7 +157,8 @@ Example response: ...@@ -150,7 +157,8 @@ Example response:
"font":"#FFFFFF", "font":"#FFFFFF",
"id":1, "id":1,
"active": true, "active": true,
"target_path": "*/welcome" "target_path": "*/welcome",
"broadcast_type": "notification",
} }
``` ```
......
...@@ -35,6 +35,7 @@ module API ...@@ -35,6 +35,7 @@ module API
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' optional :target_path, type: String, desc: 'Target path'
optional :broadcast_type, type: String, values: BroadcastMessage.broadcast_types.keys, desc: 'Broadcast type. Defaults to banner', default: -> { 'banner' }
end end
post do post do
authenticated_as_admin! authenticated_as_admin!
...@@ -73,6 +74,7 @@ module API ...@@ -73,6 +74,7 @@ module API
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' optional :target_path, type: String, desc: 'Target path'
optional :broadcast_type, type: String, values: BroadcastMessage.broadcast_types.keys, desc: 'Broadcast Type'
end end
put ':id' do put ':id' do
authenticated_as_admin! authenticated_as_admin!
......
...@@ -932,7 +932,7 @@ module API ...@@ -932,7 +932,7 @@ module API
end end
class BroadcastMessage < Grape::Entity class BroadcastMessage < Grape::Entity
expose :message, :starts_at, :ends_at, :color, :font, :target_path expose :message, :starts_at, :ends_at, :color, :font, :target_path, :broadcast_type
end end
class ApplicationStatistics < Grape::Entity class ApplicationStatistics < Grape::Entity
......
...@@ -17,7 +17,7 @@ describe API::BroadcastMessages do ...@@ -17,7 +17,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 target_path)) .to match_array(%w(id message starts_at ends_at color font active target_path broadcast_type))
end end
end end
...@@ -28,7 +28,7 @@ describe API::BroadcastMessages do ...@@ -28,7 +28,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 target_path)) .to match_array(%w(id message starts_at ends_at color font active target_path broadcast_type))
end end
end end
...@@ -85,6 +85,32 @@ describe API::BroadcastMessages do ...@@ -85,6 +85,32 @@ describe API::BroadcastMessages do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['target_path']).to eq attrs[:target_path] expect(json_response['target_path']).to eq attrs[:target_path]
end end
it 'accepts a broadcast type' do
attrs = attributes_for(:broadcast_message, broadcast_type: 'notification')
post api('/broadcast_messages', admin), params: attrs
expect(response).to have_gitlab_http_status(201)
expect(json_response['broadcast_type']).to eq attrs[:broadcast_type]
end
it 'uses default broadcast type' do
attrs = attributes_for(:broadcast_message)
post api('/broadcast_messages', admin), params: attrs
expect(response).to have_gitlab_http_status(201)
expect(json_response['broadcast_type']).to eq 'banner'
end
it 'errors for invalid broadcast type' do
attrs = attributes_for(:broadcast_message, broadcast_type: 'invalid-type')
post api('/broadcast_messages', admin), params: attrs
expect(response).to have_gitlab_http_status(400)
end
end end
end end
...@@ -144,6 +170,23 @@ describe API::BroadcastMessages do ...@@ -144,6 +170,23 @@ describe API::BroadcastMessages do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['target_path']).to eq attrs[:target_path] expect(json_response['target_path']).to eq attrs[:target_path]
end end
it 'accepts a new broadcast_type' do
attrs = { broadcast_type: 'notification' }
put api("/broadcast_messages/#{message.id}", admin), params: attrs
expect(response).to have_gitlab_http_status(200)
expect(json_response['broadcast_type']).to eq attrs[:broadcast_type]
end
it 'errors for invalid broadcast type' do
attrs = { broadcast_type: 'invalid-type' }
put api("/broadcast_messages/#{message.id}", admin), params: attrs
expect(response).to have_gitlab_http_status(400)
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