Skip to content

Commit

Permalink
Issue #46 added unit test for GET /blog and GET /admin. Setup admin l…
Browse files Browse the repository at this point in the history
…ogin for unit test.
  • Loading branch information
uptownhr committed Apr 13, 2016
1 parent 299fe68 commit 672da3c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"scripts": {
"dev": "nodemon index.js",
"dev-docker": "npm install && npm run dev",
"test": "mocha --reporter spec --timeout 5000",
"postversion": "git push && git push --tags"
"test": "PORT=9999 mocha --reporter spec --timeout 5000",
"test-watch": "PORT=9999 mocha --reporter spec --timeout 5000",
"postversion": "git push && git push --tags",
"docker-mongo": "docker exec -it hackathonstarterlite_mongo_1 mongo"
},
"author": "",
"license": "ISC",
Expand Down
41 changes: 41 additions & 0 deletions test/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict"
var request = require('supertest');
var app = require('../index.js');

const admin_user = {
email: 'admin@admin.com',
password: 'asdfasdf'
}

// for storing session
const agent = request.agent(app);

describe('Admin', function(){
before(function(done){
agent
.post('/auth/login')
.send(admin_user)
.expect(302, done)
})

describe('GET /admin/', function() {
it('should return 200 OK', function(done) {
agent
.get('/admin/')
.expect(200, done)
});
it('should return 303 when not admin', function(done){
request(app)
.get('/admin/')
.expect(302, done)
})
});

describe('GET /admin/users', function(){
it('should return 200 OK', function(done){
agent
.get('/admin/users')
.expect(200, done)
})
})
})
11 changes: 10 additions & 1 deletion test/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var request = require('supertest');
var mongoose = require('mongoose');
var app = require('../index.js');

describe('GET /', function() {
Expand Down Expand Up @@ -31,4 +32,12 @@ describe('GET /random-url', function() {
.get('/reset')
.expect(404, done);
});
});
});

describe('GET /blog', function(){
it('should return 200', function(done){
request(app)
.get('/blog')
.expect(200, done)
})
})
10 changes: 9 additions & 1 deletion test/models.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
var chai = require('chai');
var should = chai.should();
var mongoose = require('mongoose');
var User = require('../models/User');

describe('User Model', function() {
/*before( function(done){
mongoose.models = {},
mongoose.modelSchemas = {}
done()
})*/

it('should create a new user', function(done) {
var user = new User({
email: 'test@gmail.com',
Expand Down Expand Up @@ -39,4 +47,4 @@ describe('User Model', function() {
done();
});
});
});
});

0 comments on commit 672da3c

Please sign in to comment.