From d24458e4b01f8c31d67d0574eabebf76b3b12f74 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 9 Jun 2017 16:41:51 +0200 Subject: [PATCH] Fix the tests to work with the async migration --- www/drive/tests.js | 153 ++++++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 72 deletions(-) diff --git a/www/drive/tests.js b/www/drive/tests.js index a3181ee7c..ddc3b0fb7 100644 --- a/www/drive/tests.js +++ b/www/drive/tests.js @@ -109,24 +109,27 @@ define([ }] }; var fo = FO.init(files, config); - fo.fixFiles(); - if (files['CryptPad_RECENTPADS'] || !files.filesData) { - console.log("DRIVE1: migration from RECENTPADS to filesData failed"); - return cb(); - } - var fileKey = Object.keys(files.root.Folder2)[0]; - if (!fileKey) { return cb(); } - var fileId = files.root.Folder2[fileKey]; - var res = typeof fileId === "number" - && typeof files.filesData[fileId] === "object" - && files.filesData[fileId].filename === "FileName" - && typeof files.trash.DeletedF[1].element === "number" - && typeof files.filesData[files.trash.DeletedF[1].element] === "object" - && files.filesData[files.trash.DeletedF[1].element].filename === "DeletedF" - && typeof files.template[0] === "number" - && typeof files.filesData[files.template[0]] === "object" - && !files.filesData[files.template[0]].filename; - return cb(res); + var todo = function () { + fo.fixFiles(); + if (files['CryptPad_RECENTPADS'] || !files.filesData) { + console.log("DRIVE1: migration from RECENTPADS to filesData failed"); + return cb(); + } + var fileKey = Object.keys(files.root.Folder2)[0]; + if (!fileKey) { return cb(); } + var fileId = files.root.Folder2[fileKey]; + var res = typeof fileId === "number" + && typeof files.filesData[fileId] === "object" + && files.filesData[fileId].filename === "FileName" + && typeof files.trash.DeletedF[1].element === "number" + && typeof files.filesData[files.trash.DeletedF[1].element] === "object" + && files.filesData[files.trash.DeletedF[1].element].filename === "DeletedF" + && typeof files.template[0] === "number" + && typeof files.filesData[files.template[0]] === "object" + && !files.filesData[files.template[0]].filename; + return cb(res); + }; + fo.migrate(todo); }, "DRIVE1: migration and fixFiles without unsorted"); assert(function (cb) { @@ -153,33 +156,36 @@ define([ }] }; var fo = FO.init(files, config); - fo.fixFiles(); - if (files['CryptPad_RECENTPADS'] || !files.filesData) { - console.log("DRIVE2: migration from RECENTPADS to filesData failed"); - return cb(); - } - if (!files.template) { - console.log("DRIVE2: template is missing"); - return cb(); - } - if (files.unsorted) { - console.log("DRIVE2: unsorted not removed"); - return cb(); - } - var fileKey = Object.keys(files.root.Folder2)[0]; - var fileKey2 = Object.keys(files.root).filter(function (x) { - return typeof files.root[x] === "number"; - })[0]; - if (!fileKey || !fileKey2) { return cb(); } - var fileId = files.root.Folder2[fileKey]; - var fileId2 = files.root[fileKey2]; - var res = typeof fileId === "number" - && typeof files.filesData[fileId] === "object" - && files.filesData[fileId].filename === "FileName" - && typeof fileId2 === "number" - && typeof files.filesData[fileId2] === "object" - && !files.filesData[fileId2].filename; - return cb(res); + var todo = function () { + fo.fixFiles(); + if (files['CryptPad_RECENTPADS'] || !files.filesData) { + console.log("DRIVE2: migration from RECENTPADS to filesData failed"); + return cb(); + } + if (!files.template) { + console.log("DRIVE2: template is missing"); + return cb(); + } + if (files.unsorted) { + console.log("DRIVE2: unsorted not removed"); + return cb(); + } + var fileKey = Object.keys(files.root.Folder2)[0]; + var fileKey2 = Object.keys(files.root).filter(function (x) { + return typeof files.root[x] === "number"; + })[0]; + if (!fileKey || !fileKey2) { return cb(); } + var fileId = files.root.Folder2[fileKey]; + var fileId2 = files.root[fileKey2]; + var res = typeof fileId === "number" + && typeof files.filesData[fileId] === "object" + && files.filesData[fileId].filename === "FileName" + && typeof fileId2 === "number" + && typeof files.filesData[fileId2] === "object" + && !files.filesData[fileId2].filename; + return cb(res); + }; + fo.migrate(todo); }, "DRIVE2: migration and fixFiles with unsorted"); assert(function (cb) { @@ -204,33 +210,36 @@ define([ "CryptPad_RECENTPADS": [] }; var fo = FO.init(files, config); - fo.fixFiles(); - if (files['CryptPad_RECENTPADS'] || !files.filesData) { - console.log("DRIVE2: migration from RECENTPADS to filesData failed"); - return cb(); - } - var fileKey = Object.keys(files.root.Folder2)[0]; - var fileKey2 = Object.keys(files.trash.DeletedF[0].element)[0]; - if (!fileKey || !fileKey2) { return cb(); } - var fileId = files.root.Folder2[fileKey]; - var fileId2 = files.trash.DeletedF[0].element[fileKey2]; - var res = typeof fileId === "number" - && typeof files.filesData[fileId] === "object" - && files.filesData[fileId].filename === "FileName" - && files.filesData[fileId].href === href1 - && typeof files.trash.DeletedF[1].element === "number" - && typeof files.filesData[files.trash.DeletedF[1].element] === "object" - && files.filesData[files.trash.DeletedF[1].element].filename === "DeletedF" - && files.filesData[files.trash.DeletedF[1].element].href === href2 - && typeof files.template[0] === "number" - && typeof files.filesData[files.template[0]] === "object" - && !files.filesData[files.template[0]].filename - && files.filesData[files.template[0]].href === href3 - && typeof fileId2 === "number" - && typeof files.filesData[fileId2] === "object" - && files.filesData[fileId2].filename === "Trash" - && files.filesData[fileId2].href === href4; - return cb(res); + var todo = function () { + fo.fixFiles(); + if (files['CryptPad_RECENTPADS'] || !files.filesData) { + console.log("DRIVE2: migration from RECENTPADS to filesData failed"); + return cb(); + } + var fileKey = Object.keys(files.root.Folder2)[0]; + var fileKey2 = Object.keys(files.trash.DeletedF[0].element)[0]; + if (!fileKey || !fileKey2) { return cb(); } + var fileId = files.root.Folder2[fileKey]; + var fileId2 = files.trash.DeletedF[0].element[fileKey2]; + var res = typeof fileId === "number" + && typeof files.filesData[fileId] === "object" + && files.filesData[fileId].filename === "FileName" + && files.filesData[fileId].href === href1 + && typeof files.trash.DeletedF[1].element === "number" + && typeof files.filesData[files.trash.DeletedF[1].element] === "object" + && files.filesData[files.trash.DeletedF[1].element].filename === "DeletedF" + && files.filesData[files.trash.DeletedF[1].element].href === href2 + && typeof files.template[0] === "number" + && typeof files.filesData[files.template[0]] === "object" + && !files.filesData[files.template[0]].filename + && files.filesData[files.template[0]].href === href3 + && typeof fileId2 === "number" + && typeof files.filesData[fileId2] === "object" + && files.filesData[fileId2].filename === "Trash" + && files.filesData[fileId2].href === href4; + return cb(res); + }; + fo.migrate(todo); }, "DRIVE4: migration and fixFiles with a pad in trash not root"); // userObject Tests