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-contact-point-action.js
81 lines (69 loc) · 2.29 KB
/
test-update-contact-point-action.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
import assert from 'assert';
import DB from '../src/db/db';
import { createContactPointId } from '../src/utils/ids';
import { getId } from '../src/utils/jsonld';
import { createRandomOrcid } from '../src/utils/orcid';
describe('UpdateContactPointAction', function() {
this.timeout(40000);
let user;
const db = new DB();
before(async () => {
const action = await db.post({
'@type': 'RegisterAction',
actionStatus: 'CompletedActionStatus',
agent: {
'@type': 'Person',
orcid: createRandomOrcid(),
name: 'Peter Jon Smith'
}
});
user = action.result;
});
it('should create and update a contact point', async () => {
let now = new Date().toISOString();
const createAction = await db.post(
{
'@type': 'UpdateContactPointAction',
agent: getId(user),
actionStatus: 'CompletedActionStatus',
object: createContactPointId(user),
payload: {
contactType: 'notifications',
email: 'mailto:[email protected]',
active: true
}
},
{ user, now }
);
// console.log(require('util').inspect(createAction, { depth: null }));
assert(createAction.result.contactPoint.token.value);
assert.equal(createAction.result.contactPoint.token.dateCreated, now);
assert.equal(createAction.result.contactPoint.dateVerified, null);
// we need `dateModified` for the reconciliation logic
assert.equal(createAction.result.dateModified, now);
// Update
now = new Date().toISOString();
const updateAction = await db.post(
{
'@type': 'UpdateContactPointAction',
agent: getId(user),
actionStatus: 'CompletedActionStatus',
object: createContactPointId(user),
payload: {
contactType: 'notifications',
email: 'mailto:[email protected]',
active: true
}
},
{ user, now }
);
assert(updateAction.result.contactPoint.token.value);
assert(
createAction.result.contactPoint.token.value !==
updateAction.result.contactPoint.token.value
);
assert.equal(updateAction.result.contactPoint.dateVerified, null);
assert.equal(updateAction.result.dateModified, now);
// console.log(require('util').inspect(updateAction, { depth: null }));
});
});