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-feed.js
84 lines (72 loc) · 1.97 KB
/
test-feed.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
import assert from 'assert';
import DB from '../src/db/db';
import Feed from '../src/db/feed';
import { getId } from '../src/utils/jsonld';
import { createRandomOrcid } from '../src/utils/orcid';
import {
createPreprintServer,
createConfig,
crossrefDoi
} from './utils/create-preprint-server';
describe('feed', function() {
this.timeout(40000);
let user;
let server;
const port = 3333;
const config = createConfig(port, { logLevel: 'fatal' });
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;
});
it('follow the changes feed and sync index DB and make the latest triggering seq accessible via the getLatestTriggeringSeq view', done => {
const feed = new Feed(db);
feed.start();
feed.on('sync', (seq, preprint) => {
assert.equal(preprint['@type'], 'ScholarlyPreprint');
assert.equal(preprint.triggeringSeq, seq);
const lastSeq = feed.stop();
assert.equal(lastSeq, seq);
db.getLatestTriggeringSeq()
.then(latestTriggeringSeq => {
assert.equal(latestTriggeringSeq, seq);
done();
})
.catch(done);
});
feed.on('error', err => {
feed.stop();
done(err);
});
const action = db
.post(
{
'@type': 'RequestForRapidPREreviewAction',
agent: getId(user.hasRole[0]),
actionStatus: 'CompletedActionStatus',
object: crossrefDoi
},
{
user
}
)
.catch(done);
});
after(done => {
server.close(done);
});
});