mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
[web] Add tests on find_malformed_filetrees and fix_malformed_filetree, partially fix fix_malformed_filetree (#23120)
* Create tests on find_malformed_filetrees and fix_malformed_filetrees
* Remove lines that are making fix_malformed_filetree fail
These lines are causing errors such as
```
Missing file hash: 586846800000000000000000/5891271c0000000000000000 (rootFolder.0.folders.2.fileRefs.7.hash)
SaaS: likely needs filestore restore
Server Pro: please reach out to support
```
* Add snapshots of projects after fix_malformed_filetree
* Set `WRITE_SNAPSHOT` as false
* Make `deleteProjectsRecordId0` constant
* Ignore duplicated ID errors in CreateMalformedFileTrees.mjs
* Move snapshots to directory folder
* Remove unnecessary code
* Update tests to cover use cases from the scripts
* Fix: Use `new ObjectId(projectId)` instead of the string in mongo queries
* Fix: Query `rootFolder: []` to fix more than `rootFolder: { $size: 0 }`
* Remove/rename files from first draft
* Remove empty strings from expects in unrelated tests, now that `filterOutput` removes them
* Add missing `expectFixStdout` to tests
* misc: rename test util to strId
* Add "well formed filetrees" to test cases
* Use `wellFormed` variable to remove some duplication
* Update tests:
- check Missing file hash path
- remove test on string/numbers as array items
* Add test "bug: shifted arrays in filetree"
* Rename `wellFormedFile` to `wellFormedFolder`
* Fix name of the root folder to `'rootFolder'`, not `'untitled'`
GitOrigin-RevId: dc098bb7ad3ca441fe2bb72b5f5f0e3bcedbdf67
This commit is contained in:
@@ -140,7 +140,10 @@ function parentPath(path) {
|
||||
*/
|
||||
async function fixRootFolder(projectId) {
|
||||
const result = await db.projects.updateOne(
|
||||
{ _id: projectId, rootFolder: [] },
|
||||
{
|
||||
_id: new ObjectId(projectId),
|
||||
rootFolder: { $size: 0 },
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
rootFolder: [
|
||||
@@ -163,7 +166,7 @@ async function fixRootFolder(projectId) {
|
||||
*/
|
||||
async function removeNulls(projectId, path) {
|
||||
const result = await db.projects.updateOne(
|
||||
{ _id: projectId, [path]: { $type: 'array' } },
|
||||
{ _id: new ObjectId(projectId), [path]: { $type: 'array' } },
|
||||
{ $pull: { [path]: null } }
|
||||
)
|
||||
return result.modifiedCount
|
||||
@@ -174,7 +177,7 @@ async function removeNulls(projectId, path) {
|
||||
*/
|
||||
async function fixArray(projectId, path) {
|
||||
const result = await db.projects.updateOne(
|
||||
{ _id: projectId, [path]: { $not: { $type: 'array' } } },
|
||||
{ _id: new ObjectId(projectId), [path]: { $not: { $type: 'array' } } },
|
||||
{ $set: { [path]: [] } }
|
||||
)
|
||||
return result.modifiedCount
|
||||
@@ -185,7 +188,7 @@ async function fixArray(projectId, path) {
|
||||
*/
|
||||
async function fixFolderId(projectId, path) {
|
||||
const result = await db.projects.updateOne(
|
||||
{ _id: projectId, [path]: { $exists: false } },
|
||||
{ _id: new ObjectId(projectId), [path]: { $exists: false } },
|
||||
{ $set: { [path]: new ObjectId() } }
|
||||
)
|
||||
return result.modifiedCount
|
||||
@@ -196,7 +199,7 @@ async function fixFolderId(projectId, path) {
|
||||
*/
|
||||
async function removeElementsWithoutIds(projectId, path) {
|
||||
const result = await db.projects.updateOne(
|
||||
{ _id: projectId, [path]: { $type: 'array' } },
|
||||
{ _id: new ObjectId(projectId), [path]: { $type: 'array' } },
|
||||
{ $pull: { [path]: { _id: null } } }
|
||||
)
|
||||
return result.modifiedCount
|
||||
@@ -207,15 +210,16 @@ async function removeElementsWithoutIds(projectId, path) {
|
||||
*/
|
||||
async function fixName(projectId, path) {
|
||||
const project = await db.projects.findOne(
|
||||
{ _id: projectId },
|
||||
{ _id: new ObjectId(projectId) },
|
||||
{ projection: { rootFolder: 1 } }
|
||||
)
|
||||
const arrayPath = parentPath(parentPath(path))
|
||||
const array = ProjectLocator.findElementByMongoPath(project, arrayPath)
|
||||
const existingNames = new Set(array.map(x => x.name))
|
||||
const name = findUniqueName(existingNames)
|
||||
const name =
|
||||
path === 'rootFolder.0.name' ? 'rootFolder' : findUniqueName(existingNames)
|
||||
const result = await db.projects.updateOne(
|
||||
{ _id: projectId, [path]: { $in: [null, ''] } },
|
||||
{ _id: new ObjectId(projectId), [path]: { $in: [null, ''] } },
|
||||
{ $set: { [path]: name } }
|
||||
)
|
||||
return result.modifiedCount
|
||||
|
||||
Reference in New Issue
Block a user