|
|
@@ -3,11 +3,12 @@ import { testClient } from 'hono/testing';
|
|
|
import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '@d8d/shared-test-util';
|
|
|
import { JWTUtil } from '@d8d/shared-utils';
|
|
|
import { UserEntity, Role } from '@d8d/user-module';
|
|
|
+import { File } from '@d8d/file-module';
|
|
|
import channelRoutes from '../../src/routes/channel.routes';
|
|
|
import { Channel } from '../../src/entities/channel.entity';
|
|
|
|
|
|
// 设置集成测试钩子
|
|
|
-setupIntegrationDatabaseHooksWithEntities([UserEntity, Role, Channel])
|
|
|
+setupIntegrationDatabaseHooksWithEntities([UserEntity, File, Role, Channel])
|
|
|
|
|
|
describe('渠道管理API集成测试', () => {
|
|
|
let client: ReturnType<typeof testClient<typeof channelRoutes>>;
|
|
|
@@ -62,7 +63,8 @@ describe('渠道管理API集成测试', () => {
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
|
- expect(data.success).toBe(true);
|
|
|
+ expect(data.channelName).toBe(createData.channelName);
|
|
|
+ expect(data.channelType).toBe(createData.channelType);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -131,7 +133,7 @@ describe('渠道管理API集成测试', () => {
|
|
|
await channelRepository.save(testChannel);
|
|
|
|
|
|
const deleteData = {
|
|
|
- channelId: testChannel.channelId
|
|
|
+ id: testChannel.id
|
|
|
};
|
|
|
|
|
|
const response = await client.deleteChannel.$post({
|
|
|
@@ -152,7 +154,7 @@ describe('渠道管理API集成测试', () => {
|
|
|
|
|
|
// 验证渠道状态变为0(软删除)
|
|
|
const deletedChannel = await channelRepository.findOne({
|
|
|
- where: { channelId: testChannel.channelId }
|
|
|
+ where: { id: testChannel.id }
|
|
|
});
|
|
|
expect(deletedChannel?.status).toBe(0);
|
|
|
});
|
|
|
@@ -173,7 +175,7 @@ describe('渠道管理API集成测试', () => {
|
|
|
await channelRepository.save(testChannel);
|
|
|
|
|
|
const updateData = {
|
|
|
- channelId: testChannel.channelId,
|
|
|
+ id: testChannel.id,
|
|
|
channelName: '更新后的渠道名称',
|
|
|
channelType: '更新类型',
|
|
|
contactPerson: '李四',
|
|
|
@@ -189,16 +191,23 @@ describe('渠道管理API集成测试', () => {
|
|
|
});
|
|
|
|
|
|
console.debug('更新渠道响应状态:', response.status);
|
|
|
+
|
|
|
+ if (response.status !== 200) {
|
|
|
+ const errorData = await response.json();
|
|
|
+ console.debug('更新渠道错误:', errorData);
|
|
|
+ }
|
|
|
+
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
|
- expect(data.success).toBe(true);
|
|
|
+ expect(data.channelName).toBe(updateData.channelName);
|
|
|
+ expect(data.channelType).toBe(updateData.channelType);
|
|
|
}
|
|
|
|
|
|
// 验证渠道已更新
|
|
|
const updatedChannel = await channelRepository.findOne({
|
|
|
- where: { channelId: testChannel.channelId }
|
|
|
+ where: { id: testChannel.id }
|
|
|
});
|
|
|
expect(updatedChannel?.channelName).toBe(updateData.channelName);
|
|
|
expect(updatedChannel?.channelType).toBe(updateData.channelType);
|
|
|
@@ -225,7 +234,7 @@ describe('渠道管理API集成测试', () => {
|
|
|
|
|
|
// 尝试将渠道B的名称改为渠道A的名称
|
|
|
const updateData = {
|
|
|
- channelId: channel2.channelId,
|
|
|
+ id: channel2.id,
|
|
|
channelName: '渠道A' // 重复的名称
|
|
|
};
|
|
|
|
|
|
@@ -343,8 +352,8 @@ describe('渠道管理API集成测试', () => {
|
|
|
});
|
|
|
await channelRepository.save(testChannel);
|
|
|
|
|
|
- const response = await client['getChannel/:id'].$get({
|
|
|
- param: { id: testChannel.channelId }
|
|
|
+ const response = await client.getChannel[':id'].$get({
|
|
|
+ param: { id: testChannel.id }
|
|
|
}, {
|
|
|
headers: {
|
|
|
'Authorization': `Bearer ${testToken}`
|
|
|
@@ -356,13 +365,13 @@ describe('渠道管理API集成测试', () => {
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
const data = await response.json();
|
|
|
- expect(data.channelId).toBe(testChannel.channelId);
|
|
|
- expect(data.channelName).toBe(testChannel.channelName);
|
|
|
+ expect(data!.id).toBe(testChannel.id);
|
|
|
+ expect(data!.channelName).toBe(testChannel.channelName);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
it('应该处理不存在的渠道', async () => {
|
|
|
- const response = await client['getChannel/:id'].$get({
|
|
|
+ const response = await client.getChannel[':id'].$get({
|
|
|
param: { id: 999999 }
|
|
|
}, {
|
|
|
headers: {
|