update-post.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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() => {
  8. crowi = await getInstance();
  9. });
  10. beforeEach(async() => {
  11. UpdatePost = mongoose.model('UpdatePost');
  12. });
  13. describe('.createPrefixesByPathPattern', () => {
  14. describe('with a path', () => {
  15. test('should return right patternPrfixes', () => {
  16. expect(UpdatePost.createPrefixesByPathPattern('/*')).toEqual(['*', '*']);
  17. expect(UpdatePost.createPrefixesByPathPattern('/user/*/日報*')).toEqual(['user', '*']);
  18. expect(UpdatePost.createPrefixesByPathPattern('/project/hoge/*')).toEqual(['project', 'hoge']);
  19. expect(UpdatePost.createPrefixesByPathPattern('/*/MTG/*')).toEqual(['*', 'MTG']);
  20. expect(UpdatePost.createPrefixesByPathPattern('自己紹介')).toEqual(['*', '*']);
  21. expect(UpdatePost.createPrefixesByPathPattern('/user/aoi/メモ/2016/02/10/xxx')).toEqual(['user', 'aoi']);
  22. });
  23. });
  24. });
  25. describe('.getRegExpByPattern', () => {
  26. describe('with a pattern', () => {
  27. test('should return right regexp', () => {
  28. expect(UpdatePost.getRegExpByPattern('/*')).toEqual(/^\/.*/);
  29. expect(UpdatePost.getRegExpByPattern('/user/*/日報*')).toEqual(/^\/user\/.*\/日報.*/);
  30. expect(UpdatePost.getRegExpByPattern('/project/hoge/*')).toEqual(/^\/project\/hoge\/.*/);
  31. expect(UpdatePost.getRegExpByPattern('/*/MTG/*')).toEqual(/^\/.*\/MTG\/.*/);
  32. expect(UpdatePost.getRegExpByPattern('自己紹介')).toEqual(/^\/.*自己紹介.*/);
  33. expect(UpdatePost.getRegExpByPattern('/user/aoi/メモ/2016/02/10/xxx')).toEqual(/^\/user\/aoi\/メモ\/2016\/02\/10\/xxx/);
  34. });
  35. });
  36. });
  37. describe('.normalizeChannelName', () => {
  38. describe('with a channel name', () => {
  39. test('should return true', () => {
  40. expect(UpdatePost.normalizeChannelName('#pj-hoge')).toEqual('pj-hoge');
  41. expect(UpdatePost.normalizeChannelName('pj-hoge')).toEqual('pj-hoge');
  42. });
  43. });
  44. });
  45. });