-
Notifications
You must be signed in to change notification settings - Fork 27
/
PostWork.test.ts
87 lines (70 loc) · 2.32 KB
/
PostWork.test.ts
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
/* tslint:disable:no-relative-imports */
import { pickBy } from 'ramda'
import { describe } from 'riteway'
import { ABraveAndStartlingTruth, TheRaven } from '../../helpers/Claims'
import { delay, runtimeId, setUpServerAndDb } from '../../helpers/utils'
import { getWork, postWork } from '../../helpers/works'
const PREFIX = `test-functional-node-poet-${runtimeId()}`
const NODE_PORT = '28081'
const getWorkFromNode = getWork(NODE_PORT)
const postWorkToNode = postWork(NODE_PORT)
const getClaimWithoutAnchor = (claim: any) => pickBy((v: any, k: string) => k !== 'anchor', claim)
describe('POST /works', async assert => {
// Setup Mongodb and the app server
const { db, server, rabbitMQ } = await setUpServerAndDb({ PREFIX, NODE_PORT })
{
const response = await postWorkToNode(ABraveAndStartlingTruth)
const body = await response.text()
assert({
given: 'POST /works with a signed verifiable claim',
should: 'return 202',
actual: response.status,
expected: 202,
})
assert({
given: 'POST /works with a signed verifiable claim',
should: 'return an empty body',
actual: body,
expected: '',
})
await delay(5000)
const retrievedResponse = await getWorkFromNode(ABraveAndStartlingTruth.id)
const retrievedClaim = getClaimWithoutAnchor(await retrievedResponse.json())
assert({
given: 'a work posted to node',
should: 'retrieve the work by id',
actual: retrievedResponse.ok,
expected: true,
})
assert({
given: 'a work posted to node',
should: 'retrieve the full claim',
actual: retrievedClaim,
expected: ABraveAndStartlingTruth,
})
}
{
const invalidSignedClaim = {
...ABraveAndStartlingTruth,
'sec:proof': TheRaven['sec:proof'],
}
const response = await postWorkToNode(invalidSignedClaim)
assert({
given: 'POST /works with an invalidly signed claim',
should: 'return 422',
actual: response.status,
expected: 422,
})
const actual = await response.text()
const expected = 'Signed Verifiable Claim\'s signature is incorrect.'
assert({
given: 'POST /works with an invalidly signed claim',
should: `return ${expected}`,
actual,
expected,
})
}
await server.stop()
await db.teardown()
await rabbitMQ.stop()
})