mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +08:00
feat(server): add compatibility field (#4022)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
|
||||
import pkg from '../package.json' assert { type: 'json' };
|
||||
|
||||
@Controller('/')
|
||||
export class AppController {
|
||||
@Get()
|
||||
hello() {
|
||||
info() {
|
||||
const version = AFFiNE.version;
|
||||
return {
|
||||
message: `AFFiNE GraphQL server: ${pkg.version}`,
|
||||
compatibility: version,
|
||||
message: `AFFiNE ${version} Server`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { INestApplication, LoggerService } from '@nestjs/common';
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
// @ts-expect-error graphql-upload is not typed
|
||||
@@ -10,28 +10,6 @@ import type { TokenType } from '../modules/auth';
|
||||
import type { UserType } from '../modules/users';
|
||||
import type { InvitationType, WorkspaceType } from '../modules/workspaces';
|
||||
|
||||
export class NestDebugLogger implements LoggerService {
|
||||
log(message: string): any {
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
error(message: string, trace: string): any {
|
||||
console.error(message, trace);
|
||||
}
|
||||
|
||||
warn(message: string): any {
|
||||
console.warn(message);
|
||||
}
|
||||
|
||||
debug(message: string): any {
|
||||
console.debug(message);
|
||||
}
|
||||
|
||||
verbose(message: string): any {
|
||||
console.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
const gql = '/graphql';
|
||||
|
||||
async function signUp(
|
||||
|
||||
@@ -3,10 +3,9 @@ import {
|
||||
createRandomUser,
|
||||
deleteUser,
|
||||
getLoginCookie,
|
||||
loginUser,
|
||||
} from '@affine-test/kit/utils/cloud';
|
||||
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 { expect } from '@playwright/test';
|
||||
|
||||
let user: {
|
||||
@@ -25,38 +24,21 @@ test.afterEach(async () => {
|
||||
await deleteUser(user.email);
|
||||
});
|
||||
|
||||
test('server exist', async ({ page }) => {
|
||||
await openHomePage(page);
|
||||
await waitEditorLoad(page);
|
||||
|
||||
test('server exist', async () => {
|
||||
const json = await (await fetch('http://localhost:3010')).json();
|
||||
expect(json.message).toMatch(/^AFFiNE GraphQL server/);
|
||||
expect(json.compatibility).toMatch(/[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?/);
|
||||
});
|
||||
|
||||
test('enable cloud success', async ({ page, context }) => {
|
||||
await page.goto('http://localhost:8080');
|
||||
await page.waitForSelector('v-line');
|
||||
|
||||
await clickSideBarCurrentWorkspaceBanner(page);
|
||||
await page.getByTestId('cloud-signin-button').click({
|
||||
delay: 200,
|
||||
await loginUser(page, user, {
|
||||
beforeLogin: async () => {
|
||||
expect(await getLoginCookie(context)).toBeUndefined();
|
||||
},
|
||||
afterLogin: async () => {
|
||||
expect(await getLoginCookie(context)).toBeTruthy();
|
||||
await page.reload();
|
||||
await waitEditorLoad(page);
|
||||
expect(await getLoginCookie(context)).toBeTruthy();
|
||||
},
|
||||
});
|
||||
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,
|
||||
});
|
||||
expect(await getLoginCookie(context)).toBeUndefined();
|
||||
await page.getByTestId('sign-in-button').click();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.reload();
|
||||
await waitEditorLoad(page);
|
||||
expect(await getLoginCookie(context)).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -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