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
/
render.test.js
171 lines (155 loc) · 4.63 KB
/
render.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const COUCH_URL = 'http://admin:admin@localhost:5984'
const ts = new Date().getTime()
const DB1 = 'rendertest_' + ts
const Nano = require('nano')
const nano = Nano(COUCH_URL)
// the code we're testing
process.env.COUCH_URL = COUCH_URL
process.env.COUCH_RENDER_DATABASE = DB1
const postRender = require('./postRender.js')
const getRender = require('./getRender.js')
// pause
const sleep = async (ms) => {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms)
})
}
beforeAll(async () => {
await nano.db.create(DB1)
const db1 = nano.db.use(DB1)
await db1.createIndex({ ddoc: 'find', index: { partial_filter_selector: { status: 'done' }, fields: ['choirId', 'songId', 'date'] }, name: 'completedRenders', partitioned: false })
})
afterAll(async () => {
await nano.db.destroy(DB1)
})
test('postRender - missing parameters #1', async () => {
const obj = {
choirId: 'a'
}
const response = await postRender(obj)
expect(response.statusCode).toBe(400)
expect(response.body.ok).toBe(false)
})
test('postRender - missing parameters #2', async () => {
const obj = {
songId: 'b'
}
const response = await postRender(obj)
expect(response.statusCode).toBe(400)
expect(response.body.ok).toBe(false)
})
test('postRender - create render status', async () => {
let obj = {
choirId: 'a',
songId: 'b',
partId: 'xyz789'
}
let response = await postRender(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
obj = {
choirId: 'a',
songId: 'b',
partId: 'abc123'
}
response = await postRender(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
obj = {
choirId: 'a',
songId: 'c',
partId: ''
}
response = await postRender(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
await sleep(1000)
response = await getRender({ choirId: 'a', songId: 'b' })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.render).toBe('object')
expect(response.body.render.status).toBe('new')
})
test('getRender - check non-existant song', async () => {
const response = await getRender({ choirId: 'a', songId: 'nothing' })
expect(response.statusCode).toBe(404)
expect(response.body.ok).toBe(false)
})
test('postRender - updater status #1', async () => {
const obj = {
choirId: 'a',
songId: 'b',
partId: 'xyz789',
status: 'converted'
}
let response = await postRender(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
await sleep(1000)
response = await getRender({ choirId: 'a', songId: 'b' })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.render).toBe('object')
expect(response.body.render.status).toBe('converted')
})
test('postRender - updater status #2', async () => {
const obj = {
choirId: 'a',
songId: 'b',
partId: 'xyz789',
status: 'aligned'
}
let response = await postRender(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
await sleep(1000)
response = await getRender({ choirId: 'a', songId: 'b' })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.render).toBe('object')
expect(response.body.render.status).toBe('aligned')
})
test('postRender - updater status #3', async () => {
const obj = {
choirId: 'a',
songId: 'b',
partId: 'xyz789',
status: 'rendered'
}
let response = await postRender(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
await sleep(1000)
response = await getRender({ choirId: 'a', songId: 'b' })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.render).toBe('object')
expect(response.body.render.status).toBe('rendered')
})
test('postRender - updater status #4', async () => {
const obj = {
choirId: 'a',
songId: 'b',
status: 'done'
}
let response = await postRender(obj)
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
await sleep(1000)
response = await getRender({ choirId: 'a', songId: 'b' })
expect(response.statusCode).toBe(200)
expect(response.body.ok).toBe(true)
expect(typeof response.body.render).toBe('object')
expect(response.body.render.status).toBe('done')
})
test('postRender - invalid status', async () => {
const obj = {
choirId: 'a',
songId: 'b',
partId: 'xyz789',
status: 'sausages'
}
const response = await postRender(obj)
expect(response.statusCode).toBe(400)
expect(response.body.ok).toBe(false)
})