user.test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var chai = require('chai')
  2. , expect = chai.expect
  3. , sinon = require('sinon')
  4. , sinonChai = require('sinon-chai')
  5. , Promise = require('bluebird')
  6. , utils = require('../utils.js')
  7. ;
  8. chai.use(sinonChai);
  9. describe('User', function () {
  10. var Page = utils.models.Page,
  11. User = utils.models.User,
  12. conn = utils.mongoose.connection;
  13. describe('Create and Find.', function () {
  14. context('The user', function() {
  15. it('should created', function(done) {
  16. User.createUserByEmailAndPassword('Aoi Miyazaki', 'aoi', 'aoi@example.com', 'hogefuga11', function (err, userData) {
  17. expect(err).to.be.null;
  18. expect(userData).to.instanceof(User);
  19. done();
  20. });
  21. });
  22. it('should be found by findUserByUsername', function(done) {
  23. User.findUserByUsername('aoi')
  24. .then(function(userData) {
  25. expect(userData).to.instanceof(User);
  26. done();
  27. });
  28. });
  29. it('should be found by findUsersByPartOfEmail', function(done) {
  30. User.findUsersByPartOfEmail('ao', {})
  31. .then(function(userData) {
  32. expect(userData).to.be.array;
  33. expect(userData[0]).to.instanceof(User);
  34. expect(userData[0].email).to.equal('aoi@example.com');
  35. done();
  36. });
  37. });
  38. });
  39. });
  40. describe('User Utilities', function () {
  41. context('Get username from path', function() {
  42. it('found', function(done) {
  43. var username = null;
  44. username = User.getUsernameByPath('/user/sotarok');
  45. expect(username).to.equal('sotarok');
  46. username = User.getUsernameByPath('/user/some.user.name12/'); // with slash
  47. expect(username).to.equal('some.user.name12');
  48. done();
  49. });
  50. it('not found', function(done) {
  51. var username = null;
  52. username = User.getUsernameByPath('/the/page/is/not/related/to/user/page');
  53. expect(username).to.be.null;
  54. done();
  55. });
  56. });
  57. });
  58. });