Migrate from koa-route to koa-router

This commit is contained in:
Jonathan Cremin 2015-08-22 16:16:15 +01:00
parent 8474cca94c
commit a4bf3dd51d
17 changed files with 206 additions and 291 deletions

View file

@ -1,5 +1,5 @@
import { agent } from 'supertest';
import app from '../../api/app';
import app from '../../app';
const request = agent(app.listen());
@ -8,7 +8,7 @@ describe('hostr-api auth', function(){
describe('with no credentials', function(){
it('should `throw` 401', function(done){
request
.get('/user')
.get('/api/user')
.expect(401, done);
});
});
@ -16,18 +16,19 @@ describe('hostr-api auth', function(){
describe('with invalid credentials', function(){
it('should `throw` 401', function(done){
request
.get('/user')
.get('/api/user')
.auth('user', 'invalid password')
.expect(401, done);
});
});
describe('with valid credentials', function(){
it('should call the next middleware', function(done){
it('should 404', function(done){
request
.get('/')
.get('/api/')
.auth('test@hostr.co', 'test-password')
.expect(200, done);
.expect('Content-type', /application\/json/)
.expect(404, done);
});
});
});

View file

@ -1,6 +1,6 @@
import assert from 'assert';
import { agent } from 'supertest';
import app from '../../api/app';
import app from '../../app';
const request = agent(app.listen());
@ -11,7 +11,7 @@ describe('hostr-api file', function() {
describe('when GET /file', function() {
it('should receive a list of file objects', function(done) {
request
.get('/file')
.get('/api/file')
.auth('test@hostr.co', 'test-password')
.expect(200)
.expect(function(response) {
@ -25,7 +25,7 @@ describe('hostr-api file', function() {
it('should receive a new file object', function(done) {
this.timeout(30000);
request
.post('/file')
.post('/api/file')
.attach('file', 'test/fixtures/utah-arches.jpg')
.auth('test@hostr.co', 'test-password')
.expect(201)
@ -40,7 +40,7 @@ describe('hostr-api file', function() {
describe('when GET /file/:id', function() {
it('should receive the file object', function(done) {
request
.get('/file/' + id)
.get('/api/file/' + id)
.expect(200)
.expect(function(response) {
assert(response.body.name === 'utah-arches.jpg');
@ -52,16 +52,16 @@ describe('hostr-api file', function() {
describe('when DELETE /file/:id', function() {
it('should delete the file object', function(done) {
request
.delete('/file/' + id)
.delete('/api/file/' + id)
.auth('test@hostr.co', 'test-password')
.expect(200, done);
.expect(204, done);
});
});
describe('when GET deleted /file/:id', function() {
it('should not receive the file object', function(done) {
request
.get('/file/' + id)
.get('/api/file/' + id)
.expect(404, done);
});
});

View file

@ -1,6 +1,6 @@
import assert from 'assert';
import { agent } from 'supertest';
import app from '../../api/app';
import app from '../../app';
const request = agent(app.listen());
@ -9,7 +9,7 @@ describe('hostr-api user', function() {
describe('when GET /user', function() {
it('should receive a user object', function(done) {
request
.get('/user')
.get('/api/user')
.auth('test@hostr.co', 'test-password')
.expect(function(response) {
assert(response.body.id === '54fd04a37675bcd06213eac8');
@ -22,7 +22,7 @@ describe('hostr-api user', function() {
describe('when GET /user/token', function() {
it('should receive a user token object', function(done) {
request
.get('/user/token')
.get('/api/user/token')
.auth('test@hostr.co', 'test-password')
.expect(function(response) {
assert(response.body.token);
@ -35,7 +35,7 @@ describe('hostr-api user', function() {
describe('when GET /user/transaction', function() {
it('should receive a user transactions object', function(done) {
request
.get('/user/transaction')
.get('/api/user/transaction')
.auth('test@hostr.co', 'test-password')
.expect(200)
.expect(function(response) {
@ -48,7 +48,7 @@ describe('hostr-api user', function() {
describe('when GET /user/settings', function() {
it('should update user password', function(done) {
request
.post('/user/settings')
.post('/api/user/settings')
.send({'current_password': 'test-password', 'new_password': 'test-password' })
.auth('test@hostr.co', 'test-password')
.expect(200)

View file

@ -3,19 +3,3 @@ db.files.createIndex({
"status": 1,
"time_added": -1
});
db.files.save({"_id": "94U1ruo7anyQ",
"owner": ObjectId("54fd04a37675bcd06213eac8"),
"system_name": "94U1ruo7anyQ",
"file_name": "utah-arches.jpg",
"original_name": "utah-arches.jpg",
"file_size": 194544,
"time_added": 1436223854,
"status": "active",
"last_accessed": null,
"s3": true,
"type": "image",
"ip": "::1",
"md5": "1f4185751b4db05494cbc0aad68d7d77",
"width": 1024,
"height": 683
});

View file

@ -1,19 +1,16 @@
import web from '../../web/app';
import api from '../../api/app';
import assert from 'assert';
import { agent } from 'supertest';
import app from '../../app';
const request = agent(web.listen());
const apiRequest = agent(api.listen());
const request = agent(app.listen());
let file = {};
describe('setup hostr-web file', function() {
describe('when POSTing a file to /file', function() {
it('should receive a new file object', function(done) {
this.timeout(30000);
apiRequest
.post('/file')
request
.post('/api/file')
.attach('file', 'test/fixtures/utah-arches.jpg')
.auth('test@hostr.co', 'test-password')
.expect(201)

View file

@ -1,5 +1,5 @@
import app from '../../web/app';
import { agent } from 'supertest';
import app from '../../app';
const request = agent(app.listen());