|
6 | 6 | let(:headers) { { Authorization: UserProfileMock::TOKEN } }
|
7 | 7 | let(:project_type) { Project::Types::PYTHON }
|
8 | 8 | let(:user_id) { owner.id }
|
9 |
| - let!(:project) { create(:project, name: 'Test Project', user_id:, locale: 'en', project_type:) } |
| 9 | + let(:locale) { 'en' } |
| 10 | + let!(:project) { create(:project, name: 'Test Project', user_id:, locale:, project_type:) } |
10 | 11 | let(:owner) { create(:owner, school:) }
|
11 | 12 | let(:school) { create(:school) }
|
12 | 13 |
|
|
28 | 29 | end
|
29 | 30 |
|
30 | 31 | it 'responds 200 OK' do
|
31 |
| - put("/api/projects/#{project.id}", headers:, params:) |
| 32 | + put("/api/projects/#{project.identifier}", headers:, params:) |
32 | 33 | expect(response).to have_http_status(:ok)
|
33 | 34 | end
|
34 | 35 |
|
35 | 36 | it 'responds with the project JSON' do
|
36 |
| - put("/api/projects/#{project.id}", headers:, params:) |
| 37 | + put("/api/projects/#{project.identifier}", headers:, params:) |
37 | 38 | data = JSON.parse(response.body, symbolize_names: true)
|
38 | 39 |
|
39 | 40 | expect(data[:name]).to eq('New Name')
|
40 | 41 | end
|
41 | 42 |
|
42 | 43 | it 'responds with the components JSON' do
|
43 |
| - put("/api/projects/#{project.id}", headers:, params:) |
| 44 | + put("/api/projects/#{project.identifier}", headers:, params:) |
44 | 45 | data = JSON.parse(response.body, symbolize_names: true)
|
45 | 46 |
|
46 | 47 | expect(data[:components].first[:content]).to eq('print("hello")')
|
47 | 48 | end
|
48 | 49 |
|
49 | 50 | it 'responds 422 Unprocessable Entity when params are invalid' do
|
50 |
| - put("/api/projects/#{project.id}", headers:, params: { project: { components: [{ name: ' ' }] } }) |
| 51 | + put("/api/projects/#{project.identifier}", headers:, params: { project: { components: [{ name: ' ' }] } }) |
51 | 52 | expect(response).to have_http_status(:unprocessable_entity)
|
52 | 53 | end
|
53 | 54 |
|
54 | 55 | it 'responds 401 Unauthorized when no token is given' do
|
55 |
| - put("/api/projects/#{project.id}", params:) |
| 56 | + put("/api/projects/#{project.identifier}", params:) |
56 | 57 | expect(response).to have_http_status(:unauthorized)
|
57 | 58 | end
|
58 | 59 |
|
|
78 | 79 | expect(data[:name]).to eq('Test Project')
|
79 | 80 | end
|
80 | 81 | end
|
| 82 | + |
| 83 | + context 'when locale is nil, i.e. the other fallback locale in ProjectLoader' do |
| 84 | + let(:locale) { nil } |
| 85 | + |
| 86 | + it 'responds 200 OK even though no locale is specified in query string' do |
| 87 | + put("/api/projects/#{project.identifier}", headers:, params:) |
| 88 | + expect(response).to have_http_status(:ok) |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + context "when locale is 'fr', i.e. not a fallback locale in ProjectLoader" do |
| 93 | + let(:locale) { 'fr' } |
| 94 | + |
| 95 | + it 'responds 200 OK if locale is specified in query string' do |
| 96 | + put("/api/projects/#{project.identifier}?locale=fr", headers:, params:) |
| 97 | + expect(response).to have_http_status(:ok) |
| 98 | + end |
| 99 | + |
| 100 | + it 'responds 404 Not Found if locale is not specified in query string' do |
| 101 | + put("/api/projects/#{project.identifier}", headers:, params:) |
| 102 | + expect(response).to have_http_status(:not_found) |
| 103 | + end |
| 104 | + end |
81 | 105 | end
|
0 commit comments