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-update-scores.js
82 lines (70 loc) · 2 KB
/
test-update-scores.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
import assert from 'assert';
import DB from '../src/db/db';
import { getId } from '../src/utils/jsonld';
import { createRandomOrcid } from '../src/utils/orcid';
import {
createPreprintServer,
createConfig,
crossrefDoi,
arXivId
} from './utils/create-preprint-server';
describe('update scores', function() {
this.timeout(40000);
let user;
let server;
const port = 3333;
const config = createConfig(port);
const db = new DB(config);
before(async () => {
await db.init({ reset: true });
await db.ddoc();
server = createPreprintServer({ logLevel: 'fatal' });
await new Promise((resolve, reject) => {
server.listen(port, resolve);
});
const action = await db.post({
'@type': 'RegisterAction',
actionStatus: 'CompletedActionStatus',
agent: {
'@type': 'Person',
orcid: createRandomOrcid(),
name: 'Peter Jon Smith'
}
});
user = action.result;
for (const id of [crossrefDoi, arXivId]) {
const action = await db.post(
{
'@type': 'RequestForRapidPREreviewAction',
agent: getId(user.hasRole[0]),
actionStatus: 'CompletedActionStatus',
object: id
},
{
user,
now:
id === arXivId
? '2019-10-01T00:00:00.650Z'
: '2019-10-20T00:00:00.650Z'
}
);
await db.syncIndex(action, { now: '2019-10-20T00:00:00.650Z' });
}
});
it('should update scores', async () => {
// first update so that 1 score get to 0
let preprints = await db.updateScores({
now: '2019-10-29T00:00:00.650Z'
});
assert.equal(preprints.length, 2);
assert.equal(preprints.filter(preprint => preprint.score === 0).length, 1);
// update again, this time only 1 preprint is updated (the one with score non null)
preprints = await db.updateScores({
now: '2019-10-29T03:00:00.650Z'
});
assert.equal(preprints.length, 1);
});
after(done => {
server.close(done);
});
});