Skip to content

Commit 68b10f9

Browse files
authored
1 parent ffad74d commit 68b10f9

File tree

6 files changed

+1318
-2
lines changed

6 files changed

+1318
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@
114114
"publishConfig": {
115115
"access": "public"
116116
}
117-
}
117+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { get, has } from 'lodash';
2+
3+
import ActivityInteractionType from '../../../../models/ActivityInteractionType';
4+
import Statement from '../../../../models/Statement';
5+
6+
export const getBooleanMetadata = (statement: Statement)
7+
: {readonly [key: string]: any} => {
8+
if (
9+
!(
10+
get(
11+
statement.object,
12+
['definition', 'interactionType'],
13+
) === ActivityInteractionType.TRUE_FALSE
14+
&& has(statement, ['result', 'response'])
15+
)
16+
) {
17+
return {};
18+
}
19+
20+
return {
21+
'https://learninglocker&46;net/true-false-response': get(statement, ['result', 'response']),
22+
};
23+
};
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import Statement from '../../../../models/Statement';
2+
import { getBooleanMetadata } from './getBooleanMetadata';
23
import { getDurationMetadata } from './getDurationMetadata';
34
import { getSequencingMetadata } from './getSequencingMetadata';
45

5-
export default (statement: Statement): {readonly [key: string]: any} => {
6+
export default (statement: Statement): { readonly [key: string]: any } => {
67
const durationMetadata = getDurationMetadata(statement);
78
const sequencingMetadata = getSequencingMetadata(statement);
9+
const booleanMetadata = getBooleanMetadata(statement);
810

911
return {
1012
...durationMetadata,
1113
...sequencingMetadata,
14+
...booleanMetadata,
1215
};
1316
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import ActivityInteractionType from '../../../../../models/ActivityInteractionType';
2+
import InteractionActivityDefinition from '../../../../../models/InteractionActivityDefinition';
3+
import Statement from '../../../../../models/Statement';
4+
import SubStatementObject from '../../../../../models/SubStatementObject';
5+
import { statementDefaults } from './statements.fixture';
6+
7+
const booleanInteractionActivityStatement: Statement = {
8+
...statementDefaults,
9+
...{
10+
result: {
11+
response: 'true',
12+
},
13+
object: {
14+
definition: {
15+
name: {'en-US': 'Question 1'},
16+
description: {'en-US': 'Does the TCAPI include the concept of statements?'},
17+
type: 'http://adlnet.gov/expapi/activities/cmi.interaction',
18+
interactionType: ActivityInteractionType.TRUE_FALSE,
19+
correctResponsesPattern: ['true'],
20+
} as Partial<InteractionActivityDefinition>,
21+
} as SubStatementObject,
22+
} as Partial<Statement>,
23+
};
24+
25+
export {
26+
booleanInteractionActivityStatement,
27+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as assert from 'assert';
2+
import Statement from '../../../../models/Statement';
3+
4+
import { getBooleanMetadata } from '../../../../service/storeStatements/queriables/getMetadataFromStatement/getBooleanMetadata';
5+
import { booleanInteractionActivityStatement } from './fixtures/boolean.fixture';
6+
7+
describe('Retrieve sequencing metadata from statement', () => {
8+
it('should return empty metadata from empty result', () => {
9+
const expectedEmptyMetadata = {};
10+
11+
const actualEmptyMetadataFromEmptyResult = getBooleanMetadata(
12+
{
13+
...booleanInteractionActivityStatement,
14+
...{
15+
result: {},
16+
} as Partial<Statement>,
17+
},
18+
);
19+
20+
assert.deepEqual(actualEmptyMetadataFromEmptyResult, expectedEmptyMetadata);
21+
});
22+
23+
it('should return false metadata when `false` provided in the result', () => {
24+
const actualCorrectMetadata = getBooleanMetadata(
25+
{
26+
...booleanInteractionActivityStatement,
27+
...{
28+
result: {
29+
response: 'false',
30+
},
31+
} as Partial<Statement>,
32+
},
33+
);
34+
35+
const expectedCorrectMetadata = {
36+
'https://learninglocker&46;net/true-false-response': 'false',
37+
};
38+
39+
assert.deepEqual(actualCorrectMetadata, expectedCorrectMetadata);
40+
});
41+
42+
it('should return true metadata when `true` provided in the result', () => {
43+
const actualCorrectMetadata = getBooleanMetadata(booleanInteractionActivityStatement);
44+
45+
const expectedCorrectMetadata = {
46+
'https://learninglocker&46;net/true-false-response': 'true',
47+
};
48+
49+
assert.deepEqual(actualCorrectMetadata, expectedCorrectMetadata);
50+
});
51+
});

0 commit comments

Comments
 (0)