mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Convert tests to ESM
GitOrigin-RevId: 03bd4db8cddc548706439edd7f6db0bc3e7ed9d3
This commit is contained in:
@@ -1,26 +1,29 @@
|
||||
const { expect } = require('chai')
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { ObjectId } = require('mongodb-legacy')
|
||||
const sinon = require('sinon')
|
||||
import { vi, expect } from 'vitest'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
import sinon from 'sinon'
|
||||
|
||||
const { ObjectId } = mongodb
|
||||
|
||||
const MODULE_PATH =
|
||||
'../../../../app/src/Features/Project/FolderStructureBuilder'
|
||||
|
||||
describe('FolderStructureBuilder', function () {
|
||||
beforeEach(function () {
|
||||
this.FolderStructureBuilder = SandboxedModule.require(MODULE_PATH, {
|
||||
requires: { 'mongodb-legacy': { ObjectId } },
|
||||
})
|
||||
beforeEach(async function (ctx) {
|
||||
vi.doMock('mongodb-legacy', () => ({
|
||||
default: { ObjectId },
|
||||
}))
|
||||
|
||||
ctx.FolderStructureBuilder = (await import(MODULE_PATH)).default
|
||||
})
|
||||
|
||||
describe('buildFolderStructure', function () {
|
||||
describe('when given no documents at all', function () {
|
||||
beforeEach(function () {
|
||||
this.result = this.FolderStructureBuilder.buildFolderStructure([], [])
|
||||
beforeEach(function (ctx) {
|
||||
ctx.result = ctx.FolderStructureBuilder.buildFolderStructure([], [])
|
||||
})
|
||||
|
||||
it('returns an empty root folder', function () {
|
||||
sinon.assert.match(this.result, {
|
||||
it('returns an empty root folder', function (ctx) {
|
||||
sinon.assert.match(ctx.result, {
|
||||
_id: sinon.match.instanceOf(ObjectId),
|
||||
name: 'rootFolder',
|
||||
folders: [],
|
||||
@@ -31,7 +34,7 @@ describe('FolderStructureBuilder', function () {
|
||||
})
|
||||
|
||||
describe('when given documents and files', function () {
|
||||
beforeEach(function () {
|
||||
beforeEach(function (ctx) {
|
||||
const docUploads = [
|
||||
{ path: '/main.tex', doc: { _id: 'doc-1', name: 'main.tex' } },
|
||||
{ path: '/foo/other.tex', doc: { _id: 'doc-2', name: 'other.tex' } },
|
||||
@@ -46,14 +49,14 @@ describe('FolderStructureBuilder', function () {
|
||||
{ path: '/foo/bbb.jpg', file: { _id: 'file-2', name: 'bbb.jpg' } },
|
||||
{ path: '/bar/ccc.jpg', file: { _id: 'file-3', name: 'ccc.jpg' } },
|
||||
]
|
||||
this.result = this.FolderStructureBuilder.buildFolderStructure(
|
||||
ctx.result = ctx.FolderStructureBuilder.buildFolderStructure(
|
||||
docUploads,
|
||||
fileUploads
|
||||
)
|
||||
})
|
||||
|
||||
it('returns a full folder structure', function () {
|
||||
sinon.assert.match(this.result, {
|
||||
it('returns a full folder structure', function (ctx) {
|
||||
sinon.assert.match(ctx.result, {
|
||||
_id: sinon.match.instanceOf(ObjectId),
|
||||
name: 'rootFolder',
|
||||
docs: [{ _id: 'doc-1', name: 'main.tex' }],
|
||||
@@ -98,13 +101,13 @@ describe('FolderStructureBuilder', function () {
|
||||
})
|
||||
|
||||
describe('when given duplicate files', function () {
|
||||
it('throws an error', function () {
|
||||
it('throws an error', function (ctx) {
|
||||
const docUploads = [
|
||||
{ path: '/foo/doc.tex', doc: { _id: 'doc-1', name: 'doc.tex' } },
|
||||
{ path: '/foo/doc.tex', doc: { _id: 'doc-2', name: 'doc.tex' } },
|
||||
]
|
||||
expect(() =>
|
||||
this.FolderStructureBuilder.buildFolderStructure(docUploads, [])
|
||||
ctx.FolderStructureBuilder.buildFolderStructure(docUploads, [])
|
||||
).to.throw()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user