ItemProjector.spec.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'reflect-metadata'
  2. import { TimerInterface } from '@standardnotes/time'
  3. import { Item } from '../Domain/Item/Item'
  4. import { ItemProjector } from './ItemProjector'
  5. import { ContentType } from '@standardnotes/common'
  6. describe('ItemProjector', () => {
  7. let item: Item
  8. let timer: TimerInterface
  9. const createProjector = () => new ItemProjector(timer)
  10. beforeEach(() => {
  11. timer = {} as jest.Mocked<TimerInterface>
  12. timer.convertMicrosecondsToStringDate = jest.fn().mockReturnValue('2021-04-15T08:00:00.123456Z')
  13. item = new Item()
  14. item.uuid = '1-2-3'
  15. item.itemsKeyId = '2-3-4'
  16. item.duplicateOf = null
  17. item.encItemKey = '3-4-5'
  18. item.content = 'test'
  19. item.contentType = ContentType.Note
  20. item.authHash = 'asd'
  21. item.deleted = false
  22. item.createdAtTimestamp = 123
  23. item.updatedAtTimestamp = 123
  24. item.updatedWithSession = '7-6-5'
  25. item.userUuid = 'u1-2-3'
  26. })
  27. it('should create a full projection of an item', async () => {
  28. expect(await createProjector().projectFull(item)).toMatchObject({
  29. uuid: '1-2-3',
  30. items_key_id: '2-3-4',
  31. duplicate_of: null,
  32. enc_item_key: '3-4-5',
  33. content: 'test',
  34. content_type: 'Note',
  35. auth_hash: 'asd',
  36. deleted: false,
  37. created_at: '2021-04-15T08:00:00.123456Z',
  38. updated_at: '2021-04-15T08:00:00.123456Z',
  39. updated_with_session: '7-6-5',
  40. })
  41. })
  42. it('should create a custom projection of an item', async () => {
  43. expect(await createProjector().projectCustom('dump', item)).toMatchObject({
  44. uuid: '1-2-3',
  45. items_key_id: '2-3-4',
  46. duplicate_of: null,
  47. enc_item_key: '3-4-5',
  48. content: 'test',
  49. content_type: 'Note',
  50. auth_hash: 'asd',
  51. deleted: false,
  52. created_at: '2021-04-15T08:00:00.123456Z',
  53. updated_at: '2021-04-15T08:00:00.123456Z',
  54. updated_with_session: '7-6-5',
  55. user_uuid: 'u1-2-3',
  56. })
  57. })
  58. it('should throw error on simple projection', async () => {
  59. let error = null
  60. try {
  61. await createProjector().projectSimple(item)
  62. } catch (e) {
  63. error = e
  64. }
  65. expect((error as Error).message).toEqual('not implemented')
  66. })
  67. })