|
8 | 8 | databaseBuilder,
|
9 | 9 | expect,
|
10 | 10 | generateValidRequestAuthorizationHeader,
|
| 11 | + insertUserWithRoleSuperAdmin, |
11 | 12 | } from '../../../../test-helper.js';
|
12 | 13 |
|
13 | 14 | describe('Certification | Results | Acceptance | Application | Routes | certification results', function () {
|
@@ -267,4 +268,71 @@ describe('Certification | Results | Acceptance | Application | Routes | certific
|
267 | 268 | });
|
268 | 269 | });
|
269 | 270 | });
|
| 271 | + |
| 272 | + describe('GET /api/admin/sessions/{sessionId}/generate-results-download-link', function () { |
| 273 | + context('when user is Super Admin', function () { |
| 274 | + it('should return a 200 status code response', async function () { |
| 275 | + // given |
| 276 | + const sessionId = 121; |
| 277 | + const options = { |
| 278 | + method: 'GET', |
| 279 | + url: `/api/admin/sessions/${sessionId}/generate-results-download-link`, |
| 280 | + payload: {}, |
| 281 | + }; |
| 282 | + const server = await createServer(); |
| 283 | + await insertUserWithRoleSuperAdmin(); |
| 284 | + databaseBuilder.factory.buildSession({ id: 121 }); |
| 285 | + await databaseBuilder.commit(); |
| 286 | + |
| 287 | + // when |
| 288 | + options.headers = { authorization: generateValidRequestAuthorizationHeader() }; |
| 289 | + const response = await server.inject(options); |
| 290 | + |
| 291 | + // then |
| 292 | + expect(response.statusCode).to.equal(200); |
| 293 | + }); |
| 294 | + }); |
| 295 | + |
| 296 | + context('when user is not SuperAdmin', function () { |
| 297 | + it('should return 403 HTTP status code', async function () { |
| 298 | + // given |
| 299 | + const sessionId = 121; |
| 300 | + const options = { |
| 301 | + method: 'GET', |
| 302 | + url: `/api/admin/sessions/${sessionId}/generate-results-download-link`, |
| 303 | + payload: {}, |
| 304 | + }; |
| 305 | + const server = await createServer(); |
| 306 | + await insertUserWithRoleSuperAdmin(); |
| 307 | + |
| 308 | + // when |
| 309 | + options.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; |
| 310 | + const response = await server.inject(options); |
| 311 | + |
| 312 | + // then |
| 313 | + expect(response.statusCode).to.equal(403); |
| 314 | + }); |
| 315 | + }); |
| 316 | + |
| 317 | + context('when user is not connected', function () { |
| 318 | + it('should return 401 HTTP status code if user is not authenticated', async function () { |
| 319 | + // given |
| 320 | + const sessionId = 121; |
| 321 | + const options = { |
| 322 | + method: 'GET', |
| 323 | + url: `/api/admin/sessions/${sessionId}/generate-results-download-link`, |
| 324 | + payload: {}, |
| 325 | + }; |
| 326 | + const server = await createServer(); |
| 327 | + await insertUserWithRoleSuperAdmin(); |
| 328 | + |
| 329 | + // when |
| 330 | + options.headers = {}; |
| 331 | + const response = await server.inject(options); |
| 332 | + |
| 333 | + // then |
| 334 | + expect(response.statusCode).to.equal(401); |
| 335 | + }); |
| 336 | + }); |
| 337 | + }); |
270 | 338 | });
|
0 commit comments