From 70f707cc397549bad62c26cea90496c8482706a1 Mon Sep 17 00:00:00 2001 From: Spoffy Date: Wed, 8 Jan 2025 01:50:57 +0000 Subject: [PATCH] WIP tests --- test/server/lib/ActiveDoc.ts | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/server/lib/ActiveDoc.ts b/test/server/lib/ActiveDoc.ts index 8babb27b96..4eff5b4aee 100644 --- a/test/server/lib/ActiveDoc.ts +++ b/test/server/lib/ActiveDoc.ts @@ -21,9 +21,12 @@ import * as _ from 'lodash'; import {resolve} from 'path'; import * as sinon from 'sinon'; import {createDocTools} from 'test/server/docTools'; +import {makeTestingFilesystemStoreSpec} from "test/server/lib/FilesystemAttachmentStore"; import * as testUtils from 'test/server/testUtils'; import {EnvironmentSnapshot} from 'test/server/testUtils'; import * as tmp from 'tmp'; +import { globalUploadSet } from "../../../app/server/lib/uploads"; +import { DocAttachmentsLocationSummary } from "../../../app/server/lib/AttachmentFileManager"; const execFileAsync = promisify(child_process.execFile); @@ -1145,6 +1148,41 @@ describe('ActiveDoc', function() { await activeDoc.shutdown(); } }); + + it('can transfer all attachments to external storage', async function() { + const uploadedFile = await testUtils.writeTmpFile("Hello world!"); + const stats = await fse.stat(uploadedFile); + const uploadId = globalUploadSet.registerUpload([ + { + absPath: uploadedFile, + origName: "HelloWorld.txt", + size: stats.size, + ext: ".txt", + }, + ], + null, + // No cleanup needed since it's a temporary file + () => {}, + null, + ); + + const storeSpec = await makeTestingFilesystemStoreSpec('filesystem'); + const storeProvider = new AttachmentStoreProvider([storeSpec], 'TEST-INSTALL-ID'); + + const activeDoc = new ActiveDoc(docTools.getDocManager(), 'transferToExternalTest', + storeProvider); + await activeDoc.createEmptyDoc(fakeSession); + await activeDoc.addAttachments(fakeSession, uploadId); + const locationSummary = await activeDoc.attachmentLocationSummary(); + assert.equal(locationSummary, DocAttachmentsLocationSummary.INTERNAL); + // Need to write a method to set the default store. + // `setDocumentSettings` - use getMetaTable and user actions + await activeDoc.startTransferringAllAttachmentsToDefaultStore(); + console.log(activeDoc.attachmentTransferStatus()); + console.log(await activeDoc.attachmentLocationSummary()); + assert.equal(activeDoc.attachmentTransferStatus().isRunning, true); + await activeDoc.shutdown(); + }); }); async function dumpTables(path: string): Promise {