|
|
@@ -12,7 +12,8 @@ import { TestDataFactory } from '../utils/test-data-factory';
|
|
|
import { TestQueryFactory } from '../utils/test-query-factory';
|
|
|
import { AuthService } from '@d8d/auth-module-mt';
|
|
|
import { UserServiceMt } from '@d8d/user-module-mt';
|
|
|
-import { UserEntityMt } from '@d8d/user-module-mt';
|
|
|
+import { UserEntityMt, RoleMt } from '@d8d/user-module-mt';
|
|
|
+import { FileMt } from '@d8d/file-module-mt';
|
|
|
|
|
|
// 定义响应类型
|
|
|
interface SuccessResponse {
|
|
|
@@ -45,7 +46,7 @@ interface ErrorResponse {
|
|
|
}
|
|
|
|
|
|
// 设置集成测试钩子
|
|
|
-setupIntegrationDatabaseHooksWithEntities([AreaEntityMt, UserEntityMt])
|
|
|
+setupIntegrationDatabaseHooksWithEntities([AreaEntityMt, UserEntityMt, FileMt, RoleMt])
|
|
|
|
|
|
describe('区域API集成测试', () => {
|
|
|
let client: ReturnType<typeof testClient<typeof areasRoutesMt>>;
|
|
|
@@ -253,6 +254,10 @@ describe('区域API集成测试', () => {
|
|
|
it('应该成功获取指定省份下启用状态的城市列表', async () => {
|
|
|
const response = await client.cities.$get({
|
|
|
query: TestQueryFactory.createCitiesQuery(testAreas[0].id)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
IntegrationTestAssertions.expectStatus(response, 200);
|
|
|
@@ -284,6 +289,10 @@ describe('区域API集成测试', () => {
|
|
|
it('应该处理不存在的省份ID', async () => {
|
|
|
const response = await client.cities.$get({
|
|
|
query: TestQueryFactory.createCitiesQuery(999)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
IntegrationTestAssertions.expectStatus(response, 200);
|
|
|
@@ -299,6 +308,10 @@ describe('区域API集成测试', () => {
|
|
|
it('应该验证省份ID参数', async () => {
|
|
|
const response = await client.cities.$get({
|
|
|
query: TestQueryFactory.createCitiesQuery(0)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 参数验证应该返回400错误
|
|
|
@@ -314,6 +327,10 @@ describe('区域API集成测试', () => {
|
|
|
|
|
|
const response = await client.districts.$get({
|
|
|
query: TestQueryFactory.createDistrictsQuery(chaoyangCity!.id)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
IntegrationTestAssertions.expectStatus(response, 200);
|
|
|
@@ -344,6 +361,10 @@ describe('区域API集成测试', () => {
|
|
|
it('应该处理不存在的城市ID', async () => {
|
|
|
const response = await client.districts.$get({
|
|
|
query: TestQueryFactory.createDistrictsQuery(999)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
IntegrationTestAssertions.expectStatus(response, 200);
|
|
|
@@ -359,6 +380,10 @@ describe('区域API集成测试', () => {
|
|
|
it('应该验证城市ID参数', async () => {
|
|
|
const response = await client.districts.$get({
|
|
|
query: TestQueryFactory.createDistrictsQuery(0)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 参数验证应该返回400错误
|
|
|
@@ -371,6 +396,10 @@ describe('区域API集成测试', () => {
|
|
|
// 测试省份API
|
|
|
const provincesResponse = await client.provinces.$get({
|
|
|
query: TestQueryFactory.createProvincesQuery()
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
IntegrationTestAssertions.expectStatus(provincesResponse, 200);
|
|
|
const provincesData = await provincesResponse.json();
|
|
|
@@ -385,6 +414,10 @@ describe('区域API集成测试', () => {
|
|
|
// 测试城市API
|
|
|
const citiesResponse = await client.cities.$get({
|
|
|
query: TestQueryFactory.createCitiesQuery(testAreas[0].id)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
IntegrationTestAssertions.expectStatus(citiesResponse, 200);
|
|
|
const citiesData = await citiesResponse.json();
|
|
|
@@ -400,6 +433,10 @@ describe('区域API集成测试', () => {
|
|
|
const chaoyangCity = testAreas.find(area => area.name === '朝阳区' && area.level === AreaLevel.CITY);
|
|
|
const districtsResponse = await client.districts.$get({
|
|
|
query: TestQueryFactory.createDistrictsQuery(chaoyangCity!.id)
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
});
|
|
|
IntegrationTestAssertions.expectStatus(districtsResponse, 200);
|
|
|
const districtsData = await districtsResponse.json();
|