Initial test/scaffolding working

This commit is contained in:
Fergal Moran
2014-03-23 22:01:12 +00:00
parent d4e760aee7
commit ff20c82312
11 changed files with 180 additions and 111 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
node_modules
.idea/*
public
.tmp
.sass-cache

View File

@@ -0,0 +1,11 @@
'use strict';
angular.module('robotoPromotoApp')
.controller('PromotionsCtrl', function ($scope, $http) {
$http.get('/api/promotions').success(function(promotions) {
$scope.gridPromotions = {
data: promotions,
filterOptions: $scope.filterOptions
};
});
});

View File

@@ -0,0 +1,7 @@
<div ng-include="'partials/navbar'"></div>
<p><strong>Filter: </strong><input type="text" ng-model="filterOptions.filterText"/></p>
<div class="gridStyle" ng-grid-"gridPromotions"></div>
<div class="footer">
<p>♥ from the PodNoms team</p>
</div>

View File

@@ -1,37 +1,28 @@
'use strict';
var mongoose = require('mongoose'),
User = mongoose.model('User'),
Promotion = mongoose.model('Promotion'),
Thing = mongoose.model('Thing');
var user;
User = mongoose.model('User'),
Promotion = mongoose.model('Promotion');
console.log("Creating users");
// Clear old users, then add a default user
User.find({}).remove(function() {
user = new User({
console.log("Clearing old data");
User.remove().exec();
Promotion.remove().exec();
var user = new User({
provider: 'local',
name: 'Test User',
name: 'Fake User',
email: 'test@test.com',
password: 'test' }, function() {
console.log('finished populating users');
}
);
password: 'password'
});
user.save(function(err){ if (err) console.dir(err);});
var promotion = new Promotion({ title: 'Test Prom 1', user: user }).save(function(err){ if (err) console.dir(err);});
promotion = new Promotion({ title: 'Test Prom 2', user: user});
promotion.save(function(err){ if (err) console.dir(err);});
promotion = new Promotion({ title: 'Test Prom 3', user: user});
promotion.save(function(err){ if (err) console.dir(err);});
promotion = new Promotion({ title: 'Test Prom 4', user: user});
promotion.save(function(err){ if (err) console.dir(err);});
Promotion.find({}).remove(function(){
console.log("Creating promotions");
Promotion.create({
title: 'Dev prom 1',
user: user
}, {
title: 'Dev prom 2',
user: user
}, {
title: 'Dev prom 3',
user: user
}, function(err){
console.log('finished populating promotions');
});
});
console.log("Bootstrap complete");

View File

@@ -3,6 +3,6 @@
module.exports = {
env: 'development',
mongo: {
uri: 'mongodb://localhost/roboto-dev'
uri: 'mongodb://home.bitchmints.com/roboto-dev'
}
};

View File

@@ -3,6 +3,6 @@
module.exports = {
env: 'test',
mongo: {
uri: 'mongodb://localhost/roboto-test'
uri: 'mongodb://home.bitchmints.com/roboto-test'
}
};

View File

@@ -61,7 +61,9 @@
"mocha": "~1.18.2",
"mongodb": "~1.3.23",
"mocha-mongoose": "~1.0.1",
"grunt-mocha-debug": "0.0.10"
"grunt-mocha-debug": "0.0.10",
"mongoose-fakery": "~0.1.7",
"superagent": "~0.17.0"
},
"engines": {
"node": ">=0.10.0"

View File

@@ -0,0 +1,22 @@
'use strict';
describe('Controller: PromotionsCtrl', function () {
// load the controller's module
beforeEach(module('robotoPromotoApp'));
var PromotionsCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
PromotionsCtrl = $controller('PromotionsCtrl', {
$scope: scope
});
}));
it('should attach a list of awesomeThings to the scope', function () {
expect(scope.awesomeThings.length).toBe(3);
});
});

View File

@@ -1,31 +1,64 @@
'use strict';
var should = require('should'),
app = require('../../../server'),
request = require('supertest');
mongoose = require('mongoose'),
app = require('../../../server'),
agent = require('superagent'),
request = require('supertest'),
User = mongoose.model('User'),
Promotion = mongoose.model('Promotion');
describe('GET /api/promotions', function() {
it('should respond with JSON array', function(done) {
//create a passport user for authenticated requests
var user, provider, auth;
describe('Promotions Api', function(){
before(function(done){
User.remove().exec();
Promotion.remove().exec();
user = new User({
provider: 'local',
name: 'Fake User',
email: 'test@test.com',
password: 'password'
});
user.save(function(err){
should.not.exist(err);
auth = agent.agent();
auth.post('/signin')
.send({ user: 'test@test.com', password: 'password' })
.end(function (err, res) {
done();
});
});
});
describe('GET /api/promotions', function () {
it('should respond with JSON array', function (done) {
request(app)
.get('/api/promotions')
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
.end(function (err, res) {
if (err) return done(err);
res.body.should.be.instanceof(Array);
done();
});
});
});
describe('POST /api/promotions', function(){
it('should respond with the item POSTed', function(done){
});
describe('POST /api/promotions', function () {
it('should respond with the item POSTed', function (done) {
request(app)
.post('/api/promotions')
.send({
title: 'API - Test 2',
user: {
name: 'Fergal Moran'
}
user: auth
})
.expect(201)
.expect('Content-Type', /json/)
.end(function (err, res) {
done();
});
});
});
});

View File

@@ -24,16 +24,16 @@ describe('Promotion Model', function () {
title: 'Test Prom 1',
user: user
});
// Clear promotions before testing
Promotion.remove().exec();
User.remove().exec();
Promotion.remove().exec();
done();
});
afterEach(function (done) {
after(function (done) {
//going to leave the data intact post test
//as it is removed in before()
//Promotion.remove().exec();
Promotion.remove().exec();
User.remove().exec();
done();
});
@@ -50,6 +50,15 @@ describe('Promotion Model', function () {
done();
});
});
it('should fail when saving a duplicate promotion', function (done) {
promotion.save(function (err) {
should.not.exist(err);
promotion2.save(function (err) {
should.exist(err);
done();
});
});
});
it('should fail when saving without a user', function (done) {
promotion.user = '';
promotion.save(function (err) {
@@ -64,14 +73,7 @@ describe('Promotion Model', function () {
done();
});
});
it('should fail when saving a duplicate promotion', function (done) {
promotion.save(function (err) {
promotion2.save(function (err) {
should.exist(err);
done();
});
});
});
});
describe('Search methods', function () {
it('should find promotion by title', function (done) {

View File

@@ -6,8 +6,8 @@ var should = require('should'),
var user;
describe('User Model', function() {
before(function(done) {
describe('User Model', function () {
before(function (done) {
user = new User({
provider: 'local',
name: 'Fake User',
@@ -20,40 +20,40 @@ describe('User Model', function() {
done();
});
afterEach(function(done) {
afterEach(function (done) {
User.remove().exec();
done();
});
it('should begin with no users', function(done) {
User.find({}, function(err, users) {
it('should begin with no users', function (done) {
User.find({}, function (err, users) {
users.should.have.length(0);
done();
});
});
it('should fail when saving a duplicate user', function(done) {
it('should fail when saving a duplicate user', function (done) {
user.save();
var userDup = new User(user);
userDup.save(function(err) {
userDup.save(function (err) {
should.exist(err);
done();
});
});
it('should fail when saving without an email', function(done) {
it('should fail when saving without an email', function (done) {
user.email = '';
user.save(function(err) {
user.save(function (err) {
should.exist(err);
done();
});
});
it("should authenticate user if password is valid", function() {
it("should authenticate user if password is valid", function () {
user.authenticate('password').should.be.true;
});
it("should not authenticate user if password is invalid", function() {
it("should not authenticate user if password is invalid", function () {
user.authenticate('blah').should.not.be.true;
});