ItemConflictProjector.spec.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'reflect-metadata'
  2. import { ProjectorInterface } from './ProjectorInterface'
  3. import { Item } from '../Domain/Item/Item'
  4. import { ItemConflict } from '../Domain/Item/ItemConflict'
  5. import { ItemConflictProjector } from './ItemConflictProjector'
  6. import { ItemHash } from '../Domain/Item/ItemHash'
  7. import { ItemProjection } from './ItemProjection'
  8. import { ConflictType } from '@standardnotes/responses'
  9. describe('ItemConflictProjector', () => {
  10. let itemProjector: ProjectorInterface<Item, ItemProjection>
  11. let itemProjection: ItemProjection
  12. let itemConflict1: ItemConflict
  13. let itemConflict2: ItemConflict
  14. let item: Item
  15. let itemHash: ItemHash
  16. const createProjector = () => new ItemConflictProjector(itemProjector)
  17. beforeEach(() => {
  18. itemProjection = {} as jest.Mocked<ItemProjection>
  19. itemProjector = {} as jest.Mocked<ProjectorInterface<Item, ItemProjection>>
  20. itemProjector.projectFull = jest.fn().mockReturnValue(itemProjection)
  21. item = {} as jest.Mocked<Item>
  22. itemHash = {} as jest.Mocked<ItemHash>
  23. itemConflict1 = {
  24. serverItem: item,
  25. type: ConflictType.ConflictingData,
  26. }
  27. itemConflict2 = {
  28. unsavedItem: itemHash,
  29. type: ConflictType.UuidConflict,
  30. }
  31. })
  32. it('should create a full projection of a server item conflict', async () => {
  33. expect(await createProjector().projectFull(itemConflict1)).toMatchObject({
  34. server_item: itemProjection,
  35. type: ConflictType.ConflictingData,
  36. })
  37. })
  38. it('should create a full projection of an unsaved item conflict', async () => {
  39. expect(await createProjector().projectFull(itemConflict2)).toMatchObject({
  40. unsaved_item: itemHash,
  41. type: 'uuid_conflict',
  42. })
  43. })
  44. it('should throw error on custom projection', async () => {
  45. let error = null
  46. try {
  47. await createProjector().projectCustom('test', itemConflict1)
  48. } catch (e) {
  49. error = e
  50. }
  51. expect((error as Error).message).toEqual('not implemented')
  52. })
  53. it('should throw error on simple projection', async () => {
  54. let error = null
  55. try {
  56. await createProjector().projectSimple(itemConflict1)
  57. } catch (e) {
  58. error = e
  59. }
  60. expect((error as Error).message).toEqual('not implemented')
  61. })
  62. })