Skip to content

Commit

Permalink
Rename tests to match their implementation directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmccurdy committed Sep 18, 2017
1 parent ff6191b commit 92ce6fb
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 178 deletions.
82 changes: 82 additions & 0 deletions lib/__tests__/body-parsing.js → lib/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,86 @@ describe('Body Parsing', () => {
.send('message=lol');
});
});

describe('Nested Query Strings', () => {
describe('when options.qs = false', () => {
test('should not support nested query strings', () => {
const app = koala();
app.use(function * (next) {
this.response.body = this.request.query;
});

return request(app.callback())
.get('/')
.query({
something: {
nested: true
}
})
.expect(200)
.expect({
'something[nested]': 'true'
});
});
});

describe('when options.qs = true', () => {
test('should support nested query strings', () => {
const app = koala({
qs: true
});
app.use(function * (next) {
this.response.body = this.request.query;
});

return request(app.callback())
.get('/')
.query({
something: {
nested: true
}
})
.expect(200)
.expect({
something: {
nested: 'true'
}
});
});
});
});

describe('jsonp', () => {
test('should return jsonp response', () => {
const app = koala({
jsonp: {
callback: '_callback'
}
});
app.use(function * (next) {
this.jsonp = {foo: 'bar'};
});

return request(app.callback())
.get('/user.json?_callback=fn')
.expect(200)
.expect('/**/ typeof fn === \'function\' && fn({"foo":"bar"});');
});

test('should return json response', () => {
const app = koala({
jsonp: {
callback: '_callback'
}
});
app.use(function * (next) {
this.jsonp = {foo: 'bar'};
});

return request(app.callback())
.get('/user.json')
.expect(200)
.expect({'foo': 'bar'});
});
});
});
36 changes: 0 additions & 36 deletions lib/__tests__/jsonp.js

This file was deleted.

33 changes: 0 additions & 33 deletions lib/__tests__/object-streams.js

This file was deleted.

50 changes: 0 additions & 50 deletions lib/__tests__/query-string.js

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const koala = require('..');
const koala = require('../..');
const request = require('supertest');

describe('Conditional-Get', () => {
Expand Down
28 changes: 1 addition & 27 deletions lib/__tests__/headers.js → lib/middleware/__tests__/headers.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
const koala = require('..');
const koala = require('../..');
const request = require('supertest');

describe('Set headers', () => {
describe('X-Response-Time', () => {
test('should get X-Response-Time correctly by default', () => {
const app = koala();

return request(app.callback())
.get('/')
.expect(404)
.expect('X-Response-Time', /s$/);
});
test(
'should not get X-Response-Time by options.responseTime = false',
() => {
const app = koala({
responseTime: false
});

return request(app.callback())
.get('/')
.expect(404)
.expect(res => {
expect(res.headers['X-Response-Time']).toBe(undefined);
});
}
);
});

describe('Strict-Transport-Security', () => {
test('should not set Strict-Transport-Security by default', () => {
const app = koala();
Expand Down
88 changes: 88 additions & 0 deletions lib/middleware/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const koala = require('../..');
const request = require('supertest');
const PassThrough = require('stream').PassThrough;

describe('Middlewares', () => {
describe('Response Time', () => {
test('should get X-Response-Time correctly by default', () => {
const app = koala();

return request(app.callback())
.get('/')
.expect(404)
.expect('X-Response-Time', /s$/);
});
test(
'should not get X-Response-Time by options.responseTime = false',
() => {
const app = koala({
responseTime: false
});

return request(app.callback())
.get('/')
.expect(404)
.expect(res => {
expect(res.headers['X-Response-Time']).toBe(undefined);
});
}
);
});

describe('Object Streams', () => {
test('should be supported', () => {
const app = koala();
app.use(function * (next) {
const body = this.body = new PassThrough({
objectMode: true
});

body.write({
message: 'a'
});

body.write({
message: 'b'
});

body.end();
});

return request(app.callback())
.get('/')
.expect(200)
.expect([{
message: 'a'
}, {
message: 'b'
}]);
});
});

describe('Session', () => {
test('should has this.session by default', () => {
const app = koala();

app.use(function * () {
this.body = this.session;
});

return request(app.callback())
.get('/')
.expect('{}');
});
test('should has no this.session by options.session = false', () => {
const app = koala({
session: false
});

app.use(function * () {
this.body = this.session === undefined;
});

return request(app.callback())
.get('/')
.expect('true');
});
});
});
31 changes: 0 additions & 31 deletions lib/middleware/__tests__/middleware.js

This file was deleted.

0 comments on commit 92ce6fb

Please sign in to comment.