history.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict'
  2. const { expect } = require('chai')
  3. const core = require('..')
  4. const Change = core.Change
  5. const File = core.File
  6. const History = core.History
  7. const Operation = core.Operation
  8. const Snapshot = core.Snapshot
  9. describe('History', function () {
  10. describe('findBlobHashes', function () {
  11. it('finds blob hashes from snapshot and changes', function () {
  12. const history = new History(new Snapshot(), [])
  13. const blobHashes = new Set()
  14. history.findBlobHashes(blobHashes)
  15. expect(blobHashes.size).to.equal(0)
  16. // Add a file with a hash to the snapshot.
  17. history.getSnapshot().addFile('foo', File.fromHash(File.EMPTY_FILE_HASH))
  18. history.findBlobHashes(blobHashes)
  19. expect(Array.from(blobHashes)).to.have.members([File.EMPTY_FILE_HASH])
  20. // Add a file with a hash to the changes.
  21. const testHash = 'a'.repeat(40)
  22. const change = Change.fromRaw({
  23. operations: [],
  24. timestamp: '2015-03-05T12:03:53.035Z',
  25. authors: [null],
  26. })
  27. change.pushOperation(Operation.addFile('bar', File.fromHash(testHash)))
  28. history.pushChanges([change])
  29. history.findBlobHashes(blobHashes)
  30. expect(Array.from(blobHashes)).to.have.members([
  31. File.EMPTY_FILE_HASH,
  32. testHash,
  33. ])
  34. })
  35. })
  36. })