mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
* fix: correct typedef for Document in helpers.mjs * add move-migrations codemod * update migration paths to use shared migrations directory * move migrations to shared location * fix: update Dockerfile and docker-compose.ci.yml to include migrations directory * feat: add migrations tool to workspaces in package.json * [monorepo] Fix order of docker ignore rules * [web] remove unused docker ignore file * [monorepo] replace old references to migrations folder * [server-ce] copy migrations from new place * [migrations] Inline web scripts Co-authored-by: Brian Gough <brian.gough@overleaf.com> * [migrations] move three web scripts over Co-authored-by: Brian Gough <brian.gough@overleaf.com> * [migrations] add missing collection Co-authored-by: Brian Gough <brian.gough@overleaf.com> * [migrations] remove lodash dependency Co-authored-by: Brian Gough <brian.gough@overleaf.com> * [migrations] avoid mongodb-legacy dependency Co-authored-by: Brian Gough <brian.gough@overleaf.com> * [monorepo] run migrations from tools/migrations Co-authored-by: Brian Gough <brian.gough@overleaf.com> * [migrations] simplify migration for adding gitBridge feature to users * [monorepo] run migrations from tests in all the services * [migrations] add Jenkins pipeline for linting/formatting * [monorepo] fixup running web migrations everywhere * [monorepo] trigger Jenkins builds on changes to mongo migrations * [migrations] add Jenkins pipeline for linting/formatting * [monorepo] build scripts: update devDependencies before deps scanning * [monorepo] build scripts: formerly depend on tools/migrations * [monorepo] run eslint on .mjs files * [migrations] enable more eslint rules and fix all the errors * [rake] fix migrations:list task --------- Co-authored-by: Jakob Ackermann <jakob.ackermann@overleaf.com> GitOrigin-RevId: 14cf69cc1b9405bbc75adbb9a000e555500e0614
209 lines
6.3 KiB
JavaScript
209 lines
6.3 KiB
JavaScript
import { expect } from 'chai'
|
|
import { exec } from 'node:child_process'
|
|
import mongodb from 'mongodb-legacy'
|
|
import UserHelper from './helpers/User.mjs'
|
|
|
|
const User = UserHelper.promises
|
|
|
|
const ObjectId = mongodb.ObjectId
|
|
|
|
describe('ConvertArchivedState', function () {
|
|
let userOne, userTwo, userThree, userFour
|
|
let projectOne, projectOneId
|
|
let projectTwo, projectTwoId
|
|
let projectThree, projectThreeId
|
|
let projectFour, projectFourId
|
|
let projectIdTrashed
|
|
let projectIdNotTrashed
|
|
let projectIdArchivedAndTrashed
|
|
let projectIdNotArchivedNotTrashed
|
|
|
|
beforeEach(async function () {
|
|
userOne = new User()
|
|
userTwo = new User()
|
|
userThree = new User()
|
|
userFour = new User()
|
|
await userOne.login()
|
|
await userTwo.login()
|
|
await userThree.login()
|
|
await userFour.login()
|
|
|
|
projectOneId = await userOne.createProject('old-archived-1', {
|
|
template: 'blank',
|
|
})
|
|
|
|
projectOne = await userOne.getProject(projectOneId)
|
|
projectOne.archived = true
|
|
projectOne.collaberator_refs.push(userTwo._id)
|
|
projectOne.tokenAccessReadOnly_refs.push(userThree._id)
|
|
|
|
await userOne.saveProject(projectOne)
|
|
|
|
projectTwoId = await userOne.createProject('old-archived-2', {
|
|
template: 'blank',
|
|
})
|
|
|
|
projectTwo = await userOne.getProject(projectTwoId)
|
|
projectTwo.archived = true
|
|
projectTwo.tokenAccessReadAndWrite_refs.push(userThree._id)
|
|
projectTwo.tokenAccessReadOnly_refs.push(userFour._id)
|
|
|
|
await userOne.saveProject(projectTwo)
|
|
|
|
projectThreeId = await userOne.createProject('already-new-archived', {
|
|
template: 'blank',
|
|
})
|
|
projectThree = await userOne.getProject(projectThreeId)
|
|
projectThree.archived = [
|
|
new ObjectId(userOne._id),
|
|
new ObjectId(userTwo._id),
|
|
new ObjectId(userFour._id),
|
|
]
|
|
projectThree.collaberator_refs.push(userTwo._id)
|
|
projectThree.tokenAccessReadOnly_refs.push(userFour._id)
|
|
|
|
await userOne.saveProject(projectThree)
|
|
|
|
projectFourId = await userOne.createProject('not-archived', {
|
|
template: 'blank',
|
|
})
|
|
projectFour = await userOne.getProject(projectFourId)
|
|
projectFour.archived = false
|
|
|
|
await userOne.saveProject(projectFour)
|
|
|
|
projectIdTrashed = await userOne.createProject('trashed', {
|
|
template: 'blank',
|
|
})
|
|
{
|
|
const p = await userOne.getProject(projectIdTrashed)
|
|
p.trashed = true
|
|
p.collaberator_refs.push(userTwo._id)
|
|
await userOne.saveProject(p)
|
|
}
|
|
|
|
projectIdNotTrashed = await userOne.createProject('not-trashed', {
|
|
template: 'blank',
|
|
})
|
|
{
|
|
const p = await userOne.getProject(projectIdNotTrashed)
|
|
p.trashed = false
|
|
p.collaberator_refs.push(userTwo._id)
|
|
await userOne.saveProject(p)
|
|
}
|
|
|
|
projectIdArchivedAndTrashed = await userOne.createProject('not-trashed', {
|
|
template: 'blank',
|
|
})
|
|
{
|
|
const p = await userOne.getProject(projectIdArchivedAndTrashed)
|
|
p.archived = true
|
|
p.trashed = true
|
|
p.collaberator_refs.push(userTwo._id)
|
|
await userOne.saveProject(p)
|
|
}
|
|
|
|
projectIdNotArchivedNotTrashed = await userOne.createProject(
|
|
'not-archived,not-trashed',
|
|
{
|
|
template: 'blank',
|
|
}
|
|
)
|
|
{
|
|
const p = await userOne.getProject(projectIdNotArchivedNotTrashed)
|
|
p.archived = false
|
|
p.trashed = false
|
|
p.collaberator_refs.push(userTwo._id)
|
|
await userOne.saveProject(p)
|
|
}
|
|
})
|
|
|
|
beforeEach(function (done) {
|
|
exec(
|
|
'cd ../../tools/migrations && east migrate --tag server-ce --force 20221111111111_ce_sp_convert_archived_state',
|
|
error => {
|
|
if (error) {
|
|
return done(error)
|
|
}
|
|
done()
|
|
}
|
|
)
|
|
})
|
|
|
|
describe('main method', function () {
|
|
it('should change a project archived boolean to an array', async function () {
|
|
projectOne = await userOne.getProject(projectOneId)
|
|
projectTwo = await userOne.getProject(projectTwoId)
|
|
expect(convertObjectIdsToStrings(projectOne.archived)).to.deep.equal([
|
|
userOne._id,
|
|
userTwo._id,
|
|
userThree._id,
|
|
])
|
|
|
|
expect(convertObjectIdsToStrings(projectTwo.archived)).to.deep.equal([
|
|
userOne._id,
|
|
userThree._id,
|
|
userFour._id,
|
|
])
|
|
expect(projectTwo.trashed).to.deep.equal([])
|
|
})
|
|
|
|
it('should not change the value of a project already archived with an array', async function () {
|
|
projectThree = await userOne.getProject(projectThreeId)
|
|
expect(convertObjectIdsToStrings(projectThree.archived)).to.deep.equal([
|
|
userOne._id,
|
|
userTwo._id,
|
|
userFour._id,
|
|
])
|
|
expect(projectThree.trashed).to.deep.equal([])
|
|
})
|
|
|
|
it('should change a none-archived project with a boolean value to an array', async function () {
|
|
projectFour = await userOne.getProject(projectFourId)
|
|
expect(convertObjectIdsToStrings(projectFour.archived)).to.deep.equal([])
|
|
expect(projectFour.trashed).to.deep.equal([])
|
|
})
|
|
|
|
it('should change a archived and trashed project with a boolean value to an array', async function () {
|
|
const p = await userOne.getProject(projectIdArchivedAndTrashed)
|
|
expect(convertObjectIdsToStrings(p.archived)).to.deep.equal([
|
|
userOne._id,
|
|
userTwo._id,
|
|
])
|
|
expect(convertObjectIdsToStrings(p.trashed)).to.deep.equal([
|
|
userOne._id,
|
|
userTwo._id,
|
|
])
|
|
})
|
|
|
|
it('should change a trashed project with a boolean value to an array', async function () {
|
|
const p = await userOne.getProject(projectIdTrashed)
|
|
expect(p.archived).to.not.exist
|
|
expect(convertObjectIdsToStrings(p.trashed)).to.deep.equal([
|
|
userOne._id,
|
|
userTwo._id,
|
|
])
|
|
})
|
|
|
|
it('should change a not-trashed project with a boolean value to an array', async function () {
|
|
const p = await userOne.getProject(projectIdNotTrashed)
|
|
expect(p.archived).to.not.exist
|
|
expect(convertObjectIdsToStrings(p.trashed)).to.deep.equal([])
|
|
})
|
|
|
|
it('should change a not-archived/not-trashed project with a boolean value to an array', async function () {
|
|
const p = await userOne.getProject(projectIdNotArchivedNotTrashed)
|
|
expect(p.archived).to.deep.equal([])
|
|
expect(p.trashed).to.deep.equal([])
|
|
})
|
|
})
|
|
|
|
function convertObjectIdsToStrings(ids) {
|
|
if (typeof ids === 'object') {
|
|
return ids.map(id => {
|
|
return id.toString()
|
|
})
|
|
}
|
|
}
|
|
})
|