Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

add spec ensuring roles to exist on membership creation via api

ulfertsf18e484e9789
diff --git a/spec/requests/api/v3/membership_resources_spec.rb b/spec/requests/api/v3/membership_resources_spec.rb
index 872dcf4c5a4..3d3fc8bca84 100644
--- a/spec/requests/api/v3/membership_resources_spec.rb
+++ b/spec/requests/api/v3/membership_resources_spec.rb
@@ -403,6 +403,28 @@ describe 'API v3 memberhips resource', type: :request, content_type: :json do
end
end
+ context 'if providing no roles' do
+ let(:body) do
+ {
+ project: {
+ href: api_v3_paths.project(project.id)
+ },
+ principal: {
+ href: principal_path
+ },
+ roles: []
+ }.to_json
+ end
+
+ it 'responds with 422 and explains the error' do
+ expect(last_response.status).to eq(422)
+
+ expect(last_response.body)
+ .to be_json_eql("Roles need to be assigned.".to_json)
+ .at_path('message')
+ end
+ end
+
context 'if lacking the manage permissions' do
let(:permissions) { [:view_members] }