This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
invitation.test.js
138 lines (120 loc) · 4.19 KB
/
invitation.test.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const COUCH_URL = 'http://admin:admin@localhost:5984'
const ts = new Date().getTime()
const DB1 = 'invitationtest_' + ts
const Nano = require('nano')
const nano = Nano(COUCH_URL)
// the code we're testing
process.env.COUCH_URL = COUCH_URL
process.env.COUCH_INVITATION_DATABASE = DB1
const postInvitation = require('./postInvitation.js')
const getInvitation = require('./getInvitation.js')
const getInvitationList = require('./getInvitationList.js')
const deleteInvitation = require('./deleteInvitation.js')
let id1, id2, id3
beforeAll(async () => {
await nano.db.create(DB1)
const db1 = nano.db.use(DB1)
await db1.createIndex({ index: { fields: ['expires'] }, name: 'byExpiration', partitioned: false })
})
afterAll(async () => {
await nano.db.destroy(DB1)
})
test('postInvitation - missing parameters #1', async () => {
const obj = {
invitee: 'bob@aol.com',
choirId: 'xyz123'
}
const response = await postInvitation(obj)
expect(response.statusCode).toBe(400)
expect(response.body.ok).toBe(false)
})
test('postInvitation - create invitations', async () => {
let obj = {
creator: 'abc123',
invitee: 'bob@aol.com',
choirId: 'xyz123'
}
let response = await postInvitation(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.id).toBe('string')
id1 = response.body.id
obj = {
creator: 'abc123',
choirId: 'xyz123'
}
response = await postInvitation(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.id).toBe('string')
id2 = response.body.id
obj = {
creator: 'abc123',
invitee: 'sue@aol.com'
}
response = await postInvitation(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.id).toBe('string')
id3 = response.body.id
})
test('getInvitation - check', async () => {
let response = await getInvitation({ inviteId: id1 })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.invitation).toBe('object')
response = await getInvitation({ inviteId: id2 })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.invitation).toBe('object')
response = await getInvitation({ inviteId: id3 })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.invitation).toBe('object')
})
test('getInvitation - invalid', async () => {
const response = await getInvitation({ inviteId: 'nonsense' })
expect(response.statusCode).toBe(404)
expect(response.body.ok).toBe(false)
})
test('deleteInvitation - remove invitation by id', async () => {
let response = await deleteInvitation({ inviteId: id3 })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
response = await getInvitation({ inviteId: id3 })
expect(response.statusCode).toBe(404)
expect(response.body.ok).toBe(false)
})
test('deleteInvitation - invalid id', async () => {
const response = await getInvitation({ inviteId: 'nonsense' })
expect(response.statusCode).toBe(404)
expect(response.body.ok).toBe(false)
})
test('deleteInvitation - missing id', async () => {
const response = await getInvitation({ })
expect(response.statusCode).toBe(400)
expect(response.body.ok).toBe(false)
})
test('getInvitationList - check', async () => {
const response = await getInvitationList()
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(response.body.invitations.length).toBe(2)
expect(typeof response.body.invitations[0]).toBe('object')
})
test('postInvitation - create password reset invitation', async () => {
const obj = {
creator: 'xxxyyy',
userId: 'uid456'
}
let response = await postInvitation(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.id).toBe('string')
const inviteId = response.body.id
response = await getInvitation({ inviteId: inviteId })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.invitation).toBe('object')
expect(response.body.invitation.userId).toBe('uid456')
})