mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 03:49:56 +08:00
refactor(electron): nestjsfy
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
import {
|
||||
AFFiNEUpdateProvider,
|
||||
availableForMyPlatformAndInstaller,
|
||||
} from '../../src/main/updater/affine-update-provider';
|
||||
} from '../../src/entries/main/updater/affine-update-provider';
|
||||
import { MockedAppAdapter, MockedUpdater } from './mocks';
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { universalId } from '@affine/nbstore';
|
||||
import fs from 'fs-extra';
|
||||
import { v4 } from 'uuid';
|
||||
import { afterAll, afterEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
const tmpDir = path.join(__dirname, 'tmp');
|
||||
const appDataPath = path.join(tmpDir, 'app-data');
|
||||
|
||||
vi.doMock('@affine/electron/helper/db/ensure-db', () => ({
|
||||
ensureSQLiteDB: async () => ({
|
||||
destroy: () => {},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.doMock('@affine/electron/helper/main-rpc', () => ({
|
||||
mainRPC: {
|
||||
getPath: async () => appDataPath,
|
||||
},
|
||||
}));
|
||||
|
||||
afterEach(async () => {
|
||||
try {
|
||||
await fs.remove(tmpDir);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
vi.doUnmock('@affine/electron/helper/main-rpc');
|
||||
});
|
||||
|
||||
describe('workspace db management', () => {
|
||||
test('trash workspace', async () => {
|
||||
const { trashWorkspace } = await import(
|
||||
'@affine/electron/helper/workspace/handlers'
|
||||
);
|
||||
const workspaceId = v4();
|
||||
const workspacePath = path.join(
|
||||
appDataPath,
|
||||
'workspaces',
|
||||
'local',
|
||||
workspaceId
|
||||
);
|
||||
await fs.ensureDir(workspacePath);
|
||||
await trashWorkspace(
|
||||
universalId({ peer: 'local', type: 'workspace', id: workspaceId })
|
||||
);
|
||||
expect(await fs.pathExists(workspacePath)).toBe(false);
|
||||
// removed workspace will be moved to deleted-workspaces
|
||||
expect(
|
||||
await fs.pathExists(
|
||||
path.join(appDataPath, 'deleted-workspaces', workspaceId)
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('delete workspace', async () => {
|
||||
const { deleteWorkspace } = await import(
|
||||
'@affine/electron/helper/workspace/handlers'
|
||||
);
|
||||
const workspaceId = v4();
|
||||
const workspacePath = path.join(
|
||||
appDataPath,
|
||||
'workspaces',
|
||||
'local',
|
||||
workspaceId
|
||||
);
|
||||
await fs.ensureDir(workspacePath);
|
||||
await deleteWorkspace(
|
||||
universalId({ peer: 'local', type: 'workspace', id: workspaceId })
|
||||
);
|
||||
expect(await fs.pathExists(workspacePath)).toBe(false);
|
||||
// deleted workspace will remove it permanently
|
||||
expect(
|
||||
await fs.pathExists(
|
||||
path.join(appDataPath, 'deleted-workspaces', workspaceId)
|
||||
)
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user