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