|
150 | 150 | end |
151 | 151 | end |
152 | 152 |
|
| 153 | + describe 'POST /api/templates/pdf' do |
| 154 | + let(:pdf_base64) { Base64.strict_encode64(Rails.root.join('spec/fixtures/sample-document.pdf').read) } |
| 155 | + let(:base_params) do |
| 156 | + { |
| 157 | + name: 'Test Template', |
| 158 | + documents: [{ name: 'sample-document.pdf', file: pdf_base64 }] |
| 159 | + } |
| 160 | + end |
| 161 | + |
| 162 | + it 'creates a template with audience set as submitters_order' do |
| 163 | + post '/api/templates/pdf', |
| 164 | + headers: { 'x-auth-token': author.access_token.token }, |
| 165 | + params: base_params.merge(audience: 'manager_then_employee').to_json, |
| 166 | + env: { 'CONTENT_TYPE' => 'application/json' } |
| 167 | + |
| 168 | + expect(response).to have_http_status(:ok) |
| 169 | + |
| 170 | + template = Template.last |
| 171 | + expect(template.preferences['submitters_order']).to eq('manager_then_employee') |
| 172 | + end |
| 173 | + |
| 174 | + it 'creates a template with simultaneous audience' do |
| 175 | + post '/api/templates/pdf', |
| 176 | + headers: { 'x-auth-token': author.access_token.token }, |
| 177 | + params: base_params.merge(audience: 'simultaneous').to_json, |
| 178 | + env: { 'CONTENT_TYPE' => 'application/json' } |
| 179 | + |
| 180 | + expect(response).to have_http_status(:ok) |
| 181 | + expect(Template.last.preferences['submitters_order']).to eq('simultaneous') |
| 182 | + end |
| 183 | + |
| 184 | + it 'ignores audience when not provided' do |
| 185 | + post '/api/templates/pdf', |
| 186 | + headers: { 'x-auth-token': author.access_token.token }, |
| 187 | + params: base_params.to_json, |
| 188 | + env: { 'CONTENT_TYPE' => 'application/json' } |
| 189 | + |
| 190 | + expect(response).to have_http_status(:ok) |
| 191 | + expect(Template.last.preferences['submitters_order']).to eq('single_sided') |
| 192 | + end |
| 193 | + |
| 194 | + it 'ignores an invalid audience value' do |
| 195 | + post '/api/templates/pdf', |
| 196 | + headers: { 'x-auth-token': author.access_token.token }, |
| 197 | + params: base_params.merge(audience: 'invalid_value').to_json, |
| 198 | + env: { 'CONTENT_TYPE' => 'application/json' } |
| 199 | + |
| 200 | + expect(response).to have_http_status(:ok) |
| 201 | + expect(Template.last.preferences['submitters_order']).to eq('single_sided') |
| 202 | + end |
| 203 | + |
| 204 | + it 'stores prefill attribute on fields' do |
| 205 | + employee_uuid = SecureRandom.uuid |
| 206 | + fields = [ |
| 207 | + { |
| 208 | + uuid: SecureRandom.uuid, |
| 209 | + submitter_uuid: employee_uuid, |
| 210 | + name: 'First Name', |
| 211 | + type: 'text', |
| 212 | + prefill: 'employee_first_name', |
| 213 | + areas: [{ x: 0.1, y: 0.1, w: 0.2, h: 0.03, page: 0 }] |
| 214 | + } |
| 215 | + ] |
| 216 | + |
| 217 | + post '/api/templates/pdf', |
| 218 | + headers: { 'x-auth-token': author.access_token.token }, |
| 219 | + params: base_params.merge( |
| 220 | + submitters: [{ name: 'Employee', uuid: employee_uuid }], |
| 221 | + fields: |
| 222 | + ).to_json, |
| 223 | + env: { 'CONTENT_TYPE' => 'application/json' } |
| 224 | + |
| 225 | + expect(response).to have_http_status(:ok) |
| 226 | + |
| 227 | + stored_field = Template.last.fields.find { |f| f['name'] == 'First Name' } |
| 228 | + expect(stored_field['prefill']).to eq('employee_first_name') |
| 229 | + end |
| 230 | + end |
| 231 | + |
153 | 232 | describe 'POST /api/templates/:id/clone' do |
154 | 233 | it 'clones a template' do |
155 | 234 | template = create(:template, account:, |
|
0 commit comments