PackUtilsTests.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const { expect } = require('chai')
  2. const { ObjectId } = require('mongodb')
  3. const { packsAreDuplicated } = require('../../../../app/js/util/PackUtils')
  4. const examplePack = {
  5. v: 12,
  6. meta: {
  7. user_id: '525e6018b53de7a920002545',
  8. start_ts: 1399130007228,
  9. end_ts: 1399130007228,
  10. },
  11. op: [
  12. {
  13. p: 2372,
  14. d: 'Test for a Subsection',
  15. },
  16. {
  17. p: 2372,
  18. i: 'Reviews and review terminology',
  19. },
  20. ],
  21. }
  22. const objectId1 = ObjectId('53650ba27e62ca78520d9814')
  23. const objectId2 = ObjectId('0b5a814a27e678520d92c536')
  24. describe('PackUtils', function () {
  25. describe('packsAreDuplicated()', function () {
  26. it('returns `false` when any of the packs is undefined', function () {
  27. const pack = { ...examplePack, _id: objectId1 }
  28. expect(packsAreDuplicated(pack, undefined)).to.be.false
  29. expect(packsAreDuplicated(undefined, pack)).to.be.false
  30. expect(packsAreDuplicated(undefined, undefined)).to.be.false
  31. })
  32. it('returns `true` for identical packs with same `_id`', function () {
  33. const pack1 = { ...examplePack, _id: objectId1 }
  34. const pack2 = { ...examplePack, _id: objectId1 }
  35. expect(packsAreDuplicated(pack1, pack2)).to.be.true
  36. })
  37. it('returns `true` for identical packs with different `_id`', function () {
  38. const pack1 = { ...examplePack, _id: objectId1 }
  39. const pack2 = { ...examplePack, _id: objectId2 }
  40. expect(packsAreDuplicated(pack1, pack2)).to.be.true
  41. })
  42. it('returns `false` for packs with different anidated properties', function () {
  43. const pack1 = { ...examplePack, _id: objectId1 }
  44. const pack2 = { ...examplePack, _id: 1 }
  45. pack2.op = [...pack2.op, { p: 2800, i: 'char' }]
  46. expect(packsAreDuplicated(pack1, pack2)).to.be.false
  47. })
  48. })
  49. })