update-post.test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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', () => {
  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. });
  25. });
  26. });
  27. describe('.getRegExpByPattern', () => {
  28. describe('with a pattern', () => {
  29. test('should return right regexp', () => {
  30. expect(UpdatePost.getRegExpByPattern('/*')).toEqual(/^\/.*/);
  31. expect(UpdatePost.getRegExpByPattern('/user/*/日報*')).toEqual(/^\/user\/.*\/日報.*/);
  32. expect(UpdatePost.getRegExpByPattern('/project/hoge/*')).toEqual(/^\/project\/hoge\/.*/);
  33. expect(UpdatePost.getRegExpByPattern('/*/MTG/*')).toEqual(/^\/.*\/MTG\/.*/);
  34. expect(UpdatePost.getRegExpByPattern('自己紹介')).toEqual(/^\/.*自己紹介.*/);
  35. expect(UpdatePost.getRegExpByPattern('/user/aoi/メモ/2016/02/10/xxx')).toEqual(/^\/user\/aoi\/メモ\/2016\/02\/10\/xxx/);
  36. });
  37. });
  38. });
  39. describe('.normalizeChannelName', () => {
  40. describe('with a channel name', () => {
  41. test('should return true', () => {
  42. expect(UpdatePost.normalizeChannelName('#pj-hoge')).toEqual('pj-hoge');
  43. expect(UpdatePost.normalizeChannelName('pj-hoge')).toEqual('pj-hoge');
  44. });
  45. });
  46. });
  47. });