Skip to content

Commit

Permalink
test: fix mocks for proxy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Mar 8, 2017
1 parent c1e9ac0 commit eb2e71c
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions test/integration/proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ function provisionServer () {
}

test('proxies request to CouchDB', function (t) {
t.plan(1)

var mock = nock('http://example.com')
.get('/hoodie-store/')
.reply(200, {db_name: 'hoodie-store'})
.put('/hoodie-store/_security')
.reply(201)
.get('/hoodie-store/_all_docs')
.query({
include_docs: true,
startkey: '"replication_"',
endkey: '"replication_\uffff"'
})
.reply(200, {rows: []})
.get('/foo/')
.reply(200, {ok: true})
.reply(200, {db_name: 'foo'})

var server = provisionServer()
server.register({
Expand All @@ -30,13 +39,19 @@ test('proxies request to CouchDB', function (t) {
PouchDB: PouchDB
.plugin(require('pouchdb-adapter-http'))
.defaults({
prefix: 'http://example.com'
prefix: 'http://example.com/'
})
}
}, noop)

server.inject('/foo', function (response) {
t.ok(mock.isDone(), 'request proxied to http://example.com/foo/')
// mock.pendingMocks() might still not be fulfilled as bootstrapping
// is happening in the background
mock.pendingMocks().forEach(function (route) {
t.isNot(route, 'GET http://example.com:80/foo/')
})

t.end()
})
})

Expand All @@ -51,8 +66,6 @@ test('proxies request to PouchDB', function (t) {
}
}, noop)

t.tearDown(server.stop.bind(server, null))

server.start(function () {
request.get('http://127.0.0.1:12345/foo', function (err, res, data) {
t.error(err, 'error')
Expand All @@ -69,14 +82,29 @@ test('proxies request to PouchDB', function (t) {
test('adds basic auth header', function (t) {
t.plan(1)

nock('http://example.com')
.get('/hoodie-store/')
.reply(200, {db_name: 'hoodie-store'})
.put('/hoodie-store/_security')
.reply(201)
.get('/hoodie-store/_all_docs')
.query({
include_docs: true,
startkey: '"replication_"',
endkey: '"replication_\uffff"'
})
.reply(200, {rows: []})
.get('/foo/')
.reply(200, {ok: true})

var server = provisionServer()
server.register({
register: plugin,
options: {
PouchDB: PouchDB
.plugin(require('pouchdb-adapter-http'))
.defaults({
prefix: 'http://example.com'
prefix: 'http://example.com/'
}),
hooks: {
onPreAuth: function (request, next) {
Expand Down

0 comments on commit eb2e71c

Please sign in to comment.