change.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. })