Skip to content

Instantly share code, notes, and snippets.

@ayoola-solomon
Created December 16, 2015 13:38
Show Gist options
  • Save ayoola-solomon/92953d6f5d335ac18613 to your computer and use it in GitHub Desktop.
Save ayoola-solomon/92953d6f5d335ac18613 to your computer and use it in GitHub Desktop.
'use strict';
var models = require('../../../server/models/');
var should = require('should');
describe('Fellow', function() {
var mockFellow;
beforeEach(function(done) {
mockFellow = {
uid: 'google:12345678',
email: 'fellow@email.com',
first_name: 'FirstName',
last_name: 'LastName',
name: 'FirstName LastName',
known_as: 'nickname',
picture: 'http://pictureurl.com',
level: 'D1'
}
models.Fellow.destroy({where: {}}).then(function() {
done();
});
});
afterEach(function(done) {
models.Fellow.destroy({where: {}}).then(function() {
done();
});
});
it('should create a fellow', function(done) {
models.Fellow.create(mockFellow).then(function(fellow) {
should.exist(fellow);
fellow.email.should.equal(mockFellow.email);
fellow.name.should.equal(mockFellow.name);
fellow.uid.should.equal(mockFellow.uid);
done();
});
});
it('should not create two fellows with same uid', function(done) {
models.Fellow.create(mockFellow).then(function(fellow) {
models.Fellow.create(mockFellow).catch(function(err) {
should.exist(err);
err.message.should.equal('Validation error');
err.errors[0].message.should.equal('uid must be unique');
done();
});
});
});
it('should be able to update a fellow', function(done) {
models.Fellow.create(mockFellow).then(function(fellow) {
var new_email = "newemail@email.com";
fellow.email = new_email;
fellow.save().then(function(fellow) {
should.exist(fellow);
fellow.email.should.not.equal(mockFellow.email);
fellow.email.should.equal(new_email);
done();
});
});
});
it('should be able to find a fellow', function(done) {
models.Fellow.create(mockFellow).then(function(createdFellow) {
models.Fellow.findOne({
where : {
uid: createdFellow.uid
}
}).then(function(fellow) {
should.exist(fellow);
fellow.name.should.equal(createdFellow.name);
done();
});
});
});
it('should be able to delete a fellow', function(done) {
models.Fellow.create(mockFellow).then(function(createdFellow) {
createdFellow.destroy().then(function() {
models.Fellow.findOne({
where : {
uid: createdFellow.uid
}
}).then(function(fellow) {
should.not.exist(fellow);
done();
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment