mirror of
https://github.com/fergalmoran/roboto-promoto.git
synced 2025-12-22 01:30:36 +00:00
Initial test/scaffolding working
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
node_modules
|
||||
.idea/*
|
||||
public
|
||||
.tmp
|
||||
.sass-cache
|
||||
|
||||
11
app/scripts/controllers/promotions.js
Normal file
11
app/scripts/controllers/promotions.js
Normal 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
|
||||
};
|
||||
});
|
||||
});
|
||||
7
app/views/partials/promotions.html
Normal file
7
app/views/partials/promotions.html
Normal 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>
|
||||
@@ -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({
|
||||
provider: 'local',
|
||||
name: 'Test User',
|
||||
email: 'test@test.com',
|
||||
password: 'test' }, function() {
|
||||
console.log('finished populating users');
|
||||
}
|
||||
);
|
||||
console.log("Clearing old data");
|
||||
|
||||
User.remove().exec();
|
||||
Promotion.remove().exec();
|
||||
|
||||
var user = new User({
|
||||
provider: 'local',
|
||||
name: 'Fake User',
|
||||
email: 'test@test.com',
|
||||
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");
|
||||
2
lib/config/env/development.js
vendored
2
lib/config/env/development.js
vendored
@@ -3,6 +3,6 @@
|
||||
module.exports = {
|
||||
env: 'development',
|
||||
mongo: {
|
||||
uri: 'mongodb://localhost/roboto-dev'
|
||||
uri: 'mongodb://home.bitchmints.com/roboto-dev'
|
||||
}
|
||||
};
|
||||
|
||||
2
lib/config/env/test.js
vendored
2
lib/config/env/test.js
vendored
@@ -3,6 +3,6 @@
|
||||
module.exports = {
|
||||
env: 'test',
|
||||
mongo: {
|
||||
uri: 'mongodb://localhost/roboto-test'
|
||||
uri: 'mongodb://home.bitchmints.com/roboto-test'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
|
||||
22
test/client/spec/controllers/promotions.js
Normal file
22
test/client/spec/controllers/promotions.js
Normal 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);
|
||||
});
|
||||
});
|
||||
@@ -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) {
|
||||
request(app)
|
||||
.get('/api/promotions')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.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){
|
||||
request(app)
|
||||
.post('/api/promotions')
|
||||
.send({
|
||||
title: 'API - Test 2',
|
||||
user: {
|
||||
name: 'Fergal Moran'
|
||||
}
|
||||
});
|
||||
//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) {
|
||||
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) {
|
||||
request(app)
|
||||
.post('/api/promotions')
|
||||
.send({
|
||||
title: 'API - Test 2',
|
||||
user: auth
|
||||
})
|
||||
.expect(201)
|
||||
.expect('Content-Type', /json/)
|
||||
.end(function (err, res) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -6,55 +6,55 @@ var should = require('should'),
|
||||
|
||||
var user;
|
||||
|
||||
describe('User Model', function() {
|
||||
before(function(done) {
|
||||
user = new User({
|
||||
provider: 'local',
|
||||
name: 'Fake User',
|
||||
email: 'test@test.com',
|
||||
password: 'password'
|
||||
describe('User Model', function () {
|
||||
before(function (done) {
|
||||
user = new User({
|
||||
provider: 'local',
|
||||
name: 'Fake User',
|
||||
email: 'test@test.com',
|
||||
password: 'password'
|
||||
});
|
||||
|
||||
// Clear users before testing
|
||||
User.remove().exec();
|
||||
done();
|
||||
});
|
||||
|
||||
// Clear users before testing
|
||||
User.remove().exec();
|
||||
done();
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
User.remove().exec();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should begin with no users', function(done) {
|
||||
User.find({}, function(err, users) {
|
||||
users.should.have.length(0);
|
||||
done();
|
||||
afterEach(function (done) {
|
||||
User.remove().exec();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when saving a duplicate user', function(done) {
|
||||
user.save();
|
||||
var userDup = new User(user);
|
||||
userDup.save(function(err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
it('should begin with no users', function (done) {
|
||||
User.find({}, function (err, users) {
|
||||
users.should.have.length(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when saving without an email', function(done) {
|
||||
user.email = '';
|
||||
user.save(function(err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
it('should fail when saving a duplicate user', function (done) {
|
||||
user.save();
|
||||
var userDup = new User(user);
|
||||
userDup.save(function (err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should authenticate user if password is valid", function() {
|
||||
user.authenticate('password').should.be.true;
|
||||
});
|
||||
it('should fail when saving without an email', function (done) {
|
||||
user.email = '';
|
||||
user.save(function (err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should not authenticate user if password is invalid", function() {
|
||||
user.authenticate('blah').should.not.be.true;
|
||||
});
|
||||
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 () {
|
||||
user.authenticate('blah').should.not.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user