update-api-client-tests
Update api-client integration tests after spec regeneration. Use when generated code has changed and tests need to match.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Update api-client integration tests after spec regeneration. Use when generated code has changed and tests need to match.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | update-api-client-tests |
| description | Update api-client integration tests after spec regeneration. Use when generated code has changed and tests need to match. |
The integration tests in packages/api-client/src/__tests__/ use generated functions from packages/api-client/src/generated/. When the OpenAPI spec changes and code is regenerated, the tests may break.
Run the typecheck to find errors in the test files:
npx tsc --noEmit -p packages/api-client/tsconfig.json
If there are no errors, the tests already match the generated code — stop here.
For each error, read the relevant generated file to understand the new signature. Generated code lives in:
packages/api-client/src/generated/crm/crm.ts — account and person endpointspackages/api-client/src/generated/support/support.ts — case endpointspackages/api-client/src/generated/models/ — all model and body typesCommon changes to look for:
Apply fixes to the test files:
packages/api-client/src/__tests__/accounts-crud.integration.test.tspackages/api-client/src/__tests__/people.integration.test.tspackages/api-client/src/__tests__/support.integration.test.tspackages/api-client/src/__tests__/crm.integration.test.tsclient("path", ...) ky calls for operations that have a generated function. This is the entire point: if the spec changes, the test should break at compile time.opts(client) from ./setup.js to pass the ky instance as the options argument.as FooBody — the generated body types extend AbstractBean which requires Created and Updated, but the API doesn't need these on requests.as unknown as Model — list endpoints return PaginatedResponse<T> at runtime but the generated response type doesn't reflect this.afterAll — it prevents test data from accumulating.Importing generated functions:
import { accountGetAllAccounts, accountAddAccount } from "../generated/crm/crm.js";
import type { Account, AccountAddAccountBody } from "../generated/models/index.js";
Calling a list endpoint:
const res = await accountGetAllAccounts(undefined, opts(client));
const body = res.data as unknown as PaginatedResponse<Account>;
Calling a create endpoint:
const res = await accountAddAccount(
{ Name: "Test", PersonAccount: [...] } as AccountAddAccountBody,
undefined, // params
opts(client),
);
const created = res.data as unknown as Account;
Calling a get/update/delete endpoint:
const res = await accountGetAccount(uid, opts(client));
const res = await accountUpdateAccount(uid, body as AccountUpdateAccountBody, opts(client));
const res = await accountDeleteAccount(uid, opts(client));
Run the typecheck again to confirm all errors are resolved:
npx tsc --noEmit -p packages/api-client/tsconfig.json