-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
test.headers.js
58 lines (49 loc) · 1.7 KB
/
test.headers.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
'use strict';
var http = require('http');
var PouchDB = require('../../lib');
var should = require("chai").should();
describe('test.headers.js', function () {
var server;
var headers;
var PORT = 9615;
before(function (done) {
server = http.createServer(function (req, res) {
headers = req.headers;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('');
});
server.listen(PORT, done);
});
after(function () {
return server.close();
});
it('Test headers are sent correctly', function () {
var opts = {ajax: {headers: {foo: 'bar'}}};
return new PouchDB('http:https://127.0.0.1:' + PORT, opts).then(function() {
should.equal(headers.foo, 'bar');
});
});
it('Test auth params are sent correctly', function () {
var opts = {auth: {username: 'foo', password: 'bar'}};
return new PouchDB('http:https://127.0.0.1:' + PORT, opts).then(function() {
should.equal(typeof headers.authorization, 'string');
});
});
it('Test headers are sent correctly on GET request', function() {
var db = new PouchDB('http:https://127.0.0.1:' + PORT);
var opts = { ajax: { headers: { ick: "slick" } } };
return db.get('fake', opts).then(function() {
should.equal(headers.ick, 'slick');
});
});
it('Test that we combine ajax options both globally and locally on GET',
function() {
var opts = { ajax: { headers: { aheader: 'whyyes' } } };
var db = new PouchDB('http:https://127.0.0.1:' + PORT, opts);
var getOpts = {ajax: { headers: { ick: "slick", aheader: "override!" } } };
return db.get('fake', getOpts).then(function() {
should.equal(headers.ick, 'slick');
should.equal(headers.aheader, 'override!');
});
});
});