chore: replace all cn comments of fe to en version by volc api (#320)

This commit is contained in:
tecvan
2025-07-31 10:32:15 +08:00
committed by GitHub
parent 716ec0cba8
commit 71f6245a01
2960 changed files with 15545 additions and 15545 deletions

View File

@@ -18,7 +18,7 @@ import { vi, describe, it, expect, beforeAll, beforeEach } from 'vitest';
import { Toast } from '@coze-arch/bot-semi';
import { axiosInstance, isApiError, ApiError } from '@coze-arch/bot-http';
// 导入 axios 配置以触发 Toast 配置
// Import axios configuration to trigger Toast configuration
import '../src/axios';
vi.mock('@coze-arch/bot-semi', () => ({
@@ -28,9 +28,9 @@ vi.mock('@coze-arch/bot-semi', () => ({
},
}));
// 模拟 isApiError 函数
// emulating the isApiError function
vi.mock('@coze-arch/bot-http', () => {
// 保存原始的 axiosInstance.interceptors.response.use 方法
// Save the original axiosInstant.interceptors.response.use method
const originalUse = vi.fn();
return {
@@ -60,13 +60,13 @@ describe('axios configuration', () => {
let onRejected: Function;
beforeAll(async () => {
// 导入 axios 配置以触发 Toast 配置和拦截器注册
// Import axios configuration to trigger Toast configuration and blocker registration
await import('../src/axios');
// 验证 Toast.config 被调用
// Verify that Toast.config is called
expect(Toast.config).toHaveBeenCalledWith({ top: 80 });
// 获取注册的拦截器函数
// Get the registered interceptor function
const useArgs = (axiosInstance.interceptors.response.use as any).mock
.calls[0];
onFulfilled = useArgs[0];
@@ -88,15 +88,15 @@ describe('axios configuration', () => {
});
it('should show error toast when API error occurs', () => {
// 创建一个 API 错误
// Create an API error
const apiError = new (ApiError as any)('500', 'API Error');
// 模拟 isApiError 返回 true
// isApiError returns true
(isApiError as any).mockReturnValue(true);
try {
onRejected(apiError);
// 如果没有抛出错误,测试应该失败
// If no errors are thrown, the test should fail
expect(true).toBe(false);
} catch (error) {
expect(isApiError).toHaveBeenCalledWith(apiError);
@@ -109,16 +109,16 @@ describe('axios configuration', () => {
});
it('should not show error toast when __disableErrorToast is true', () => {
// 创建一个 API 错误,并设置 __disableErrorToast true
// Create an API error and set __disableErrorToast to true
const apiError = new (ApiError as any)('401', 'Unauthorized');
apiError.config.__disableErrorToast = true;
// 模拟 isApiError 返回 true
// isApiError returns true
(isApiError as any).mockReturnValue(true);
try {
onRejected(apiError);
// 如果没有抛出错误,测试应该失败
// If no errors are thrown, the test should fail
expect(true).toBe(false);
} catch (error) {
expect(isApiError).toHaveBeenCalledWith(apiError);
@@ -128,15 +128,15 @@ describe('axios configuration', () => {
});
it('should not show error toast when error has no message', () => {
// 创建一个没有消息的 API 错误
// Create an API error with no message
const apiError = new (ApiError as any)('403', undefined);
// 模拟 isApiError 返回 true
// isApiError returns true
(isApiError as any).mockReturnValue(true);
try {
onRejected(apiError);
// 如果没有抛出错误,测试应该失败
// If no errors are thrown, the test should fail
expect(true).toBe(false);
} catch (error) {
expect(isApiError).toHaveBeenCalledWith(apiError);
@@ -146,16 +146,16 @@ describe('axios configuration', () => {
});
it('should not show error toast when isApiError returns false', () => {
// 创建一个普通错误
// Create a normal error
const regularError = new Error('Regular Error');
(regularError as any).msg = 'Error message';
// 模拟 isApiError 返回 false
// isApiError returned false
(isApiError as any).mockReturnValue(false);
try {
onRejected(regularError);
// 如果没有抛出错误,测试应该失败
// If no errors are thrown, the test should fail
expect(true).toBe(false);
} catch (error) {
expect(isApiError).toHaveBeenCalledWith(regularError);
@@ -165,10 +165,10 @@ describe('axios configuration', () => {
});
it('should handle null or undefined error', () => {
// 测试 null 错误
// Test null error
try {
onRejected(null);
// 如果没有抛出错误,测试应该失败
// If no errors are thrown, the test should fail
expect(true).toBe(false);
} catch (error) {
expect(isApiError).toHaveBeenCalledWith(null);
@@ -178,10 +178,10 @@ describe('axios configuration', () => {
vi.clearAllMocks();
// 测试 undefined 错误
// Test undefined error
try {
onRejected(undefined);
// 如果没有抛出错误,测试应该失败
// If no errors are thrown, the test should fail
expect(true).toBe(false);
} catch (error) {
expect(isApiError).toHaveBeenCalledWith(undefined);

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { vi } from 'vitest';
import { basicApi } from '../src/basic-api';
@@ -52,7 +52,7 @@ describe('basic-api', () => {
headers: { 'Another-Header': 'another-value' },
};
// @ts-expect-error - 我们知道这是一个有效的方法调用
// @ts-expect-error - we know this is a valid method call
await basicApi.request(mockParams, mockConfig);
expect(axiosInstance.request).toHaveBeenCalledWith({
@@ -76,7 +76,7 @@ describe('basic-api', () => {
headers: { 'Custom-Header': 'value' },
};
// @ts-expect-error - 我们知道这是一个有效的方法调用
// @ts-expect-error - we know this is a valid method call
await basicApi.request(mockParams);
expect(axiosInstance.request).toHaveBeenCalledWith({
@@ -97,7 +97,7 @@ describe('basic-api', () => {
method: 'GET',
};
// @ts-expect-error - 我们知道这是一个有效的方法调用
// @ts-expect-error - we know this is a valid method call
await basicApi.request(mockParams);
expect(axiosInstance.request).toHaveBeenCalledWith({

View File

@@ -21,7 +21,7 @@ import {
type AxiosRequestConfig,
} from '@coze-arch/bot-http';
// Toast展示位置离top 80px
// Toast display 80px from the top
Toast.config({
top: 80,
});
@@ -32,7 +32,7 @@ interface CustomAxiosConfig {
}
/**
* 业务自定义 axios 配置
* Business custom axios configuration
* @param __disableErrorToast default: false
*/
export type BotAPIRequestConfig = AxiosRequestConfig & CustomAxiosConfig;
@@ -40,7 +40,7 @@ export type BotAPIRequestConfig = AxiosRequestConfig & CustomAxiosConfig;
axiosInstance.interceptors.response.use(
response => response.data,
error => {
// 业务逻辑
// business logic
if (
isApiError(error) &&
error.msg &&