mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 05:48:59 +08:00
feat: improve admin panel (#14180)
This commit is contained in:
@@ -28,22 +28,9 @@ export class MockTeamWorkspace extends Mocker<
|
||||
},
|
||||
});
|
||||
|
||||
const feature = await this.db.feature.findFirst({
|
||||
where: {
|
||||
name: Feature.TeamPlan,
|
||||
},
|
||||
});
|
||||
|
||||
if (!feature) {
|
||||
throw new Error(
|
||||
`Feature ${Feature.TeamPlan} does not exist in DB. You might forgot to run data-migration first.`
|
||||
);
|
||||
}
|
||||
|
||||
await this.db.workspaceFeature.create({
|
||||
data: {
|
||||
workspaceId: id,
|
||||
featureId: feature.id,
|
||||
reason: 'test',
|
||||
activated: true,
|
||||
name: Feature.TeamPlan,
|
||||
|
||||
@@ -27,23 +27,10 @@ export class MockUser extends Mocker<MockUserInput, MockedUser> {
|
||||
});
|
||||
|
||||
if (feature) {
|
||||
const featureRecord = await this.db.feature.findFirst({
|
||||
where: {
|
||||
name: feature,
|
||||
},
|
||||
});
|
||||
|
||||
if (!featureRecord) {
|
||||
throw new Error(
|
||||
`Feature ${feature} does not exist in DB. You might forgot to run data-migration first.`
|
||||
);
|
||||
}
|
||||
|
||||
const config = FeatureConfigs[feature];
|
||||
await this.db.userFeature.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
featureId: featureRecord.id,
|
||||
name: feature,
|
||||
type: config.type,
|
||||
reason: 'test',
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import ava, { TestFn } from 'ava';
|
||||
|
||||
import { FeatureType } from '../../models';
|
||||
import { FeatureModel } from '../../models/feature';
|
||||
import { createTestingModule, type TestingModule } from '../utils';
|
||||
|
||||
@@ -39,96 +38,3 @@ test('should throw if feature not found', async t => {
|
||||
message: 'Feature not_found_feature not found',
|
||||
});
|
||||
});
|
||||
|
||||
test('should throw if feature config in invalid', async t => {
|
||||
const { feature } = t.context;
|
||||
const freePlanFeature = await feature.get('free_plan_v1');
|
||||
|
||||
// @ts-expect-error internal
|
||||
await feature.db.feature.update({
|
||||
where: {
|
||||
id: freePlanFeature.id,
|
||||
},
|
||||
data: {
|
||||
configs: {
|
||||
...freePlanFeature.configs,
|
||||
memberLimit: 'invalid' as any,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await t.throwsAsync(feature.get('free_plan_v1'), {
|
||||
message: 'Invalid feature config for free_plan_v1',
|
||||
});
|
||||
});
|
||||
|
||||
// NOTE(@forehalo): backward compatibility
|
||||
// new version of feature config may introduce new field
|
||||
// this test means to ensure that the older version of AFFiNE Server can still read it
|
||||
test('should get feature if extra fields exist in feature config', async t => {
|
||||
const { feature } = t.context;
|
||||
const freePlanFeature = await feature.get('free_plan_v1');
|
||||
|
||||
// @ts-expect-error internal
|
||||
await feature.db.feature.update({
|
||||
where: {
|
||||
id: freePlanFeature.id,
|
||||
},
|
||||
data: {
|
||||
configs: {
|
||||
...freePlanFeature.configs,
|
||||
extraField: 'extraValue',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const freePlanFeature2 = await feature.get('free_plan_v1');
|
||||
|
||||
t.snapshot(freePlanFeature2.configs);
|
||||
});
|
||||
|
||||
test('should create feature', async t => {
|
||||
const { feature } = t.context;
|
||||
|
||||
// @ts-expect-error internal
|
||||
const newFeature = await feature.upsert(
|
||||
'new_feature' as any,
|
||||
{},
|
||||
FeatureType.Feature,
|
||||
1
|
||||
);
|
||||
|
||||
t.deepEqual(newFeature.configs, {});
|
||||
});
|
||||
|
||||
test('should update feature', async t => {
|
||||
const { feature } = t.context;
|
||||
const freePlanFeature = await feature.get('free_plan_v1');
|
||||
|
||||
// @ts-expect-error internal
|
||||
const newFreePlanFeature = await feature.upsert(
|
||||
'free_plan_v1',
|
||||
{
|
||||
...freePlanFeature.configs,
|
||||
memberLimit: 10,
|
||||
},
|
||||
FeatureType.Quota,
|
||||
1
|
||||
);
|
||||
|
||||
t.deepEqual(newFreePlanFeature.configs, {
|
||||
...freePlanFeature.configs,
|
||||
memberLimit: 10,
|
||||
});
|
||||
});
|
||||
|
||||
test('should throw if feature config is invalid when updating', async t => {
|
||||
const { feature } = t.context;
|
||||
await t.throwsAsync(
|
||||
// @ts-expect-error internal
|
||||
feature.upsert('free_plan_v1', {} as any, FeatureType.Quota, 1),
|
||||
{
|
||||
message: 'Invalid feature config for free_plan_v1',
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -295,7 +295,7 @@ test('should paginate users', async t => {
|
||||
)
|
||||
);
|
||||
|
||||
const users = await t.context.user.pagination(0, 10);
|
||||
const users = await t.context.user.list({ skip: 0, take: 10 });
|
||||
t.is(users.length, 10);
|
||||
t.deepEqual(
|
||||
users.map(user => user.email),
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { INestApplicationContext, LogLevel } from '@nestjs/common';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import whywhywhy from 'why-is-node-running';
|
||||
|
||||
import { RefreshFeatures0001 } from '../../data/migrations/0001-refresh-features';
|
||||
|
||||
export const TEST_LOG_LEVEL: LogLevel =
|
||||
(process.env.TEST_LOG_LEVEL as LogLevel) ?? 'fatal';
|
||||
|
||||
@@ -27,7 +24,6 @@ async function flushDB(client: PrismaClient) {
|
||||
export async function initTestingDB(context: INestApplicationContext) {
|
||||
const db = context.get(PrismaClient, { strict: false });
|
||||
await flushDB(db);
|
||||
await RefreshFeatures0001.up(db, context.get(ModuleRef));
|
||||
}
|
||||
|
||||
export async function sleep(ms: number) {
|
||||
|
||||
Reference in New Issue
Block a user