mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 17:39:55 +08:00
feat(server): add compatibility field (#4022)
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
||||
import { waitEditorLoad } from '@affine-test/kit/utils/page-logic';
|
||||
import { clickSideBarCurrentWorkspaceBanner } from '@affine-test/kit/utils/sidebar';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { hash } from '@node-rs/argon2';
|
||||
import type { BrowserContext, Cookie } from '@playwright/test';
|
||||
import type { BrowserContext, Cookie, Page } from '@playwright/test';
|
||||
import { z } from 'zod';
|
||||
|
||||
export async function getLoginCookie(
|
||||
context: BrowserContext
|
||||
@@ -10,12 +14,20 @@ export async function getLoginCookie(
|
||||
);
|
||||
}
|
||||
|
||||
export async function createRandomUser() {
|
||||
const cloudUserSchema = z.object({
|
||||
name: z.string(),
|
||||
email: z.string().email(),
|
||||
password: z.string(),
|
||||
});
|
||||
|
||||
export type CloudUser = z.infer<typeof cloudUserSchema>;
|
||||
|
||||
export async function createRandomUser(): Promise<CloudUser> {
|
||||
const user = {
|
||||
name: faker.internet.userName(),
|
||||
email: faker.internet.email().toLowerCase(),
|
||||
password: '123456',
|
||||
};
|
||||
} satisfies CloudUser;
|
||||
const {
|
||||
PrismaClient,
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
@@ -31,11 +43,13 @@ export async function createRandomUser() {
|
||||
});
|
||||
await client.$disconnect();
|
||||
|
||||
return client.user.findUnique({
|
||||
const result = await client.user.findUnique({
|
||||
where: {
|
||||
email: user.email,
|
||||
},
|
||||
});
|
||||
cloudUserSchema.parse(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteUser(email: string) {
|
||||
@@ -52,3 +66,41 @@ export async function deleteUser(email: string) {
|
||||
});
|
||||
await client.$disconnect();
|
||||
}
|
||||
|
||||
export async function loginUser(
|
||||
page: Page,
|
||||
user: CloudUser,
|
||||
config?: {
|
||||
beforeLogin?: () => Promise<void>;
|
||||
afterLogin?: () => Promise<void>;
|
||||
}
|
||||
) {
|
||||
await openHomePage(page);
|
||||
await waitEditorLoad(page);
|
||||
|
||||
await clickSideBarCurrentWorkspaceBanner(page);
|
||||
await page.getByTestId('cloud-signin-button').click({
|
||||
delay: 200,
|
||||
});
|
||||
await page.getByPlaceholder('Enter your email address').type(user.email, {
|
||||
delay: 50,
|
||||
});
|
||||
await page.getByTestId('continue-login-button').click({
|
||||
delay: 200,
|
||||
});
|
||||
await page.getByTestId('sign-in-with-password').click({
|
||||
delay: 200,
|
||||
});
|
||||
await page.getByTestId('password-input').type('123456', {
|
||||
delay: 50,
|
||||
});
|
||||
if (config?.beforeLogin) {
|
||||
await config.beforeLogin();
|
||||
}
|
||||
await page.waitForTimeout(200);
|
||||
await page.getByTestId('sign-in-button').click();
|
||||
await page.waitForTimeout(200);
|
||||
if (config?.afterLogin) {
|
||||
await config.afterLogin();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user