Files
overleaf-cep/services/clsi/test/unit/js/ConversionOutputCleaner.test.js
Mathias Jakobsen 32da6548c8 Merge pull request #33277 from overleaf/mj-pandoc-clsi-two-step-download
[clsi] Use clsi-nginx for downloading pandoc exports

GitOrigin-RevId: b6013fae6f53c7af714634d700ceed491d724653
2026-05-08 08:09:18 +00:00

49 lines
1.4 KiB
JavaScript

import sinon from 'sinon'
import { vi, describe, it, beforeEach, afterEach } from 'vitest'
import Path from 'node:path'
const MODULE_PATH = Path.join(
import.meta.dirname,
'../../../app/js/ConversionOutputCleaner'
)
describe('ConversionOutputCleaner', function () {
beforeEach(async function (ctx) {
ctx.clock = sinon.useFakeTimers()
ctx.Settings = {
path: { outputDir: '/output' },
}
ctx.fs = {
rm: sinon.stub().resolves(),
}
ctx.logger = {
warn: sinon.stub(),
}
vi.doMock('node:fs/promises', () => ({ default: ctx.fs }))
vi.doMock('@overleaf/settings', () => ({ default: ctx.Settings }))
vi.doMock('@overleaf/logger', () => ({ default: ctx.logger }))
ctx.ConversionOutputCleaner = (await import(MODULE_PATH)).default
})
afterEach(function (ctx) {
ctx.clock.restore()
})
it('does not remove the directory before the TTL elapses', function (ctx) {
ctx.ConversionOutputCleaner.scheduleCleanup('test-conversion-id')
ctx.clock.tick(ctx.ConversionOutputCleaner.TTL_MS - 1)
sinon.assert.notCalled(ctx.fs.rm)
})
it('removes the conversion output directory once the TTL elapses', function (ctx) {
ctx.ConversionOutputCleaner.scheduleCleanup('test-conversion-id')
ctx.clock.tick(ctx.ConversionOutputCleaner.TTL_MS)
sinon.assert.calledWith(ctx.fs.rm, '/output/test-conversion-id', {
recursive: true,
force: true,
})
})
})