Update mock api#33
Conversation
fcb0e15 to
f4c3a68
Compare
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughMock API endpoints and data structures are updated to align with actual API specifications. A user endpoint route is modified to remove optional parameters, response schemas are restructured with renamed fields, and new conditional handling is added for recovery actions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
mock.mjs (1)
114-115: Stabilize/userInforesponse across requests.Line 115 regenerates a different user object on each call, which can cause flaky UI assertions and inconsistent state handling. Prefer returning a cached mock user for the server lifecycle.
♻️ Proposed change
+const mockedUserInfo = user(); + app.get("/cmk/v1/tenant1-id/userInfo", (req, res) => { - res.json(user()); + res.json(mockedUserInfo); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mock.mjs` around lines 114 - 115, The handler registered with app.get("/cmk/v1/tenant1-id/userInfo") calls user() each request which returns a new object and causes flaky tests; fix by creating a single cached mock user at module scope (e.g., cachedUser) initialized once (via user() or a factory) and have the route handler return that cachedUser instead of calling user() on every request; update any tests that expect idempotent responses to rely on the stable cachedUser and ensure any deliberate variations are produced by an explicit endpoint or test helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@mockServer/mockdata/user.mjs`:
- Around line 6-7: The givenName field in mockServer/mockdata/user.mjs is using
chance.name() which returns a full name and conflicts with the separate
familyName field; update the givenName assignment to use chance.first() instead
of chance.name() so givenName contains only the first/given name while
familyName remains chance.last().
---
Nitpick comments:
In `@mock.mjs`:
- Around line 114-115: The handler registered with
app.get("/cmk/v1/tenant1-id/userInfo") calls user() each request which returns a
new object and causes flaky tests; fix by creating a single cached mock user at
module scope (e.g., cachedUser) initialized once (via user() or a factory) and
have the route handler return that cachedUser instead of calling user() on every
request; update any tests that expect idempotent responses to rely on the stable
cachedUser and ensure any deliberate variations are produced by an explicit
endpoint or test helper.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f6f07055-9087-4047-8efe-4be387bc0c08
📒 Files selected for processing (3)
mock.mjsmockServer/mockdata/systems.mjsmockServer/mockdata/user.mjs
| givenName: chance.name(), | ||
| familyName: chance.last(), |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In chance@1.1.13, what is the return format of chance.name() vs chance.first(), and which is appropriate for a "givenName" field?
💡 Result:
chance.name()returns a full name string (e.g.,"Dafi Vatemi", optionally including middle/prefix/suffix). [1]chance.first()returns a first/given name string only (e.g.,"Leila"). [2]
For a "givenName" field, use chance.first(). [2]
Sources: [1] [2]
Use chance.first() for givenName instead of chance.name().
Line 6 uses chance.name(), which returns a full name string. This creates a schema mismatch since givenName should contain only the given/first name, not a full name that duplicates the separate familyName on line 7.
Proposed fix
export default () => {
return {
identifier: chance.guid(),
- givenName: chance.name(),
+ givenName: chance.first(),
familyName: chance.last(),
email: chance.email(),
role: chance.pickone(['KEY_ADMINISTRATOR', 'TENANT_ADMINISTRATOR', 'TENANT_AUDITOR']),
};
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| givenName: chance.name(), | |
| familyName: chance.last(), | |
| export default () => { | |
| return { | |
| identifier: chance.guid(), | |
| givenName: chance.first(), | |
| familyName: chance.last(), | |
| email: chance.email(), | |
| role: chance.pickone(['KEY_ADMINISTRATOR', 'TENANT_ADMINISTRATOR', 'TENANT_AUDITOR']), | |
| }; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@mockServer/mockdata/user.mjs` around lines 6 - 7, The givenName field in
mockServer/mockdata/user.mjs is using chance.name() which returns a full name
and conflicts with the separate familyName field; update the givenName
assignment to use chance.first() instead of chance.name() so givenName contains
only the first/given name while familyName remains chance.last().
bb8418b
f4c3a68 to
bb8418b
Compare
Resolves #32
Summary by CodeRabbit