chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -26,10 +26,10 @@ import {
|
||||
|
||||
import { useAuthStore } from '../../src/auth';
|
||||
|
||||
// 模拟全局变量
|
||||
// simulated global variable
|
||||
vi.stubGlobal('IS_DEV_MODE', false);
|
||||
|
||||
// 模拟依赖
|
||||
// simulated dependency
|
||||
vi.mock('@coze-arch/bot-api', () => ({
|
||||
PlaygroundApi: {
|
||||
DraftBotCollaboration: vi.fn().mockResolvedValue({
|
||||
@@ -75,7 +75,7 @@ vi.mock('@coze-arch/bot-api', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
// 模拟 logger
|
||||
// Analog logger
|
||||
vi.mock('@coze-arch/logger', () => ({
|
||||
reporter: {
|
||||
error: vi.fn(),
|
||||
@@ -85,7 +85,7 @@ vi.mock('@coze-arch/logger', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
// 模拟 CustomError
|
||||
// Simulate CustomError
|
||||
vi.mock('@coze-arch/bot-error', () => ({
|
||||
CustomError: vi.fn(),
|
||||
}));
|
||||
@@ -107,7 +107,7 @@ describe('auth', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
// 重置 store 状态
|
||||
// Reset store state
|
||||
act(() => {
|
||||
useAuthStore.setState({
|
||||
collaboratorsMap: {
|
||||
@@ -115,12 +115,12 @@ describe('auth', () => {
|
||||
[ResourceType.Workflow]: {},
|
||||
[ResourceType.Intelligence]: {},
|
||||
} as any,
|
||||
// 确保 getCachedCollaborators 方法返回一个空数组
|
||||
// Ensure getCachedCollaborators method returns an empty array
|
||||
getCachedCollaborators: vi.fn().mockReturnValue([]),
|
||||
});
|
||||
});
|
||||
|
||||
// 模拟 API 响应
|
||||
// Simulate API response
|
||||
(PlaygroundApi.DraftBotCollaboration as any).mockResolvedValue({
|
||||
data: mockCreators,
|
||||
});
|
||||
@@ -149,7 +149,7 @@ describe('auth', () => {
|
||||
it('当缓存中有协作者时应该返回缓存的协作者', () => {
|
||||
const { result } = renderHook(() => useAuthStore());
|
||||
|
||||
// 先设置缓存
|
||||
// Set up the cache first
|
||||
act(() => {
|
||||
useAuthStore.setState({
|
||||
collaboratorsMap: {
|
||||
@@ -267,7 +267,7 @@ describe('auth', () => {
|
||||
it('当资源类型为 Bot 时应该调用 patPermissionApi.AddCollaborator', async () => {
|
||||
const { result } = renderHook(() => useAuthStore());
|
||||
|
||||
// 确保 getCachedCollaborators 返回一个空数组
|
||||
// Make sure getCachedCollaborators return an empty array
|
||||
vi.spyOn(result.current, 'getCachedCollaborators').mockReturnValue([]);
|
||||
|
||||
(patPermissionApi.AddCollaborator as any).mockResolvedValue({});
|
||||
@@ -380,7 +380,7 @@ describe('auth', () => {
|
||||
it('当资源类型为 Bot 时应该调用 patPermissionApi.AddCollaborator', async () => {
|
||||
const { result } = renderHook(() => useAuthStore());
|
||||
|
||||
// 确保 getCachedCollaborators 返回一个空数组
|
||||
// Make sure getCachedCollaborators return an empty array
|
||||
vi.spyOn(result.current, 'getCachedCollaborators').mockReturnValue([]);
|
||||
|
||||
const mockUsers = [
|
||||
|
||||
@@ -21,11 +21,11 @@ import { workflowApi } from '@coze-arch/bot-api';
|
||||
|
||||
import { useSpaceGrayStore, TccKey } from '../../src/space-gray';
|
||||
|
||||
// 模拟全局变量
|
||||
// simulated global variable
|
||||
vi.stubGlobal('IS_DEV_MODE', false);
|
||||
vi.stubGlobal('IS_BOT_OP', false);
|
||||
|
||||
// 模拟依赖
|
||||
// simulated dependency
|
||||
vi.mock('@coze-arch/logger', () => ({
|
||||
reporter: {
|
||||
error: vi.fn(),
|
||||
@@ -51,7 +51,7 @@ describe('space-gray', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
// 重置 store 状态
|
||||
// Reset store state
|
||||
act(() => {
|
||||
useSpaceGrayStore.setState({
|
||||
spaceId: '',
|
||||
@@ -59,7 +59,7 @@ describe('space-gray', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// 模拟 API 响应
|
||||
// Simulate API response
|
||||
(workflowApi.GetWorkflowGrayFeature as any).mockResolvedValue({
|
||||
data: mockFeatureItems,
|
||||
});
|
||||
@@ -104,7 +104,7 @@ describe('space-gray', () => {
|
||||
});
|
||||
|
||||
it('当 IS_BOT_OP 为 true 时应该调用 OPGetWorkflowGrayFeature API', async () => {
|
||||
// 设置 IS_BOT_OP 为 true
|
||||
// Set IS_BOT_OP to true
|
||||
vi.stubGlobal('IS_BOT_OP', true);
|
||||
|
||||
const { result } = renderHook(() => useSpaceGrayStore());
|
||||
@@ -120,22 +120,22 @@ describe('space-gray', () => {
|
||||
expect(result.current.spaceId).toBe(mockSpaceId);
|
||||
expect(result.current.grayFeatureItems).toEqual(mockFeatureItems);
|
||||
|
||||
// 恢复 IS_BOT_OP 为 false
|
||||
// Restore IS_BOT_OP to false
|
||||
vi.stubGlobal('IS_BOT_OP', false);
|
||||
});
|
||||
|
||||
it('当 spaceId 与缓存的相同时不应该调用 API', async () => {
|
||||
const { result } = renderHook(() => useSpaceGrayStore());
|
||||
|
||||
// 先加载一次
|
||||
// Load once first
|
||||
await act(async () => {
|
||||
await result.current.load(mockSpaceId);
|
||||
});
|
||||
|
||||
// 清除之前的调用记录
|
||||
// Clear previous call history
|
||||
vi.clearAllMocks();
|
||||
|
||||
// 再次加载相同的 spaceId
|
||||
// Load the same spaceId again.
|
||||
await act(async () => {
|
||||
await result.current.load(mockSpaceId);
|
||||
});
|
||||
@@ -167,7 +167,7 @@ describe('space-gray', () => {
|
||||
it('当特性在灰度列表中且 in_gray 为 true 时应该返回 true', async () => {
|
||||
const { result } = renderHook(() => useSpaceGrayStore());
|
||||
|
||||
// 先加载灰度特性
|
||||
// Load grey release feature first
|
||||
await act(async () => {
|
||||
await result.current.load(mockSpaceId);
|
||||
});
|
||||
@@ -193,7 +193,7 @@ describe('space-gray', () => {
|
||||
|
||||
const { result } = renderHook(() => useSpaceGrayStore());
|
||||
|
||||
// 先加载灰度特性
|
||||
// Load grey release feature first
|
||||
await act(async () => {
|
||||
await result.current.load(mockSpaceId);
|
||||
});
|
||||
@@ -208,12 +208,12 @@ describe('space-gray', () => {
|
||||
it('当特性不在灰度列表中时应该返回 false', async () => {
|
||||
const { result } = renderHook(() => useSpaceGrayStore());
|
||||
|
||||
// 先加载灰度特性
|
||||
// Load grey release feature first
|
||||
await act(async () => {
|
||||
await result.current.load(mockSpaceId);
|
||||
});
|
||||
|
||||
// 使用一个不存在的 key
|
||||
// Use a non-existent key
|
||||
const isHit = result.current.isHitSpaceGray('NonExistentKey' as TccKey);
|
||||
|
||||
expect(isHit).toBe(false);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
// 导入被测试的模块
|
||||
// Import the tested module
|
||||
import localForage from 'localforage';
|
||||
|
||||
import { getStorage, clearStorage } from '../../src/utils/get-storage';
|
||||
|
||||
@@ -36,10 +36,10 @@ import {
|
||||
} from '@coze-arch/bot-api';
|
||||
|
||||
interface AuthStoreState {
|
||||
/* 两层map
|
||||
/* Two layer map
|
||||
{
|
||||
资源类型: {
|
||||
资源ID: 协作者
|
||||
Resource Type: {
|
||||
Resource ID: Collaborator
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -78,15 +78,15 @@ interface AuthStoreAction {
|
||||
resource: ResourceIdentifier;
|
||||
users: Creator[];
|
||||
options?: BotAPIRequestConfig;
|
||||
// 第三个参数是error code
|
||||
// The third argument is the error code
|
||||
roles?: Array<CollaboratorType>;
|
||||
}) => Promise<[Creator[], Creator[], number]>;
|
||||
// permission 服务新增的批量添加接口
|
||||
// New batch addition interface for permission service
|
||||
batchAddCollaboratorsServer: (params: {
|
||||
resource: ResourceIdentifier;
|
||||
users: Creator[];
|
||||
options?: BotAPIRequestConfig;
|
||||
// 第三个参数是error code
|
||||
// The third argument is the error code
|
||||
roles?: Array<CollaboratorType>;
|
||||
}) => Promise<boolean>;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ export const useAuthStore = create<AuthStoreState & AuthStoreAction>()(
|
||||
},
|
||||
}));
|
||||
},
|
||||
// 暂时由前端批量处理
|
||||
// Temporarily batch processed by the front end
|
||||
batchRemoveCollaborators: async (resource, userIds, options) => {
|
||||
const resultArr = await Promise.all(
|
||||
userIds.map(
|
||||
@@ -343,14 +343,14 @@ export const useAuthStore = create<AuthStoreState & AuthStoreAction>()(
|
||||
),
|
||||
),
|
||||
);
|
||||
// 目前的批量实现需要对单个添加的接口的code进行排序,拿到最高优先级的message来透出
|
||||
// Current batch implementations need to sort the code of individual added interfaces to get the highest priority message to reveal
|
||||
let errorCode = 0;
|
||||
const [addedUsers, failedUsers] = resultArr.reduce<
|
||||
[Creator[], Creator[]]
|
||||
>(
|
||||
([r, f], finish, index) => {
|
||||
const user = users[index];
|
||||
// 这么写是为了ts能正确类型推导。ts@5.0.4
|
||||
// This is written so that ts can derive the correct type. ts@5.0.4
|
||||
if (finish.result === true) {
|
||||
return [[...r, user], f];
|
||||
}
|
||||
@@ -360,12 +360,12 @@ export const useAuthStore = create<AuthStoreState & AuthStoreAction>()(
|
||||
message?: string;
|
||||
msg?: string;
|
||||
};
|
||||
// 比较code
|
||||
// Comparison code
|
||||
if (Number(error.code) > errorCode) {
|
||||
errorCode = Number(error.code);
|
||||
}
|
||||
}
|
||||
// 错误时,需要比较code然后复制message
|
||||
// Error, you need to compare the code and then copy the message
|
||||
return [r, [...f, user]];
|
||||
},
|
||||
[[], []],
|
||||
|
||||
@@ -33,7 +33,7 @@ declare namespace DataItem {
|
||||
interface UserInfo {
|
||||
app_id: number;
|
||||
/**
|
||||
* @deprecated 会因为溢出丢失精度,使用 user_id_str
|
||||
* @Deprecated will lose precision due to overflow, use user_id_str
|
||||
*/
|
||||
user_id: number;
|
||||
user_id_str: string;
|
||||
@@ -109,7 +109,7 @@ declare namespace DataItem {
|
||||
name?: string;
|
||||
[key?: string]: unknown;
|
||||
}; // Record<string, unknown>;
|
||||
// int值。1审核中,2审核通过,3审核不通过
|
||||
// int value. 1 During the review, 2 passed the review, and 3 failed the review.
|
||||
audit_status: number;
|
||||
details: Record<string, unknown>;
|
||||
is_auditing: boolean;
|
||||
@@ -119,7 +119,7 @@ declare namespace DataItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码的返回数据结构
|
||||
* The return data structure for sending the verification code
|
||||
*/
|
||||
interface SendCodeData {
|
||||
mobile: string;
|
||||
|
||||
@@ -15,17 +15,17 @@
|
||||
*/
|
||||
|
||||
export {
|
||||
/** @deprecated 该使用方式已废弃,后续请使用@coze-arch/foundation-sdk导出的方法*/
|
||||
/** @Deprecated This usage method is deprecated, please use the method exported by @code-arch/foundation-sdk in the future*/
|
||||
useSpaceStore,
|
||||
/** @deprecated 该使用方式已废弃,后续请使用@coze-arch/foundation-sdk导出的方法*/
|
||||
/** @Deprecated This usage method is deprecated, please use the method exported by @code-arch/foundation-sdk in the future*/
|
||||
useSpace,
|
||||
/** @deprecated 该使用方式已废弃,后续请使用@coze-arch/foundation-sdk导出的方法*/
|
||||
/** @Deprecated This usage method is deprecated, please use the method exported by @code-arch/foundation-sdk in the future*/
|
||||
useSpaceList,
|
||||
} from '@coze-foundation/space-store';
|
||||
|
||||
export { useAuthStore } from './auth';
|
||||
|
||||
/** @deprecated - 持久化方案有问题,废弃 */
|
||||
/** @Deprecated - problem with persistence scheme, deprecated */
|
||||
export { clearStorage } from './utils/get-storage';
|
||||
|
||||
export { useSpaceGrayStore, TccKey } from './space-gray';
|
||||
|
||||
@@ -58,7 +58,7 @@ const fetchTccConfig = async spaceId => {
|
||||
}
|
||||
};
|
||||
|
||||
/* 通过 tcc 动态配置的 space 粒度的灰度 */
|
||||
/* Dynamically configured grey release of space granularity via tcc */
|
||||
export const useSpaceGrayStore = create<TccStore & TccAction>()(
|
||||
devtools(
|
||||
(set, get) => ({
|
||||
|
||||
@@ -26,7 +26,7 @@ const instance = localForage.createInstance({
|
||||
const throttleTime = 1000;
|
||||
|
||||
/**
|
||||
* 获取store数据持久化引擎
|
||||
* Get stored data persistence engine
|
||||
*/
|
||||
export const getStorage = (): StateStorage => {
|
||||
const persistStorage: StateStorage = {
|
||||
@@ -42,5 +42,5 @@ export const getStorage = (): StateStorage => {
|
||||
return persistStorage;
|
||||
};
|
||||
|
||||
/** @deprecated - 持久化方案有问题,废弃 */
|
||||
/** @Deprecated - problem with persistence scheme, deprecated */
|
||||
export const clearStorage = instance.clear;
|
||||
|
||||
Reference in New Issue
Block a user