This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tests for meanjs core server functionality
- Loading branch information
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
var should = require('should'), | ||
mongoose = require('mongoose'), | ||
User = mongoose.model('User'), | ||
path = require('path'), | ||
config = require(path.resolve('./config/config')), | ||
seed = require(path.resolve('./config/lib/seed')); | ||
|
||
describe('Configuration tests', function () { | ||
|
||
describe('Testing default seedDB:', function () { | ||
before(function(done) { | ||
User.remove(function(err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
after(function(done) { | ||
User.remove(function(err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should not be an admin user to begin with', function(done) { | ||
User.find({username: 'admin'}, function(err, users) { | ||
should.not.exist(err); | ||
users.should.be.instanceof(Array).and.have.lengthOf(0); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('should not be a "regular" user to begin with', function(done) { | ||
User.find({username: 'user'}, function(err, users) { | ||
should.not.exist(err); | ||
users.should.be.instanceof(Array).and.have.lengthOf(0); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('should set NODE_ENV to production and seedDB turned on so admin account must exist', function(done) { | ||
|
||
// Save original value | ||
var nodeEnv = process.env.NODE_ENV; | ||
// Set node env ro production environment | ||
process.env.NODE_ENV = 'production'; | ||
|
||
User.find({username: 'admin'}, function(err, users) { | ||
|
||
// There shouldn't be any errors | ||
should.not.exist(err); | ||
users.should.be.instanceof(Array).and.have.lengthOf(0); | ||
|
||
seed.start().then(function() { | ||
User.find({username: 'admin'}, function(err, users) { | ||
should.not.exist(err); | ||
users.should.be.instanceof(Array).and.have.lengthOf(1); | ||
|
||
var admin = users.pop(); | ||
admin.username.should.equal('admin'); | ||
|
||
// Restore original NODE_ENV environment variable | ||
process.env.NODE_ENV = nodeEnv; | ||
|
||
User.remove(function(err) { | ||
should.not.exist(err); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should set NODE_ENV to test and seedDB turned on so admin, and user accounts must exist', function(done) { | ||
|
||
// Save original value | ||
var nodeEnv = process.env.NODE_ENV; | ||
// Set node env ro production environment | ||
process.env.NODE_ENV = 'test'; | ||
|
||
User.find({username: 'admin'}, function(err, users) { | ||
|
||
// There shouldn't be any errors | ||
should.not.exist(err); | ||
users.should.be.instanceof(Array).and.have.lengthOf(0); | ||
|
||
seed.start().then(function() { | ||
User.find({username: 'admin'}, function(err, users) { | ||
should.not.exist(err); | ||
users.should.be.instanceof(Array).and.have.lengthOf(1); | ||
|
||
var admin = users.pop(); | ||
admin.username.should.equal('admin'); | ||
|
||
User.find({username: 'user'}, function(err, users) { | ||
|
||
should.not.exist(err); | ||
users.should.be.instanceof(Array).and.have.lengthOf(1); | ||
|
||
var user = users.pop(); | ||
user.username.should.equal('user'); | ||
|
||
// Restore original NODE_ENV environment variable | ||
process.env.NODE_ENV = nodeEnv; | ||
|
||
User.remove(function(err) { | ||
should.not.exist(err); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |