|
@@ -95,13 +95,16 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result).toHaveProperty('id');
|
|
|
|
|
- expect(result.provinceId).toBe(testProvince.id);
|
|
|
|
|
- expect(result.cityId).toBe(testCity.id);
|
|
|
|
|
- expect(result.districtId).toBe(testDistrict.id);
|
|
|
|
|
- expect(result.basicSalary).toBe(5000.00);
|
|
|
|
|
- expect(result.totalSalary).toBe(7300.00); // 5000 + 1000 + 500 + 800
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.id).toBeDefined();
|
|
|
|
|
+ expect(data.provinceId).toBe(testProvince.id);
|
|
|
|
|
+ expect(data.cityId).toBe(testCity.id);
|
|
|
|
|
+ expect(data.districtId).toBe(testDistrict.id);
|
|
|
|
|
+ expect(data.basicSalary).toBe(5000.00);
|
|
|
|
|
+ expect(data.totalSalary).toBe(7300.00); // 5000 + 1000 + 500 + 800
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该验证区域层级关系', async () => {
|
|
it('应该验证区域层级关系', async () => {
|
|
@@ -131,20 +134,22 @@ describe('薪资管理API集成测试', () => {
|
|
|
basicSalary: 5000.00
|
|
basicSalary: 5000.00
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const firstResponse = await client.salary.create.$post({
|
|
|
|
|
- json: createData,
|
|
|
|
|
- header: () => ({
|
|
|
|
|
|
|
+ const firstResponse = await client.create.$post({
|
|
|
|
|
+ json: createData
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
'Authorization': `Bearer ${testToken}`
|
|
'Authorization': `Bearer ${testToken}`
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
expect(firstResponse.status).toBe(200);
|
|
expect(firstResponse.status).toBe(200);
|
|
|
|
|
|
|
|
// 第二次创建相同区域
|
|
// 第二次创建相同区域
|
|
|
- const secondResponse = await client.salary.create.$post({
|
|
|
|
|
- json: createData,
|
|
|
|
|
- header: () => ({
|
|
|
|
|
|
|
+ const secondResponse = await client.create.$post({
|
|
|
|
|
+ json: createData
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
'Authorization': `Bearer ${testToken}`
|
|
'Authorization': `Bearer ${testToken}`
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(secondResponse.status).toBe(400);
|
|
expect(secondResponse.status).toBe(400);
|
|
@@ -191,11 +196,14 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result).toHaveProperty('data');
|
|
|
|
|
- expect(result).toHaveProperty('total');
|
|
|
|
|
- expect(result.data).toHaveLength(2);
|
|
|
|
|
- expect(result.total).toBe(2);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data).toHaveProperty('data');
|
|
|
|
|
+ expect(data).toHaveProperty('total');
|
|
|
|
|
+ expect(data.data).toHaveLength(2);
|
|
|
|
|
+ expect(data.total).toBe(2);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该支持按区域ID过滤', async () => {
|
|
it('应该支持按区域ID过滤', async () => {
|
|
@@ -211,8 +219,11 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result.data).toHaveLength(2);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.data).toHaveLength(2);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该支持分页查询', async () => {
|
|
it('应该支持分页查询', async () => {
|
|
@@ -228,9 +239,12 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result.data).toHaveLength(1);
|
|
|
|
|
- expect(result.total).toBe(2);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.data).toHaveLength(1);
|
|
|
|
|
+ expect(data.total).toBe(2);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -256,7 +270,7 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该返回指定ID的薪资详情', async () => {
|
|
it('应该返回指定ID的薪资详情', async () => {
|
|
|
- const response = await client['detail/:id'].$get({
|
|
|
|
|
|
|
+ const response = await client.detail[':id'].$get({
|
|
|
param: { id: testSalary.id.toString() }
|
|
param: { id: testSalary.id.toString() }
|
|
|
}, {
|
|
}, {
|
|
|
headers: {
|
|
headers: {
|
|
@@ -265,18 +279,22 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result.id).toBe(testSalary.id);
|
|
|
|
|
- expect(result.provinceId).toBe(testProvince.id);
|
|
|
|
|
- expect(result.cityId).toBe(testCity.id);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data?.id).toBe(testSalary.id);
|
|
|
|
|
+ expect(data?.provinceId).toBe(testProvince.id);
|
|
|
|
|
+ expect(data?.cityId).toBe(testCity.id);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该处理不存在的薪资ID', async () => {
|
|
it('应该处理不存在的薪资ID', async () => {
|
|
|
- const response = await client.salary['detail/:id'].$get({
|
|
|
|
|
- param: { id: '999999' },
|
|
|
|
|
- header: () => ({
|
|
|
|
|
|
|
+ const response = await client.detail[':id'].$get({
|
|
|
|
|
+ param: { id: '999999' }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
'Authorization': `Bearer ${testToken}`
|
|
'Authorization': `Bearer ${testToken}`
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(response.status).toBe(404);
|
|
@@ -316,21 +334,25 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result.id).toBe(testSalary.id);
|
|
|
|
|
- expect(result.provinceId).toBe(testProvince.id);
|
|
|
|
|
- expect(result.cityId).toBe(testCity.id);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data?.id).toBe(testSalary.id);
|
|
|
|
|
+ expect(data?.provinceId).toBe(testProvince.id);
|
|
|
|
|
+ expect(data?.cityId).toBe(testCity.id);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该处理不存在的区域组合', async () => {
|
|
it('应该处理不存在的区域组合', async () => {
|
|
|
- const response = await client.salary.byProvinceCity.$get({
|
|
|
|
|
|
|
+ const response = await client.byProvinceCity.$get({
|
|
|
query: {
|
|
query: {
|
|
|
provinceId: '999999',
|
|
provinceId: '999999',
|
|
|
cityId: '999999'
|
|
cityId: '999999'
|
|
|
- },
|
|
|
|
|
- header: () => ({
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
'Authorization': `Bearer ${testToken}`
|
|
'Authorization': `Bearer ${testToken}`
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(response.status).toBe(404);
|
|
@@ -363,7 +385,7 @@ describe('薪资管理API集成测试', () => {
|
|
|
allowance: 1200.00
|
|
allowance: 1200.00
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const response = await client['update/:id'].$put({
|
|
|
|
|
|
|
+ const response = await client.update[':id'].$put({
|
|
|
param: { id: testSalary.id.toString() },
|
|
param: { id: testSalary.id.toString() },
|
|
|
json: updateData
|
|
json: updateData
|
|
|
}, {
|
|
}, {
|
|
@@ -373,11 +395,14 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result.id).toBe(testSalary.id);
|
|
|
|
|
- expect(result.basicSalary).toBe(5500.00);
|
|
|
|
|
- expect(result.allowance).toBe(1200.00);
|
|
|
|
|
- expect(result.totalSalary).toBe(8000.00); // 5500 + 1200 + 500 + 800
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data.id).toBe(testSalary.id);
|
|
|
|
|
+ expect(data.basicSalary).toBe(5500.00);
|
|
|
|
|
+ expect(data.allowance).toBe(1200.00);
|
|
|
|
|
+ expect(data.totalSalary).toBe(8000.00); // 5500 + 1200 + 500 + 800
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该验证更新后的区域数据', async () => {
|
|
it('应该验证更新后的区域数据', async () => {
|
|
@@ -385,7 +410,7 @@ describe('薪资管理API集成测试', () => {
|
|
|
provinceId: 999999 // 不存在的区域ID
|
|
provinceId: 999999 // 不存在的区域ID
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const response = await client['update/:id'].$put({
|
|
|
|
|
|
|
+ const response = await client.update[':id'].$put({
|
|
|
param: { id: testSalary.id.toString() },
|
|
param: { id: testSalary.id.toString() },
|
|
|
json: updateData
|
|
json: updateData
|
|
|
}, {
|
|
}, {
|
|
@@ -419,7 +444,7 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该成功删除薪资水平', async () => {
|
|
it('应该成功删除薪资水平', async () => {
|
|
|
- const response = await client['delete/:id'].$delete({
|
|
|
|
|
|
|
+ const response = await client.delete[':id'].$delete({
|
|
|
param: { id: testSalary.id.toString() }
|
|
param: { id: testSalary.id.toString() }
|
|
|
}, {
|
|
}, {
|
|
|
headers: {
|
|
headers: {
|
|
@@ -428,24 +453,28 @@ describe('薪资管理API集成测试', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.status).toBe(200);
|
|
|
- const result = await response.json();
|
|
|
|
|
- expect(result).toEqual({ success: true });
|
|
|
|
|
|
|
|
|
|
- // 验证数据已删除
|
|
|
|
|
- const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
- const salaryRepository = dataSource.getRepository(SalaryLevel);
|
|
|
|
|
- const deletedSalary = await salaryRepository.findOne({
|
|
|
|
|
- where: { id: testSalary.id }
|
|
|
|
|
- });
|
|
|
|
|
- expect(deletedSalary).toBeNull();
|
|
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+ expect(data).toEqual({ success: true });
|
|
|
|
|
+
|
|
|
|
|
+ // 验证数据已删除
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+ const salaryRepository = dataSource.getRepository(SalaryLevel);
|
|
|
|
|
+ const deletedSalary = await salaryRepository.findOne({
|
|
|
|
|
+ where: { id: testSalary.id }
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(deletedSalary).toBeNull();
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('应该处理不存在的薪资ID', async () => {
|
|
it('应该处理不存在的薪资ID', async () => {
|
|
|
- const response = await client.salary['delete/:id'].$delete({
|
|
|
|
|
- param: { id: '999999' },
|
|
|
|
|
- header: () => ({
|
|
|
|
|
|
|
+ const response = await client.delete[':id'].$delete({
|
|
|
|
|
+ param: { id: '999999' }
|
|
|
|
|
+ }, {
|
|
|
|
|
+ headers: {
|
|
|
'Authorization': `Bearer ${testToken}`
|
|
'Authorization': `Bearer ${testToken}`
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(response.status).toBe(404);
|