|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +RSpec.describe 'Update public project requests' do |
| 6 | + let(:project) { create(:project) } |
| 7 | + let(:creator) { build(:user) } |
| 8 | + let(:params) { { project: { name: 'New name' } } } |
| 9 | + |
| 10 | + context 'when auth is correct' do |
| 11 | + let(:headers) { { Authorization: UserProfileMock::TOKEN } } |
| 12 | + |
| 13 | + context 'when updating project is successful' do |
| 14 | + before do |
| 15 | + authenticated_in_hydra_as(creator) |
| 16 | + |
| 17 | + response = OperationResponse.new |
| 18 | + response[:project] = project |
| 19 | + allow(PublicProject::Update).to receive(:call).and_return(response) |
| 20 | + end |
| 21 | + |
| 22 | + it 'returns success' do |
| 23 | + put("/api/public_projects/#{project.identifier}", headers:, params:) |
| 24 | + |
| 25 | + expect(response).to have_http_status(:success) |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + context 'when updating project fails' do |
| 30 | + before do |
| 31 | + authenticated_in_hydra_as(creator) |
| 32 | + |
| 33 | + response = OperationResponse.new |
| 34 | + response[:error] = 'Error updating project' |
| 35 | + allow(PublicProject::Update).to receive(:call).and_return(response) |
| 36 | + end |
| 37 | + |
| 38 | + it 'returns error' do |
| 39 | + put("/api/public_projects/#{project.identifier}", headers:, params:) |
| 40 | + |
| 41 | + expect(response).to have_http_status(:unprocessable_entity) |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'when no token is given' do |
| 47 | + it 'returns unauthorized' do |
| 48 | + put("/api/public_projects/#{project.identifier}", headers:, params:) |
| 49 | + |
| 50 | + expect(response).to have_http_status(:unauthorized) |
| 51 | + end |
| 52 | + end |
| 53 | +end |
0 commit comments