fix(api, ETAC): Update Test Setup for BED-7401#2416
Conversation
📝 WalkthroughWalkthroughThis PR adds authenticated context injection to three test cases in the API v2 test suite. It imports authentication and context utilities, then modifies the SortingError, ColumnNotFilterable, and InvalidFilterPredicate test scenarios to construct and apply an authenticated context with an empty user before executing test assertions. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmd/api/src/api/v2/apitest/case.go (1)
41-47: Consolidate duplicated auth-context setup and align local variable style.The same context-construction block is repeated in three cases. Please extract a helper and use a richer local name with a hoisted
var (...)block.♻️ Proposed refactor
+func applyEmptyOwnerAuthContext(input *Input) { + var ( + requestContext = bhectx.Context{ + AuthCtx: auth.Context{ + Owner: model.User{}, + }, + } + ) + + SetContext(input, requestContext.ConstructGoContext()) +} + func NewSortingErrorCase() Case { return Case{ Name: "SortingError", Input: func(input *Input) { AddQueryParam(input, "sort_by", "definitelyInvalidColumn") - bhctx := bhectx.Context{ - AuthCtx: auth.Context{ - Owner: model.User{}, - }, - } - SetContext(input, bhctx.ConstructGoContext()) + applyEmptyOwnerAuthContext(input) }, @@ func NewColumnNotFilterableCase() Case { return Case{ Name: "ColumnNotFilterable", Input: func(input *Input) { AddQueryParam(input, "definitelyInvalidColumn", "gt:0") - - bhctx := bhectx.Context{ - AuthCtx: auth.Context{ - Owner: model.User{}, - }, - } - SetContext(input, bhctx.ConstructGoContext()) + applyEmptyOwnerAuthContext(input) }, @@ func NewInvalidFilterPredicateCase(validColumn string) Case { return Case{ Name: "InvalidFilterPredicate", Input: func(input *Input) { AddQueryParam(input, validColumn, "definitelyInvalidPredicate:0") - bhctx := bhectx.Context{ - AuthCtx: auth.Context{ - Owner: model.User{}, - }, - } - - SetContext(input, bhctx.ConstructGoContext()) + applyEmptyOwnerAuthContext(input) },As per coding guidelines: “Group variable initializations in a
var ( ... )block and hoist them to the top of the function when possible” and “Prefer rich variable names, for example:databaseInterfaceinstead ofdiordbi.”Also applies to: 62-68, 82-89
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/api/src/api/v2/apitest/case.go` around lines 41 - 47, Extract the repeated auth-context construction into a single helper (e.g., newBaseAuthContext or buildAuthGoContext) and replace the three inline blocks with calls to that helper; hoist any local variables into a var (...) block at the top of the function and use a descriptive name such as baseAuthContext for the bhctx.Context instance, then call SetContext(input, baseAuthContext.ConstructGoContext()) where the current inline bhctx/auth.Context construction appears (locations referencing bhctx.Context, auth.Context, SetContext, and ConstructGoContext).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@cmd/api/src/api/v2/apitest/case.go`:
- Around line 41-47: Extract the repeated auth-context construction into a
single helper (e.g., newBaseAuthContext or buildAuthGoContext) and replace the
three inline blocks with calls to that helper; hoist any local variables into a
var (...) block at the top of the function and use a descriptive name such as
baseAuthContext for the bhctx.Context instance, then call SetContext(input,
baseAuthContext.ConstructGoContext()) where the current inline
bhctx/auth.Context construction appears (locations referencing bhctx.Context,
auth.Context, SetContext, and ConstructGoContext).
Description
This updates test case setup in order for the related BHE PR to pass tests
Motivation and Context
Resolves: BED-7401
How Has This Been Tested?
NO-OP as this just changes unit tests
Screenshots (optional):
Types of changes
Checklist:
Summary by CodeRabbit