updatePost.test.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const mongoose = require('mongoose');
  2. const { getInstance } = require('../setup-crowi');
  3. describe('UpdatePost', () => {
  4. // eslint-disable-next-line no-unused-vars
  5. let crowi;
  6. let UpdatePost;
  7. beforeAll(async(done) => {
  8. crowi = await getInstance();
  9. done();
  10. });
  11. beforeEach(async(done) => {
  12. UpdatePost = mongoose.model('UpdatePost');
  13. done();
  14. });
  15. describe('.createPrefixesByPathPattern', () => {
  16. describe('with a path', () => {
  17. test('should return right patternPrfixes', (done) => {
  18. expect(UpdatePost.createPrefixesByPathPattern('/*')).toEqual(['*', '*']);
  19. expect(UpdatePost.createPrefixesByPathPattern('/user/*/日報*')).toEqual(['user', '*']);
  20. expect(UpdatePost.createPrefixesByPathPattern('/project/hoge/*')).toEqual(['project', 'hoge']);
  21. expect(UpdatePost.createPrefixesByPathPattern('/*/MTG/*')).toEqual(['*', 'MTG']);
  22. expect(UpdatePost.createPrefixesByPathPattern('自己紹介')).toEqual(['*', '*']);
  23. expect(UpdatePost.createPrefixesByPathPattern('/user/aoi/メモ/2016/02/10/xxx')).toEqual(['user', 'aoi']);
  24. done();
  25. });
  26. });
  27. });
  28. describe('.getRegExpByPattern', () => {
  29. describe('with a pattern', () => {
  30. test('should return right regexp', (done) => {
  31. expect(UpdatePost.getRegExpByPattern('/*')).toEqual(/^\/.*/);
  32. expect(UpdatePost.getRegExpByPattern('/user/*/日報*')).toEqual(/^\/user\/.*\/日報.*/);
  33. expect(UpdatePost.getRegExpByPattern('/project/hoge/*')).toEqual(/^\/project\/hoge\/.*/);
  34. expect(UpdatePost.getRegExpByPattern('/*/MTG/*')).toEqual(/^\/.*\/MTG\/.*/);
  35. expect(UpdatePost.getRegExpByPattern('自己紹介')).toEqual(/^\/.*自己紹介.*/);
  36. expect(UpdatePost.getRegExpByPattern('/user/aoi/メモ/2016/02/10/xxx')).toEqual(/^\/user\/aoi\/メモ\/2016\/02\/10\/xxx/);
  37. done();
  38. });
  39. });
  40. });
  41. describe('.normalizeChannelName', () => {
  42. describe('with a channel name', () => {
  43. test('should return true', (done) => {
  44. expect(UpdatePost.normalizeChannelName('#pj-hoge')).toEqual('pj-hoge');
  45. expect(UpdatePost.normalizeChannelName('pj-hoge')).toEqual('pj-hoge');
  46. done();
  47. });
  48. });
  49. });
  50. });