This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest-stats.js
87 lines (84 loc) · 2.16 KB
/
test-stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import assert from 'assert';
import pick from 'lodash/pick';
import { QUESTIONS } from '../src/constants';
import { getYesNoStats } from '../src/utils/stats';
describe('stats utils', function() {
describe('getYesNoStats', () => {
it('should get yes no stats', () => {
const actions = [
{
'@type': 'RapidPREreviewAction',
agent: 'role:roleId',
actionStatus: 'CompletedActionStatus',
object: 'arXiv:1910.00585',
resultReview: {
'@type': 'RapidPREreview',
about: [
{
'@type': 'OutbreakScienceEntity',
name: 'zika'
}
],
reviewAnswer: QUESTIONS.map((question, i) => {
let text;
if (question.type === 'YesNoQuestion') {
text =
i === 0
? 'yes'
: i === 1
? 'no'
: i === 2
? 'n.a.'
: 'unsure';
} else {
text = 'comment';
}
return {
'@type':
question.type === 'YesNoQuestion' ? 'YesNoAnswer' : 'Answer',
parentItem: `question:${question.identifier}`,
text
};
})
}
}
];
const stats = getYesNoStats(actions);
assert.deepEqual(
stats
.slice(0, 4)
.map(stat => pick(stat, ['nReviews', 'yes', 'no', 'na', 'unsure'])),
[
{
nReviews: 1,
yes: ['role:roleId'],
no: [],
na: [],
unsure: []
},
{
nReviews: 1,
yes: [],
no: ['role:roleId'],
na: [],
unsure: []
},
{
nReviews: 1,
yes: [],
no: [],
na: ['role:roleId'],
unsure: []
},
{
nReviews: 1,
yes: [],
no: [],
na: [],
unsure: ['role:roleId']
}
]
);
});
});
});