unpkg/server/createServer.test.js

39 lines
920 B
JavaScript
Raw Normal View History

2017-08-19 00:32:57 +00:00
const request = require('supertest')
2017-09-13 15:06:50 +00:00
const createServer = require('./createServer')
2017-08-19 00:32:57 +00:00
2017-11-08 16:57:15 +00:00
describe('The server app', function() {
2017-08-19 00:32:57 +00:00
let app
2017-11-08 18:14:46 +00:00
beforeEach(() => {
2017-09-13 15:06:50 +00:00
app = createServer()
2017-08-19 00:32:57 +00:00
})
2017-11-08 16:57:15 +00:00
it('rejects invalid package names', function(done) {
request(app)
.get('/_invalid/index.js')
2017-11-08 18:14:46 +00:00
.then(res => {
2017-11-08 16:57:15 +00:00
expect(res.statusCode).toBe(403)
done()
})
2017-08-19 00:32:57 +00:00
})
2017-11-08 16:57:15 +00:00
it('redirects invalid query params', function(done) {
request(app)
.get('/react?main=index&invalid')
2017-11-08 18:14:46 +00:00
.then(res => {
2017-11-08 16:57:15 +00:00
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/react?main=index')
done()
})
2017-08-19 00:32:57 +00:00
})
2017-11-08 16:57:15 +00:00
it('redirects /_meta to ?meta', function(done) {
request(app)
.get('/_meta/react?main=index')
2017-11-08 18:14:46 +00:00
.then(res => {
2017-11-08 16:57:15 +00:00
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/react?main=index&meta')
done()
})
2017-08-19 00:32:57 +00:00
})
})