-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
71 lines (63 loc) · 2.08 KB
/
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
const chai = require('chai')
const chaiHttp = require('chai-http')
const expect = chai.expect
chai.use(chaiHttp)
const app = require('./app.js')
describe('routes', () => {
let generatedId
it('POST /<foo> -- should post a project', () =>
chai.request(app)
.post('/foo')
.send({
files: [
{ filename: 'foo.js', value: 'foo' },
{ filename: 'bar.js', value: 'bar' },
]
})
.then(res => {
expect(res).to.have.status(201)
expect(res).to.be.json
expect(res).to.have.header('Content-Type', /json/)
expect(res.body.generatedId).to.match(/[a-z0-9]/gi)
generatedId = res.body.generatedId
}))
it('GET /<foo>/<id> -- should fetch that project by id', () =>
chai.request(app)
.get('/foo/' + generatedId)
.set('Accept', 'application/json')
.then(res => {
expect(res).to.have.status(200)
expect(res).to.be.json
expect(res).to.have.header('Content-Type', /json/)
expect(res.body.files).to.be.an('array')
}))
it('GET /recent -- should get a recent project list', () =>
chai.request(app)
.get('/recent')
.set('Accept', 'application/json')
.then(res => {
expect(res).to.have.status(200)
expect(res).to.be.json
expect(res).to.have.header('Content-Type', /json/)
expect(res.body.projects).to.be.an('array')
expect(res.body.projects[0]).to.include('foo/')
}))
it('GET /fetch?url=http://some-remote-url -- fetch proxy should succeed', () =>
chai.request(app)
.get('/fetch?url=https://google.com')
.then(res => {
expect(res).to.have.status(200)
}))
it('GET /fetch?url=invalid -- fetch proxy should fail', () =>
chai.request(app)
.get('/fetch?url=invalid')
.then(res => {
expect(res).to.have.status(500)
}))
it('GET /fetch?url=freesound:<sound_id> -- should fetch sound from freesound api', () =>
chai.request(app)
.get('/fetch?url=freesound:212208')
.then(res => {
expect(res).to.have.status(200)
}))
})