KeybuilderTests.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const SandboxedModule = require('sandboxed-module')
  2. const modulePath = '../../../app/js/KeyBuilder.js'
  3. describe('LocalFileWriter', function() {
  4. let KeyBuilder
  5. const key = 'wombat/potato'
  6. beforeEach(function() {
  7. KeyBuilder = SandboxedModule.require(modulePath, {
  8. requires: {
  9. 'logger-sharelatex': {
  10. log() {},
  11. err() {}
  12. }
  13. }
  14. })
  15. })
  16. describe('cachedKey', function() {
  17. it('should add the format to the key', function() {
  18. const opts = { format: 'png' }
  19. const newKey = KeyBuilder.addCachingToKey(key, opts)
  20. newKey.should.equal(`${key}-converted-cache/format-png`)
  21. })
  22. it('should add the style to the key', function() {
  23. const opts = { style: 'thumbnail' }
  24. const newKey = KeyBuilder.addCachingToKey(key, opts)
  25. newKey.should.equal(`${key}-converted-cache/style-thumbnail`)
  26. })
  27. it('should add format first, then style', function() {
  28. const opts = {
  29. style: 'thumbnail',
  30. format: 'png'
  31. }
  32. const newKey = KeyBuilder.addCachingToKey(key, opts)
  33. newKey.should.equal(`${key}-converted-cache/format-png-style-thumbnail`)
  34. })
  35. })
  36. })