Skip to content

Commit 1767bc1

Browse files
authored
feat(Statements): Add readonly parameter for additional support (LLC-1971) (#871)
1 parent cd5c555 commit 1767bc1

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
});

src/apps/statements/expressPresenter/utils/getStatements/getMultipleStatements.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default async (opts: Options) => {
3939
'ascending',
4040
'cursor',
4141
'offset',
42+
'readonly',
4243
]);
4344

4445
const results = await config.service.getStatements({

src/apps/statements/expressPresenter/utils/getStatements/getSingleStatement.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ export default async (opts: Options) => {
2222
const timestamp = new Date().toISOString();
2323
const resultOpts = getStatementsResultOptions(queryParams, client);
2424

25-
checkUnknownParams(queryParams, ['statementId', 'voidedStatementId', 'format', 'attachments']);
25+
checkUnknownParams(queryParams, [
26+
'statementId',
27+
'voidedStatementId',
28+
'format',
29+
'attachments',
30+
'readonly',
31+
]);
2632

2733
const results = await config.service.getStatement({ id, voided, langs, ...resultOpts });
2834
res.setHeader('X-Experience-API-Consistent-Through', timestamp);

0 commit comments

Comments
 (0)