user.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. });
  30. });
  31. describe('User Utilities', function () {
  32. context('Get username from path', function() {
  33. it('found', function(done) {
  34. var username = null;
  35. username = User.getUsernameByPath('/user/sotarok');
  36. expect(username).to.equal('sotarok');
  37. username = User.getUsernameByPath('/user/some.user.name12/'); // with slash
  38. expect(username).to.equal('some.user.name12');
  39. done();
  40. });
  41. it('not found', function(done) {
  42. var username = null;
  43. username = User.getUsernameByPath('/the/page/is/not/related/to/user/page');
  44. expect(username).to.be.null;
  45. done();
  46. });
  47. });
  48. });
  49. });