Skip to content

Commit

Permalink
migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felixheck committed Nov 23, 2017
1 parent 14887e9 commit 02497e6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 109 deletions.
176 changes: 76 additions & 100 deletions test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Lab = require('lab')
let lab = exports.lab = Lab.script()
const inert = require('inert')
const vision = require('vision')
const plugin = require('../')

const describe = lab.describe
const it = lab.it
Expand All @@ -15,159 +16,134 @@ describe('index', () => {
describe('without prefix', () => {
let server

lab.before((done) => {
server = new Hapi.Server()
server.connection({port: 0})
server.register([vision, inert, {
register: require('../'),
lab.before(async () => {
server = Hapi.Server({ port: 0 })

await expect(server.register([vision, inert, {
plugin,
options: {
swaggerEndpoint: 'http://test.url.tld/swagger'
}
}], (err) => {
expect(err).to.not.exist()
server.start(() => {
done()
})
})
}])).not.to.reject()
})

lab.after((done) => {
server.stop({}, () => {
server = null
done()
})
lab.after(async () => {
await server.stop({})
server = null
})

it('Path /', (done) => {
server.inject('/', (res) => {
expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
done()
})
it('Path /', async () => {
const res = await server.inject('/')

expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
})

it('/index.html', (done) => {
server.inject('/index.html', (res) => {
expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
done()
})
it('/index.html', async () => {
const res = await server.inject('/')

expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
})
})

describe('with prefix', () => {
let server

lab.before((done) => {
server = new Hapi.Server()
server.connection({port: 0})
server.register([vision, inert, {
register: require('../'),
lab.before(async () => {
server = Hapi.Server({ port: 0 })

await server.register([vision, inert, {
plugin,
options: {
swaggerEndpoint: 'http://test.url.tld/swagger'
}
}], {
routes: {
prefix: '/docs'
}
}, (err) => {
expect(err).to.not.exist()
server.start(() => {
done()
})
})

await server.start()
})

lab.after((done) => {
server.stop({}, () => {
server = null
done()
})
lab.after(async () => {
await server.stop({})
server = null
})

it('Path /docs', (done) => {
server.inject('/docs', (res) => {
expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
done()
})
it('Path /docs', async () => {
const res = await server.inject('/docs')

expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
})

it('Path /docs/', (done) => {
server.inject('/docs/', (res) => {
expect(res.statusCode).to.equal(404)
done()
})
it('Path /docs/', async () => {
const res = await server.inject('/docs/')

expect(res.statusCode).to.equal(404)
})

it('/docs/index.html', (done) => {
server.inject('/docs/index.html', (res) => {
expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
done()
})
it('/docs/index.html', async () => {
const res = await server.inject('/docs/index.html')

expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
})
})

describe('with prefix and stripTrailingSlash', () => {
let server

lab.before((done) => {
server = new Hapi.Server()
server.connection({port: 0, router: { stripTrailingSlash: true }})
server.register([vision, inert, {
register: require('../'),
lab.before(async () => {
server = Hapi.Server({ port: 0, router: { stripTrailingSlash: true } })

await server.register([vision, inert, {
plugin,
options: {
swaggerEndpoint: 'http://test.url.tld/swagger'
}
}], {
routes: {
prefix: '/docs'
}
}, (err) => {
expect(err).to.not.exist()
server.start(() => {
done()
})
})

await server.start()
})

lab.after((done) => {
server.stop({}, () => {
server = null
done()
})
lab.after(async () => {
await server.stop({})
server = null
})

it('Path /docs', (done) => {
server.inject('/docs', (res) => {
expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
done()
})
it('Path /docs', async () => {
const res = await server.inject('/docs')

expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
})

it('Path /docs/', (done) => {
server.inject('/docs/', (res) => {
expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
done()
})
it('Path /docs/', async () => {
const res = await server.inject('/docs/')

expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
})

it('/docs/index.html', (done) => {
server.inject('/docs/index.html', (res) => {
expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
done()
})
it('/docs/index.html', async () => {
const res = await server.inject('/docs/index.html')

expect(res.statusCode).to.equal(200)
expect(res.result).to.contain('/swagger-ui-bundle.js')
expect(res.result).to.contain('"url":"http://test.url.tld/swagger"')
})
})
})
13 changes: 4 additions & 9 deletions test/plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ const it = lab.it
const expect = Code.expect

describe('init', () => {
it('register', (done) => {
const server = new Hapi.Server()
server.connection({port: 80})
it('register', async () => {
const server = Hapi.Server({ port: 80 })
const plugins = [require('vision'), require('inert'), require('../')]

server.register([require('vision'), require('inert'), {
register: require('../')
}], (err) => {
expect(err).to.not.exist()
done()
})
await expect(server.register(plugins)).not.to.reject()
})
})

0 comments on commit 02497e6

Please sign in to comment.