|
| 1 | +import * as assert from 'assert'; |
| 2 | +import { StatusCodes } from 'http-status-codes'; |
| 3 | +import { xapiHeaderVersion } from '../../../../activities/utils/constants'; |
| 4 | +import createStatement from '../../../tests/utils/createStatement'; |
| 5 | +import { jsonContentType, statementsRoute } from '../../../utils/constants'; |
| 6 | +import setupSurpertest from '../utils/setup'; |
| 7 | + |
| 8 | +describe('getStatements', () => { |
| 9 | + const { supertest } = setupSurpertest(); |
| 10 | + const TEST_ID_1 = 'f2ec2bf0-d6bd-4013-a652-846315b3e240'; |
| 11 | + const TEST_ID_2 = '60ccc696-4502-4a8b-896f-6c3dc1eb9639'; |
| 12 | + |
| 13 | + it('should successfully return statement without readonly parameter', async () => { |
| 14 | + await supertest |
| 15 | + .post(statementsRoute) |
| 16 | + .set('Content-Type', jsonContentType) |
| 17 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 18 | + .send([createStatement({ id: TEST_ID_1 })]); |
| 19 | + |
| 20 | + await supertest |
| 21 | + .get(statementsRoute) |
| 22 | + .set('Content-Type', jsonContentType) |
| 23 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 24 | + .query({ |
| 25 | + statementId: TEST_ID_1, |
| 26 | + }) |
| 27 | + .expect((response) => { |
| 28 | + assert.deepStrictEqual(response.status, StatusCodes.OK); |
| 29 | + assert.deepStrictEqual(response.body.id, TEST_ID_1); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should successfully return statement with readonly parameter', async () => { |
| 34 | + await supertest |
| 35 | + .post(statementsRoute) |
| 36 | + .set('Content-Type', jsonContentType) |
| 37 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 38 | + .send([createStatement({ id: TEST_ID_1 })]); |
| 39 | + |
| 40 | + await supertest |
| 41 | + .get(statementsRoute) |
| 42 | + .set('Content-Type', jsonContentType) |
| 43 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 44 | + .query({ |
| 45 | + statementId: TEST_ID_1, |
| 46 | + readonly: 1, |
| 47 | + }) |
| 48 | + .expect((response) => { |
| 49 | + assert.deepStrictEqual(response.status, StatusCodes.OK); |
| 50 | + assert.deepStrictEqual(response.body.id, TEST_ID_1); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should successfully return multiple statements with readonly parameter', async () => { |
| 55 | + await supertest |
| 56 | + .post(statementsRoute) |
| 57 | + .set('Content-Type', jsonContentType) |
| 58 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 59 | + .send([createStatement({ id: TEST_ID_1 }), createStatement({ id: TEST_ID_2 })]); |
| 60 | + |
| 61 | + await supertest |
| 62 | + .get(statementsRoute) |
| 63 | + .set('Content-Type', jsonContentType) |
| 64 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 65 | + .query({ |
| 66 | + readonly: 1, |
| 67 | + }) |
| 68 | + .expect((response) => { |
| 69 | + assert.deepStrictEqual(response.status, StatusCodes.OK); |
| 70 | + const actualIds = response.body.statements.map((statement: any) => statement.id); |
| 71 | + assert.deepStrictEqual(actualIds.includes(TEST_ID_1, TEST_ID_2), true); |
| 72 | + }); |
| 73 | + }); |
| 74 | + it('should successfully return multiple statements without readonly parameter', async () => { |
| 75 | + await supertest |
| 76 | + .post(statementsRoute) |
| 77 | + .set('Content-Type', jsonContentType) |
| 78 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 79 | + .send([createStatement({ id: TEST_ID_1 }), createStatement({ id: TEST_ID_2 })]); |
| 80 | + |
| 81 | + await supertest |
| 82 | + .get(statementsRoute) |
| 83 | + .set('Content-Type', jsonContentType) |
| 84 | + .set('X-Experience-API-Version', xapiHeaderVersion) |
| 85 | + .expect((response) => { |
| 86 | + assert.deepStrictEqual(response.status, StatusCodes.OK); |
| 87 | + const actualIds = response.body.statements.map((statement: any) => statement.id); |
| 88 | + assert.deepStrictEqual(actualIds.includes(TEST_ID_1, TEST_ID_2), true); |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments