change.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict'
  2. const { expect } = require('chai')
  3. const core = require('..')
  4. const Change = core.Change
  5. const File = core.File
  6. const Operation = core.Operation
  7. describe('Change', function () {
  8. describe('findBlobHashes', function () {
  9. it('finds blob hashes from operations', function () {
  10. const blobHashes = new Set()
  11. const change = Change.fromRaw({
  12. operations: [],
  13. timestamp: '2015-03-05T12:03:53.035Z',
  14. authors: [null],
  15. })
  16. change.findBlobHashes(blobHashes)
  17. expect(blobHashes.size).to.equal(0)
  18. // AddFile with content doesn't have a hash.
  19. change.pushOperation(Operation.addFile('a.txt', File.fromString('a')))
  20. change.findBlobHashes(blobHashes)
  21. expect(blobHashes.size).to.equal(0)
  22. // AddFile with hash should give us a hash.
  23. change.pushOperation(
  24. Operation.addFile('b.txt', File.fromHash(File.EMPTY_FILE_HASH))
  25. )
  26. change.findBlobHashes(blobHashes)
  27. expect(blobHashes.size).to.equal(1)
  28. expect(blobHashes.has(File.EMPTY_FILE_HASH)).to.be.true
  29. })
  30. })
  31. describe('RestoreFileOrigin', function () {
  32. it('should convert to and from raw', function () {
  33. const origin = new core.RestoreFileOrigin(1, 'path', new Date())
  34. const raw = origin.toRaw()
  35. const newOrigin = core.Origin.fromRaw(raw)
  36. expect(newOrigin).to.eql(origin)
  37. })
  38. it('change should have a correct origin class', function () {
  39. const change = Change.fromRaw({
  40. operations: [],
  41. timestamp: '2015-03-05T12:03:53.035Z',
  42. authors: [null],
  43. origin: {
  44. kind: 'file-restore',
  45. version: 1,
  46. path: 'path',
  47. timestamp: '2015-03-05T12:03:53.035Z',
  48. },
  49. })
  50. expect(change.getOrigin()).to.be.an.instanceof(core.RestoreFileOrigin)
  51. })
  52. })
  53. })