|
@@ -6,7 +6,8 @@ import {
|
|
|
TestDataFactory
|
|
TestDataFactory
|
|
|
} from '../utils/integration-test-db';
|
|
} from '../utils/integration-test-db';
|
|
|
import { UserEntityMt, UserServiceMt } from '@d8d/user-module-mt';
|
|
import { UserEntityMt, UserServiceMt } from '@d8d/user-module-mt';
|
|
|
-import { unifiedAdvertisementAdminRoutes, unifiedAdvertisementTypeAdminRoutes, unifiedAdvertisementRoutes, unifiedAdvertisementTypeRoutes } from '@d8d/unified-advertisements-module';
|
|
|
|
|
|
|
+// 导入server包的api以确保数据源初始化,同时获取统一广告路由的类型
|
|
|
|
|
+import { adminUnifiedAdvertisementApiRoutes, adminUnifiedAdvertisementTypeApiRoutes, advertisementApiRoutes, advertisementTypeApiRoutes } from '../../src/api';
|
|
|
import { AuthService } from '@d8d/auth-module-mt';
|
|
import { AuthService } from '@d8d/auth-module-mt';
|
|
|
import { UnifiedAdvertisement, UnifiedAdvertisementType } from '@d8d/unified-advertisements-module';
|
|
import { UnifiedAdvertisement, UnifiedAdvertisementType } from '@d8d/unified-advertisements-module';
|
|
|
|
|
|
|
@@ -14,10 +15,10 @@ import { UnifiedAdvertisement, UnifiedAdvertisementType } from '@d8d/unified-adv
|
|
|
setupIntegrationDatabaseHooks()
|
|
setupIntegrationDatabaseHooks()
|
|
|
|
|
|
|
|
describe('统一广告管理员权限集成测试', () => {
|
|
describe('统一广告管理员权限集成测试', () => {
|
|
|
- let adminClient: ReturnType<typeof testClient<typeof unifiedAdvertisementAdminRoutes>>;
|
|
|
|
|
- let adminTypeClient: ReturnType<typeof testClient<typeof unifiedAdvertisementTypeAdminRoutes>>;
|
|
|
|
|
- let userClient: ReturnType<typeof testClient<typeof unifiedAdvertisementRoutes>>;
|
|
|
|
|
- let userTypeClient: ReturnType<typeof testClient<typeof unifiedAdvertisementTypeRoutes>>;
|
|
|
|
|
|
|
+ let adminClient: ReturnType<typeof testClient<typeof adminUnifiedAdvertisementApiRoutes>>['api']['v1']['admin']['unified-advertisements'];
|
|
|
|
|
+ let adminTypeClient: ReturnType<typeof testClient<typeof adminUnifiedAdvertisementTypeApiRoutes>>['api']['v1']['admin']['unified-advertisement-types'];
|
|
|
|
|
+ let userClient: ReturnType<typeof testClient<typeof advertisementApiRoutes>>['api']['v1']['advertisements'];
|
|
|
|
|
+ let userTypeClient: ReturnType<typeof testClient<typeof advertisementTypeApiRoutes>>['api']['v1']['advertisement-types'];
|
|
|
let authService: AuthService;
|
|
let authService: AuthService;
|
|
|
let userService: UserServiceMt;
|
|
let userService: UserServiceMt;
|
|
|
let superAdminToken: string;
|
|
let superAdminToken: string;
|
|
@@ -25,11 +26,11 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
let tenantUserToken: string;
|
|
let tenantUserToken: string;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
beforeEach(async () => {
|
|
|
- // 创建测试客户端
|
|
|
|
|
- adminClient = testClient(unifiedAdvertisementAdminRoutes);
|
|
|
|
|
- adminTypeClient = testClient(unifiedAdvertisementTypeAdminRoutes);
|
|
|
|
|
- userClient = testClient(unifiedAdvertisementRoutes);
|
|
|
|
|
- userTypeClient = testClient(unifiedAdvertisementTypeRoutes);
|
|
|
|
|
|
|
+ // 创建测试客户端 - 使用server包注册后的路由
|
|
|
|
|
+ adminClient = testClient(adminUnifiedAdvertisementApiRoutes).api.v1.admin['unified-advertisements'];
|
|
|
|
|
+ adminTypeClient = testClient(adminUnifiedAdvertisementTypeApiRoutes).api.v1.admin['unified-advertisement-types'];
|
|
|
|
|
+ userClient = testClient(advertisementApiRoutes).api.v1.advertisements;
|
|
|
|
|
+ userTypeClient = testClient(advertisementTypeApiRoutes).api.v1['advertisement-types'];
|
|
|
|
|
|
|
|
// 获取数据源
|
|
// 获取数据源
|
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
@@ -78,7 +79,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
|
|
|
|
|
describe('管理员广告API权限控制', () => {
|
|
describe('管理员广告API权限控制', () => {
|
|
|
it('超级管理员(ID=1)应该能访问管理员广告列表API', async () => {
|
|
it('超级管理员(ID=1)应该能访问管理员广告列表API', async () => {
|
|
|
- const response = await adminClient.$get({
|
|
|
|
|
|
|
+ const response = await adminClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|
|
@@ -95,7 +96,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('普通管理员(ID>1)不应该能访问管理员广告列表API', async () => {
|
|
it('普通管理员(ID>1)不应该能访问管理员广告列表API', async () => {
|
|
|
- const response = await adminClient.$get({
|
|
|
|
|
|
|
+ const response = await adminClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${regularUserToken}`,
|
|
'Authorization': `Bearer ${regularUserToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|
|
@@ -108,7 +109,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('普通租户用户(tenantId>1)不应该能访问管理员广告列表API', async () => {
|
|
it('普通租户用户(tenantId>1)不应该能访问管理员广告列表API', async () => {
|
|
|
- const response = await adminClient.$get({
|
|
|
|
|
|
|
+ const response = await adminClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
|
'X-Tenant-ID': '2',
|
|
'X-Tenant-ID': '2',
|
|
@@ -130,7 +131,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
|
|
|
|
|
describe('管理员广告类型API权限控制', () => {
|
|
describe('管理员广告类型API权限控制', () => {
|
|
|
it('超级管理员(ID=1)应该能访问管理员广告类型列表API', async () => {
|
|
it('超级管理员(ID=1)应该能访问管理员广告类型列表API', async () => {
|
|
|
- const response = await adminTypeClient.$get({
|
|
|
|
|
|
|
+ const response = await adminTypeClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|
|
@@ -146,7 +147,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('普通管理员(ID>1)不应该能访问管理员广告类型列表API', async () => {
|
|
it('普通管理员(ID>1)不应该能访问管理员广告类型列表API', async () => {
|
|
|
- const response = await adminTypeClient.$get({
|
|
|
|
|
|
|
+ const response = await adminTypeClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${regularUserToken}`,
|
|
'Authorization': `Bearer ${regularUserToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|
|
@@ -166,7 +167,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
|
|
|
|
|
describe('用户端广告API访问控制', () => {
|
|
describe('用户端广告API访问控制', () => {
|
|
|
it('认证用户应该能访问用户端广告列表API', async () => {
|
|
it('认证用户应该能访问用户端广告列表API', async () => {
|
|
|
- const response = await userClient.$get({
|
|
|
|
|
|
|
+ const response = await userClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
|
'X-Tenant-ID': '2',
|
|
'X-Tenant-ID': '2',
|
|
@@ -190,7 +191,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('认证用户应该能访问用户端广告类型列表API', async () => {
|
|
it('认证用户应该能访问用户端广告类型列表API', async () => {
|
|
|
- const response = await userTypeClient.$get({
|
|
|
|
|
|
|
+ const response = await userTypeClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
|
'X-Tenant-ID': '2',
|
|
'X-Tenant-ID': '2',
|
|
@@ -221,7 +222,7 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
status: 1
|
|
status: 1
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const response = await userClient.$get({
|
|
|
|
|
|
|
+ const response = await userClient.$get(undefined, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
'Authorization': `Bearer ${tenantUserToken}`,
|
|
|
'X-Tenant-ID': '2',
|
|
'X-Tenant-ID': '2',
|
|
@@ -268,12 +269,13 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const response = await adminClient.$post({
|
|
const response = await adminClient.$post({
|
|
|
|
|
+ json: newAd
|
|
|
|
|
+ }, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|
|
|
'X-User-ID': '1'
|
|
'X-User-ID': '1'
|
|
|
- },
|
|
|
|
|
- json: newAd
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 超级管理员应该能创建
|
|
// 超级管理员应该能创建
|
|
@@ -290,12 +292,13 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const response = await adminClient.$post({
|
|
const response = await adminClient.$post({
|
|
|
|
|
+ json: newAd
|
|
|
|
|
+ }, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${regularUserToken}`,
|
|
'Authorization': `Bearer ${regularUserToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|
|
|
'X-User-ID': '2'
|
|
'X-User-ID': '2'
|
|
|
- },
|
|
|
|
|
- json: newAd
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 普通管理员应该被拒绝
|
|
// 普通管理员应该被拒绝
|
|
@@ -321,13 +324,14 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const response = await adminClient[':id'].$put({
|
|
const response = await adminClient[':id'].$put({
|
|
|
- param: { id: String(testAd.id) },
|
|
|
|
|
|
|
+ param: { id: testAd.id },
|
|
|
|
|
+ json: updateData
|
|
|
|
|
+ }, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|
|
|
'X-User-ID': '1'
|
|
'X-User-ID': '1'
|
|
|
- },
|
|
|
|
|
- json: updateData
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 超级管理员应该能更新
|
|
// 超级管理员应该能更新
|
|
@@ -349,7 +353,8 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const response = await adminClient[':id'].$delete({
|
|
const response = await adminClient[':id'].$delete({
|
|
|
- param: { id: String(testAd.id) },
|
|
|
|
|
|
|
+ param: { id: testAd.id }
|
|
|
|
|
+ }, {
|
|
|
headers: {
|
|
headers: {
|
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
'Authorization': `Bearer ${superAdminToken}`,
|
|
|
'X-Tenant-ID': '1',
|
|
'X-Tenant-ID': '1',
|