|
9 | 9 | let(:filename) { "#{basename}.#{format}" } |
10 | 10 | let(:school) { create(:school) } |
11 | 11 | let(:teacher) { create(:teacher, school:) } |
12 | | - let(:cookie_headers) { { 'Cookie' => "scratch_auth=#{UserProfileMock::TOKEN}" } } |
| 12 | + let(:auth_headers) { { 'Authorization' => UserProfileMock::TOKEN } } |
13 | 13 |
|
14 | 14 | describe 'GET #show' do |
15 | 15 | context 'when the asset is PNG' do |
16 | 16 | before do |
17 | 17 | create(:scratch_asset, :with_file, filename:, asset_path: file_fixture(filename)) |
18 | 18 | end |
19 | 19 |
|
20 | | - let(:make_request) { get '/api/scratch/assets/internalapi/asset/test_image_1.png/get/' } |
21 | | - |
22 | 20 | it 'serves the file with png content type' do |
23 | | - make_request |
| 21 | + get '/api/scratch/assets/internalapi/asset/test_image_1.png/get/' |
24 | 22 |
|
25 | 23 | follow_redirect! while response.redirect? |
26 | 24 |
|
|
33 | 31 | create(:scratch_asset, :with_file, filename: svg_filename, asset_path: file_fixture(svg_filename)) |
34 | 32 | end |
35 | 33 |
|
36 | | - let(:make_request) { get '/api/scratch/assets/internalapi/asset/test_svg_image.svg/get/' } |
37 | | - |
38 | 34 | it 'serves the file with image/svg+xml content type' do |
39 | | - make_request |
| 35 | + get '/api/scratch/assets/internalapi/asset/test_svg_image.svg/get/' |
40 | 36 |
|
41 | 37 | follow_redirect! while response.redirect? |
42 | 38 |
|
|
48 | 44 | describe 'POST #create' do |
49 | 45 | let(:upload) { File.binread(file_fixture(filename)) } |
50 | 46 | let(:make_request) do |
51 | | - post '/api/scratch/assets/test_image_1.png', headers: { 'Content-Type' => 'application/octet-stream' }.merge(cookie_headers), params: upload |
| 47 | + post '/api/scratch/assets/test_image_1.png', headers: { 'Content-Type' => 'application/octet-stream' }.merge(auth_headers), params: upload |
52 | 48 | end |
53 | 49 |
|
54 | 50 | context 'when user is logged in and cat_mode is enabled' do |
|
59 | 55 | end |
60 | 56 |
|
61 | 57 | it 'creates a new asset' do |
62 | | - # Arrange |
63 | 58 | Flipper.enable_actor :cat_mode, school |
64 | 59 |
|
65 | | - # Act & Assert |
66 | 60 | expect { make_request }.to change(ScratchAsset, :count).by(1) |
67 | 61 | end |
68 | 62 |
|
69 | 63 | it 'sets the filename on the asset' do |
70 | | - # Arrange |
71 | 64 | Flipper.enable_actor :cat_mode, school |
72 | 65 |
|
73 | | - # Act & Assert |
74 | 66 | make_request |
75 | 67 | expect(ScratchAsset.last.filename).to eq(filename) |
76 | 68 | end |
77 | 69 |
|
78 | 70 | it 'attaches the uploaded file to the asset' do |
79 | | - # Arrange |
80 | 71 | Flipper.enable_actor :cat_mode, school |
81 | 72 |
|
82 | | - # Act & Assert |
83 | 73 | make_request |
84 | 74 | expect(ScratchAsset.last.file).to be_attached |
85 | 75 | end |
86 | 76 |
|
87 | 77 | it 'stores the content of the file in the attachment' do |
88 | | - # Arrange |
89 | 78 | Flipper.enable_actor :cat_mode, school |
90 | 79 |
|
91 | | - # Act & Assert |
92 | 80 | make_request |
93 | 81 | expect(ScratchAsset.last.file.download).to eq(upload) |
94 | 82 | end |
95 | 83 |
|
96 | 84 | it 'responds with 201 Created' do |
97 | | - # Arrange |
98 | 85 | Flipper.enable_actor :cat_mode, school |
99 | 86 |
|
100 | | - # Act & Assert |
101 | 87 | make_request |
102 | 88 | expect(response).to have_http_status(:created) |
103 | 89 | end |
104 | 90 |
|
105 | 91 | it 'includes the status and filename (without extension) in the response' do |
106 | | - # Arrange |
107 | 92 | Flipper.enable_actor :cat_mode, school |
108 | 93 |
|
109 | | - # Act & Assert |
110 | 94 | make_request |
111 | 95 | expect(response.parsed_body).to include( |
112 | 96 | 'status' => 'ok', |
|
124 | 108 | end |
125 | 109 |
|
126 | 110 | it 'does not update the content of the file in the attachment' do |
127 | | - # Arrange |
128 | 111 | Flipper.enable_actor :cat_mode, school |
129 | 112 |
|
130 | | - # Act & Assert |
131 | 113 | make_request |
132 | 114 | expect(ScratchAsset.last.file.download).to eq(original_upload) |
133 | 115 | end |
134 | 116 |
|
135 | 117 | it 'responds with 201 Created' do |
136 | | - # Arrange |
137 | 118 | Flipper.enable_actor :cat_mode, school |
138 | 119 |
|
139 | | - # Act & Assert |
140 | 120 | make_request |
141 | 121 | expect(response).to have_http_status(:created) |
142 | 122 | end |
143 | 123 |
|
144 | 124 | it 'includes the status and filename (without extension) in the response' do |
145 | | - # Arrange |
146 | 125 | Flipper.enable_actor :cat_mode, school |
147 | 126 |
|
148 | | - # Act & Assert |
149 | 127 | make_request |
150 | 128 | expect(response.parsed_body).to include( |
151 | 129 | 'status' => 'ok', |
|
163 | 141 | end |
164 | 142 |
|
165 | 143 | it 'responds 404 Not Found when cat_mode is not enabled' do |
166 | | - # Act |
167 | | - post '/api/scratch/assets/example.svg', headers: cookie_headers |
| 144 | + post '/api/scratch/assets/example.svg', headers: auth_headers |
168 | 145 |
|
169 | | - # Assert |
170 | 146 | expect(response).to have_http_status(:not_found) |
171 | 147 | end |
172 | 148 | end |
|
0 commit comments