|
@@ -91,7 +91,10 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
expect([200, 404]).toContain(response.status);
|
|
expect([200, 404]).toContain(response.status);
|
|
|
if (response.status === 200) {
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
const data = await response.json();
|
|
|
- expect(Array.isArray(data)).toBeTruthy();
|
|
|
|
|
|
|
+ // API返回格式: { code, message, data: { list, total } }
|
|
|
|
|
+ expect(data).toHaveProperty('data');
|
|
|
|
|
+ expect(data.data).toHaveProperty('list');
|
|
|
|
|
+ expect(Array.isArray(data.data.list)).toBeTruthy();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -142,7 +145,10 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
expect([200, 404]).toContain(response.status);
|
|
expect([200, 404]).toContain(response.status);
|
|
|
if (response.status === 200) {
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
const data = await response.json();
|
|
|
- expect(Array.isArray(data)).toBeTruthy();
|
|
|
|
|
|
|
+ // API返回格式: { code, message, data: { list, total } }
|
|
|
|
|
+ expect(data).toHaveProperty('data');
|
|
|
|
|
+ expect(data.data).toHaveProperty('list');
|
|
|
|
|
+ expect(Array.isArray(data.data.list)).toBeTruthy();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -179,7 +185,9 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
expect([200, 404]).toContain(response.status);
|
|
expect([200, 404]).toContain(response.status);
|
|
|
if (response.status === 200) {
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
const data = await response.json();
|
|
|
- expect(Array.isArray(data)).toBeTruthy();
|
|
|
|
|
|
|
+ expect(data).toHaveProperty("data");
|
|
|
|
|
+ expect(data.data).toHaveProperty("list");
|
|
|
|
|
+ expect(Array.isArray(data.data.list)).toBeTruthy();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -202,7 +210,10 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
expect([200, 404]).toContain(response.status);
|
|
expect([200, 404]).toContain(response.status);
|
|
|
if (response.status === 200) {
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
const data = await response.json();
|
|
|
- expect(Array.isArray(data)).toBeTruthy();
|
|
|
|
|
|
|
+ // API返回格式: { code, message, data: { list, total } }
|
|
|
|
|
+ expect(data).toHaveProperty('data');
|
|
|
|
|
+ expect(data.data).toHaveProperty('list');
|
|
|
|
|
+ expect(Array.isArray(data.data.list)).toBeTruthy();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -212,13 +223,22 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
|
|
|
|
|
|
|
|
+ // 先创建广告类型
|
|
|
|
|
+ const adTypeRepository = dataSource.getRepository(UnifiedAdvertisementType);
|
|
|
|
|
+ const adType = await adTypeRepository.save({
|
|
|
|
|
+ name: 'Test Type',
|
|
|
|
|
+ code: 'test_type_verify',
|
|
|
|
|
+ sort: 0,
|
|
|
|
|
+ status: 1
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
// 创建测试广告数据
|
|
// 创建测试广告数据
|
|
|
const adRepository = dataSource.getRepository(UnifiedAdvertisement);
|
|
const adRepository = dataSource.getRepository(UnifiedAdvertisement);
|
|
|
await adRepository.save({
|
|
await adRepository.save({
|
|
|
title: 'Test Ad',
|
|
title: 'Test Ad',
|
|
|
- imageUrl: 'http://example.com/ad.jpg',
|
|
|
|
|
- linkUrl: 'http://example.com',
|
|
|
|
|
- position: 'home',
|
|
|
|
|
|
|
+ typeId: adType.id,
|
|
|
|
|
+ code: 'test_ad_verify',
|
|
|
|
|
+ url: 'http://example.com',
|
|
|
status: 1
|
|
status: 1
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -232,10 +252,13 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
const data = await response.json();
|
|
|
- expect(Array.isArray(data)).toBeTruthy();
|
|
|
|
|
|
|
+ // API返回格式: { code, message, data: { list, total } }
|
|
|
|
|
+ expect(data).toHaveProperty('data');
|
|
|
|
|
+ expect(data.data).toHaveProperty('list');
|
|
|
|
|
+ expect(Array.isArray(data.data.list)).toBeTruthy();
|
|
|
// 验证返回的是统一广告数据,不是按租户隔离的
|
|
// 验证返回的是统一广告数据,不是按租户隔离的
|
|
|
- if (data.length > 0) {
|
|
|
|
|
- const ad = data[0];
|
|
|
|
|
|
|
+ if (data.data.list.length > 0) {
|
|
|
|
|
+ const ad = data.data.list[0];
|
|
|
expect(ad).not.toHaveProperty('tenantId'); // 统一广告不应该有tenantId字段
|
|
expect(ad).not.toHaveProperty('tenantId'); // 统一广告不应该有tenantId字段
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -260,11 +283,23 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
|
|
|
|
|
describe('管理员操作权限验证', () => {
|
|
describe('管理员操作权限验证', () => {
|
|
|
it('超级管理员应该能创建统一广告', async () => {
|
|
it('超级管理员应该能创建统一广告', async () => {
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+ if (!dataSource) throw new Error('Database not initialized');
|
|
|
|
|
+
|
|
|
|
|
+ // 先创建广告类型
|
|
|
|
|
+ const adTypeRepository = dataSource.getRepository(UnifiedAdvertisementType);
|
|
|
|
|
+ const adType = await adTypeRepository.save({
|
|
|
|
|
+ name: 'Test Type',
|
|
|
|
|
+ code: 'test_type',
|
|
|
|
|
+ sort: 0,
|
|
|
|
|
+ status: 1
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const newAd = {
|
|
const newAd = {
|
|
|
title: 'New Unified Ad',
|
|
title: 'New Unified Ad',
|
|
|
- imageUrl: 'http://example.com/new-ad.jpg',
|
|
|
|
|
- linkUrl: 'http://example.com/new',
|
|
|
|
|
- position: 'home',
|
|
|
|
|
|
|
+ typeId: adType.id, // 使用创建的广告类型ID
|
|
|
|
|
+ code: 'test_ad', // 必填
|
|
|
|
|
+ url: 'http://example.com/new',
|
|
|
status: 1
|
|
status: 1
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -283,11 +318,23 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('普通管理员不应该能创建统一广告', async () => {
|
|
it('普通管理员不应该能创建统一广告', async () => {
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+ if (!dataSource) throw new Error('Database not initialized');
|
|
|
|
|
+
|
|
|
|
|
+ // 先创建广告类型
|
|
|
|
|
+ const adTypeRepository = dataSource.getRepository(UnifiedAdvertisementType);
|
|
|
|
|
+ const adType = await adTypeRepository.save({
|
|
|
|
|
+ name: 'Test Type 2',
|
|
|
|
|
+ code: 'test_type_2',
|
|
|
|
|
+ sort: 0,
|
|
|
|
|
+ status: 1
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const newAd = {
|
|
const newAd = {
|
|
|
title: 'New Unified Ad',
|
|
title: 'New Unified Ad',
|
|
|
- imageUrl: 'http://example.com/new-ad.jpg',
|
|
|
|
|
- linkUrl: 'http://example.com/new',
|
|
|
|
|
- position: 'home',
|
|
|
|
|
|
|
+ typeId: adType.id,
|
|
|
|
|
+ code: 'test_ad_2',
|
|
|
|
|
+ url: 'http://example.com/new',
|
|
|
status: 1
|
|
status: 1
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -309,13 +356,22 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
|
|
|
|
|
|
|
|
+ // 先创建广告类型
|
|
|
|
|
+ const adTypeRepository = dataSource.getRepository(UnifiedAdvertisementType);
|
|
|
|
|
+ const adType = await adTypeRepository.save({
|
|
|
|
|
+ name: 'Test Type Update',
|
|
|
|
|
+ code: 'test_type_update',
|
|
|
|
|
+ sort: 0,
|
|
|
|
|
+ status: 1
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
// 创建测试广告
|
|
// 创建测试广告
|
|
|
const adRepository = dataSource.getRepository(UnifiedAdvertisement);
|
|
const adRepository = dataSource.getRepository(UnifiedAdvertisement);
|
|
|
const testAd = await adRepository.save({
|
|
const testAd = await adRepository.save({
|
|
|
title: 'Test Ad',
|
|
title: 'Test Ad',
|
|
|
- imageUrl: 'http://example.com/ad.jpg',
|
|
|
|
|
- linkUrl: 'http://example.com',
|
|
|
|
|
- position: 'home',
|
|
|
|
|
|
|
+ typeId: adType.id,
|
|
|
|
|
+ code: 'test_ad_update',
|
|
|
|
|
+ url: 'http://example.com',
|
|
|
status: 1
|
|
status: 1
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -342,13 +398,22 @@ describe('统一广告管理员权限集成测试', () => {
|
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
|
|
|
|
|
|
|
|
+ // 先创建广告类型
|
|
|
|
|
+ const adTypeRepository = dataSource.getRepository(UnifiedAdvertisementType);
|
|
|
|
|
+ const adType = await adTypeRepository.save({
|
|
|
|
|
+ name: 'Test Type Delete',
|
|
|
|
|
+ code: 'test_type_delete',
|
|
|
|
|
+ sort: 0,
|
|
|
|
|
+ status: 1
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
// 创建测试广告
|
|
// 创建测试广告
|
|
|
const adRepository = dataSource.getRepository(UnifiedAdvertisement);
|
|
const adRepository = dataSource.getRepository(UnifiedAdvertisement);
|
|
|
const testAd = await adRepository.save({
|
|
const testAd = await adRepository.save({
|
|
|
title: 'Test Ad',
|
|
title: 'Test Ad',
|
|
|
- imageUrl: 'http://example.com/ad.jpg',
|
|
|
|
|
- linkUrl: 'http://example.com',
|
|
|
|
|
- position: 'home',
|
|
|
|
|
|
|
+ typeId: adType.id,
|
|
|
|
|
+ code: 'test_ad_delete',
|
|
|
|
|
+ url: 'http://example.com',
|
|
|
status: 1
|
|
status: 1
|
|
|
});
|
|
});
|
|
|
|
|
|