overleaf/services/filestore/test/unit/js/KeybuilderTests.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-01-02 16:12:07 +00:00
const SandboxedModule = require('sandboxed-module')
2014-02-14 16:39:05 +00:00
const modulePath = '../../../app/js/KeyBuilder.js'
2014-02-14 16:39:05 +00:00
2020-08-10 16:01:12 +00:00
describe('KeybuilderTests', function () {
2020-01-02 16:12:07 +00:00
let KeyBuilder
const key = 'wombat/potato'
2020-08-10 16:01:12 +00:00
beforeEach(function () {
KeyBuilder = SandboxedModule.require(modulePath, {
2021-07-13 11:04:46 +00:00
requires: { '@overleaf/settings': {} },
})
})
2014-02-14 16:39:05 +00:00
2020-08-10 16:01:12 +00:00
describe('cachedKey', function () {
it('should add the format to the key', function () {
const opts = { format: 'png' }
2020-01-02 16:12:07 +00:00
const newKey = KeyBuilder.addCachingToKey(key, opts)
newKey.should.equal(`${key}-converted-cache/format-png`)
})
2014-02-14 16:39:05 +00:00
2020-08-10 16:01:12 +00:00
it('should add the style to the key', function () {
const opts = { style: 'thumbnail' }
2020-01-02 16:12:07 +00:00
const newKey = KeyBuilder.addCachingToKey(key, opts)
newKey.should.equal(`${key}-converted-cache/style-thumbnail`)
})
2014-02-14 16:39:05 +00:00
2020-08-10 16:01:12 +00:00
it('should add format first, then style', function () {
const opts = {
style: 'thumbnail',
2021-07-13 11:04:46 +00:00
format: 'png',
}
2020-01-02 16:12:07 +00:00
const newKey = KeyBuilder.addCachingToKey(key, opts)
newKey.should.equal(`${key}-converted-cache/format-png-style-thumbnail`)
})
})
})