Add more server-side tests
This commit is contained in:
parent
d68ccb0c48
commit
609f370de0
@ -79,6 +79,7 @@
|
||||
"nodemon": "1.11.0",
|
||||
"react-addons-test-utils": "15.5.1",
|
||||
"redux-mock-store": "1.2.3",
|
||||
"supertest": "^3.0.0",
|
||||
"uglify-js": "2.6.2",
|
||||
"watchify": "3.9.0"
|
||||
},
|
||||
|
||||
@ -8,4 +8,4 @@ const app = require('./server/app.js')
|
||||
const debug = require('debug')('peercalls')
|
||||
|
||||
let port = process.env.PORT || 3000
|
||||
app.http.listen(port, () => debug('Listening on: %s', port))
|
||||
app.listen(port, () => debug('Listening on: %s', port))
|
||||
|
||||
62
src/server/__tests__/app-test.js
Normal file
62
src/server/__tests__/app-test.js
Normal file
@ -0,0 +1,62 @@
|
||||
jest.mock('socket.io', () => {
|
||||
const { EventEmitter } = require('events')
|
||||
return jest.fn().mockReturnValue(new EventEmitter())
|
||||
})
|
||||
jest.mock('../socket.js')
|
||||
|
||||
const app = require('../app.js')
|
||||
const handleSocket = require('../socket.js')
|
||||
const io = require('socket.io')()
|
||||
const request = require('supertest')
|
||||
|
||||
describe('server/app', () => {
|
||||
|
||||
describe('GET /', () => {
|
||||
|
||||
it('renders index', () => {
|
||||
return request(app)
|
||||
.get('/')
|
||||
.expect(200)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('GET /call', () => {
|
||||
|
||||
it('redirects to a new call', () => {
|
||||
return request(app)
|
||||
.get('/call')
|
||||
.expect(302)
|
||||
.expect('location', /^call\/[0-9a-f-]{36}$/)
|
||||
})
|
||||
|
||||
it('redirects to relative url when slash', () => {
|
||||
return request(app)
|
||||
.get('/call/')
|
||||
.expect(302)
|
||||
.expect('location', /[0-9a-f-]{36}$/)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('GET /call/<uuid>', () => {
|
||||
|
||||
it('renders call page', () => {
|
||||
return request(app)
|
||||
.get('/call/test')
|
||||
.expect(200)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('io:connection', () => {
|
||||
|
||||
it('calls handleSocket with socket', () => {
|
||||
const socket = { hi: 'me socket' }
|
||||
io.emit('connection', socket)
|
||||
expect(handleSocket.mock.calls).toEqual([[ socket, io ]])
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
@ -1,12 +1,9 @@
|
||||
'use strict'
|
||||
jest.unmock('../socket.js')
|
||||
jest.unmock('events')
|
||||
jest.unmock('underscore')
|
||||
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
const handleSocket = require('../socket.js')
|
||||
|
||||
describe('socket', () => {
|
||||
describe('server/socket', () => {
|
||||
let socket, io, rooms
|
||||
beforeEach(() => {
|
||||
socket = new EventEmitter()
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
jest.unmock('../turn.js')
|
||||
const turn = require('../turn.js')
|
||||
|
||||
describe('turn', () => {
|
||||
describe('server/turn', () => {
|
||||
describe('getCredentials', () => {
|
||||
it('returns username & credential', () => {
|
||||
const auth = turn.getCredentials('a', 'b')
|
||||
|
||||
@ -18,4 +18,4 @@ app.use('/', require('./routes/index.js'))
|
||||
|
||||
io.on('connection', socket => handleSocket(socket, io))
|
||||
|
||||
module.exports = { http, app }
|
||||
module.exports = http
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user