Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Spoffy committed Jan 14, 2025
1 parent ca0ee2d commit af5f08d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/server/lib/ActiveDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<string> {
Expand Down

0 comments on commit af5f08d

Please sign in to comment.