feat!: unified migration logic in server electron, and browser (#4079)

Co-authored-by: Mirone <Saul-Mirone@outlook.com>
This commit is contained in:
Alex Yang
2023-09-06 00:44:53 -07:00
committed by GitHub
parent 925c18300f
commit 1b6a78cd00
61 changed files with 10776 additions and 10267 deletions
+70 -1
View File
@@ -1,15 +1,27 @@
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { test } from '@affine-test/kit/playwright';
import {
createRandomUser,
deleteUser,
enableCloudWorkspace,
getLoginCookie,
loginUser,
runPrisma,
} from '@affine-test/kit/utils/cloud';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
import { coreUrl } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
let user: {
id: string;
name: string;
email: string;
password: string;
@@ -40,6 +52,63 @@ test.afterEach(async () => {
});
test.describe('basic', () => {
test('migration', async ({ page, browser }) => {
let workspaceId: string;
{
// create the old cloud workspace in another browser
const context = await browser.newContext();
const page = await context.newPage();
await loginUser(page, user.email);
await page.reload();
await createLocalWorkspace(
{
name: 'test',
},
page
);
await enableCloudWorkspace(page);
await clickNewPageButton(page);
await waitForEditorLoad(page);
// http://localhost:8080/workspace/2bc0b6c8-f68d-4dd3-98a8-be746754f9e1/xxx
workspaceId = page.url().split('/')[4];
await runPrisma(async client => {
const sqls = (
await readFile(
resolve(__dirname, 'fixtures', '0.9.0-canary.9-snapshots.sql'),
'utf-8'
)
)
.replaceAll('2bc0b6c8-f68d-4dd3-98a8-be746754f9e1', workspaceId)
.split('\n');
await client.snapshot.deleteMany({
where: {
workspaceId,
},
});
for (const sql of sqls) {
await client.$executeRawUnsafe(sql);
}
});
await page.close();
}
await page.reload();
await page.waitForTimeout(1000);
await page.goto(`${coreUrl}/workspace/${workspaceId}/all`);
await page.getByTestId('upgrade-workspace').click();
await expect(page.getByText('Done, please refresh the page.')).toBeVisible({
timeout: 60000,
});
await page.goto(
`${coreUrl}/workspace/${workspaceId}/gc5FeppNDv-hello-world`
);
await waitForEditorLoad(page);
await clickEdgelessModeButton(page);
await expect(page.locator('affine-edgeless-page')).toBeVisible({
timeout: 1000,
});
});
test('can see and change email and password in setting panel', async ({
page,
}) => {