Frun1na opened a new pull request, #6788:
URL: https://github.com/apache/rocketmq-dashboard/pull/6788

   ### Which Issue(s) This PR Fixes
   
   - Fixes #6787
   
   ### Brief Description
   
   Four registry calls in `web/src/services/clusterService.ts` - 
`listNameserverRegistry` (:54), `createNameserverRegistry` (:58), 
`updateNameserverRegistry` (:67) and `deleteNameserverRegistry` (:77) - had no 
mock branch while every other call in the file has one, so in mock-data mode 
they left the demo data source and went to the real backend. The cluster page's 
NameServer registry then listed nothing without a backend (its `loadNsRegistry` 
catch clears the failure to `[]`, `web/src/pages/cluster/index.tsx:239-247`) 
and its three mutations wrote to the real registry - or failed with a request 
error - where the demo should stay self-contained.
   
   The mock now owns a registry store derived from the `nameServers` the mock 
clusters already declare, following the certificate store pattern in the same 
file: the list returns copies, and the mutations apply the endpoint's rules 
(blank name, duplicate name and unknown id are refused with the endpoint's 
messages, and omitted optional fields are cleared the way the endpoint clears 
their columns). No new fixture file, and the load-failure state that #6090 
changes is untouched.
   
   The two mutation signatures also gain the `k8sId` field the page already 
sends and the API and `CreateNameserverRegistryDTO` already accept; without it 
the service could not forward the field it documents, and the new regression 
test does not type-check.
   
   ### How Did You Test This Change?
   
   ```
   $ cd web && npx vitest run src/services/clusterService.test.ts
    ✓ src/services/clusterService.test.ts (10 tests) 12ms
    Test Files  1 passed (1)
         Tests  10 passed (10)
   ```
   
   The mapped checks for the two changed web files:
   
   ```
   $ npx eslint src/services/clusterService.test.ts 
src/services/clusterService.ts   # clean
   $ npx prettier --check src/services/clusterService.test.ts 
src/services/clusterService.ts
   Checking formatting...
   All matched files use Prettier code style!
   $ npx vitest related --run src/services/clusterService.test.ts 
src/services/clusterService.ts
    Test Files  8 passed (8)      # includes the cluster page suite
         Tests  136 passed (136)
   $ npx tsc -b        # clean
   ```
   
   The new tests fail without the fix (only the service file reverted, tests 
kept):
   
   ```
   $ git checkout -- web/src/services/clusterService.ts
   $ npx vitest run src/services/clusterService.test.ts
    FAIL  src/services/clusterService.test.ts > clusterService mock NameServer 
registry > serves the registry from the mock clusters instead of the real 
backend
   AxiosError: Network Error
    ❯ XMLHttpRequest.handleError node_modules/axios/lib/adapters/xhr.js:124:21
    ❯ Module.listNameserverRegistry src/api/cluster.ts:267:15
    ❯ src/services/clusterService.test.ts:216:21
   
    FAIL  src/services/clusterService.test.ts > clusterService mock NameServer 
registry > keeps registry mutations in the mock store and applies the endpoint 
rules
   AssertionError: expected [Function] to throw error including 'name is 
required' but got 'Network Error'
   
   Expected: "name is required"
   Received: "Network Error"
   
    Test Files  1 failed (1)
         Tests  2 failed | 8 passed (10)
   ```
   
   The stack line is the point: with the fix reverted the mock-mode call really 
reaches `src/api/cluster.ts`, which is the defect; with it, the same assertions 
read the demo store instead. Restoring the branches turns both green.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`feat:` / `fix:` / 
`refactor:` / `chore:` / `docs:` / `perf:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
   - [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks)
   - [ ] New source files carry the ASF license header
   - [ ] Documentation touched where behaviour changed (README / `docs/` / 
in-app help)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to