feat(server): enable share og information for docs (#7794)

This commit is contained in:
forehalo
2024-09-10 04:03:52 +00:00
parent 34eac4c24e
commit 0add8917f9
24 changed files with 449 additions and 40 deletions

View File

@@ -14,7 +14,13 @@ const test = ava as TestFn<{
test.before('start app', async t => {
// @ts-expect-error override
AFFiNE.flavor = { type: 'graphql', graphql: true, sync: false };
AFFiNE.flavor = {
type: 'graphql',
allinone: false,
graphql: true,
sync: false,
renderer: false,
} satisfies typeof AFFiNE.flavor;
const { app } = await createTestingApp({
imports: [buildAppModule()],
});

View File

@@ -0,0 +1,39 @@
import type { INestApplication } from '@nestjs/common';
import type { TestFn } from 'ava';
import ava from 'ava';
import request from 'supertest';
import { buildAppModule } from '../../src/app.module';
import { createTestingApp } from '../utils';
const test = ava as TestFn<{
app: INestApplication;
}>;
test.before('start app', async t => {
// @ts-expect-error override
AFFiNE.flavor = {
type: 'renderer',
allinone: false,
graphql: false,
sync: false,
renderer: true,
} satisfies typeof AFFiNE.flavor;
const { app } = await createTestingApp({
imports: [buildAppModule()],
});
t.context.app = app;
});
test.after.always(async t => {
await t.context.app.close();
});
test('should init app', async t => {
const res = await request(t.context.app.getHttpServer())
.get('/info')
.expect(200);
t.is(res.body.flavor, 'renderer');
});

View File

@@ -12,7 +12,13 @@ const test = ava as TestFn<{
test.before('start app', async t => {
// @ts-expect-error override
AFFiNE.flavor = { type: 'sync', graphql: false, sync: true };
AFFiNE.flavor = {
type: 'sync',
allinone: false,
graphql: false,
sync: true,
renderer: false,
} satisfies typeof AFFiNE.flavor;
const { app } = await createTestingApp({
imports: [buildAppModule()],
});

View File

@@ -1,5 +1,6 @@
import { mock } from 'node:test';
import { ScheduleModule } from '@nestjs/schedule';
import { TestingModule } from '@nestjs/testing';
import { PrismaClient } from '@prisma/client';
import test from 'ava';
@@ -20,7 +21,7 @@ test.before(async () => {
toFake: ['setInterval'],
});
m = await createTestingModule({
imports: [DocStorageModule],
imports: [ScheduleModule.forRoot(), DocStorageModule],
});
db = m.get(PrismaClient);

View File

@@ -52,7 +52,7 @@ class TestResolver {
}
@Public()
@Controller()
@Controller('/')
class TestController {
@Get('/ok')
ok() {
@@ -154,6 +154,7 @@ test('should be able to handle known user error in http request', async t => {
const res = await request(t.context.app.getHttpServer())
.get('/throw-known-error')
.expect(HttpStatus.FORBIDDEN);
t.is(res.body.message, 'You do not have permission to access this resource.');
t.is(res.body.name, 'ACCESS_DENIED');
t.true(t.context.logger.error.notCalled);