|
4 | 4 |
|
5 | 5 | RSpec.describe 'Updating a project', type: :request do
|
6 | 6 | let(:headers) { { Authorization: UserProfileMock::TOKEN } }
|
7 |
| - let!(:project) { create(:project, name: 'Test Project', user_id: owner.id) } |
| 7 | + let(:locale) { 'en' } |
| 8 | + let!(:project) { create(:project, name: 'Test Project', user_id: owner.id, locale:) } |
8 | 9 | let(:owner) { create(:owner, school:) }
|
9 | 10 | let(:school) { create(:school) }
|
10 | 11 |
|
|
26 | 27 | end
|
27 | 28 |
|
28 | 29 | it 'responds 200 OK' do
|
29 |
| - put("/api/projects/#{project.id}", headers:, params:) |
| 30 | + put("/api/projects/#{project.identifier}", headers:, params:) |
30 | 31 | expect(response).to have_http_status(:ok)
|
31 | 32 | end
|
32 | 33 |
|
33 | 34 | it 'responds with the project JSON' do
|
34 |
| - put("/api/projects/#{project.id}", headers:, params:) |
| 35 | + put("/api/projects/#{project.identifier}", headers:, params:) |
35 | 36 | data = JSON.parse(response.body, symbolize_names: true)
|
36 | 37 |
|
37 | 38 | expect(data[:name]).to eq('New Name')
|
38 | 39 | end
|
39 | 40 |
|
40 | 41 | it 'responds with the components JSON' do
|
41 |
| - put("/api/projects/#{project.id}", headers:, params:) |
| 42 | + put("/api/projects/#{project.identifier}", headers:, params:) |
42 | 43 | data = JSON.parse(response.body, symbolize_names: true)
|
43 | 44 |
|
44 | 45 | expect(data[:components].first[:content]).to eq('print("hello")')
|
45 | 46 | end
|
46 | 47 |
|
47 | 48 | it 'responds 422 Unprocessable Entity when params are invalid' do
|
48 |
| - put("/api/projects/#{project.id}", headers:, params: { project: { components: [{ name: ' ' }] } }) |
| 49 | + put("/api/projects/#{project.identifier}", headers:, params: { project: { components: [{ name: ' ' }] } }) |
49 | 50 | expect(response).to have_http_status(:unprocessable_entity)
|
50 | 51 | end
|
51 | 52 |
|
52 | 53 | it 'responds 401 Unauthorized when no token is given' do
|
53 |
| - put("/api/projects/#{project.id}", params:) |
| 54 | + put("/api/projects/#{project.identifier}", params:) |
54 | 55 | expect(response).to have_http_status(:unauthorized)
|
55 | 56 | end
|
| 57 | + |
| 58 | + context 'when locale is nil, i.e. the other fallback locale in ProjectLoader' do |
| 59 | + let(:locale) { nil } |
| 60 | + |
| 61 | + it 'responds 200 OK even though no locale is specified in query string' do |
| 62 | + put("/api/projects/#{project.identifier}", headers:, params:) |
| 63 | + expect(response).to have_http_status(:ok) |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + context "when locale is 'fr', i.e. not a fallback locale in ProjectLoader" do |
| 68 | + let(:locale) { 'fr' } |
| 69 | + |
| 70 | + it 'responds 200 OK if locale is specified in query string' do |
| 71 | + put("/api/projects/#{project.identifier}?locale=fr", headers:, params:) |
| 72 | + expect(response).to have_http_status(:ok) |
| 73 | + end |
| 74 | + |
| 75 | + it 'responds 404 Not Found if locale is not specified in query string' do |
| 76 | + put("/api/projects/#{project.identifier}", headers:, params:) |
| 77 | + expect(response).to have_http_status(:not_found) |
| 78 | + end |
| 79 | + end |
56 | 80 | end
|
0 commit comments