Repository navigation
feat: add billing reconciliation review and user-blocking controls #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
900dd3b
fix bugs
CSCITech 838aa63
fix bugs
CSCITech 488b765
fix: harden billing reconciliation review controls
CSCITech 2635ba7
fix: address billing reconciliation review follow-ups
CSCITech c795d6f
fix: validate smart ops reconciliation workflows
CSCITech 96bc20a
fix: address final smart ops review feedback
CSCITech d30a569
fix: correct Russian smart ops duration labels
CSCITech 5b1c4eb
fix: resolve billing reconciliation review feedback
CSCITech 99be40b
fix: reject stale settlement reviews
CSCITech 53cbba7
fix: support legacy reconciliation review rows
CSCITech 42acfaf
fix: preserve reviewed reconciliation decisions
CSCITech a779340
fix: align Vietnamese root administrator wording
CSCITech 84628e2
test: centralize reconciliation alert state isolation
CSCITech b252aa0
test: harden smart ops review coverage
CSCITech db0dfd8
fix: refine reconciliation locale wording
CSCITech b8cd2e2
fix: clarify reconciliation blocking policy
CSCITech ec1465f
test: keep removed locale key assertion type-safe
CSCITech b11aeb4
refactor: validate reconciliation responses with zod
CSCITech 81ca588
fix: correct Russian alert status wording
CSCITech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/MAX-API-Next/MAX-API/common" | ||
| "github.com/MAX-API-Next/MAX-API/model" | ||
| "github.com/gin-gonic/gin" | ||
| "github.com/glebarez/sqlite" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| func TestBillingSettlementMutationRequestsPreserveExplicitFalse(t *testing.T) { | ||
| var policy billingSettlementBlockingPolicyRequest | ||
| require.NoError(t, common.Unmarshal([]byte(`{"block_user_by_default":false}`), &policy)) | ||
| require.NotNil(t, policy.BlockUserByDefault) | ||
| assert.False(t, *policy.BlockUserByDefault) | ||
|
|
||
| var review billingSettlementReviewRequest | ||
| require.NoError(t, common.Unmarshal([]byte(`{"block_user":false,"note":"verified"}`), &review)) | ||
| require.NotNil(t, review.BlockUser) | ||
| assert.False(t, *review.BlockUser) | ||
| } | ||
|
|
||
| func TestReviewBillingSettlementAuditRecordsActingAdministrator(t *testing.T) { | ||
| gin.SetMode(gin.TestMode) | ||
| oldDB := model.DB | ||
| oldLogDB := model.LOG_DB | ||
| oldRedisEnabled := common.RedisEnabled | ||
| oldMemoryCacheEnabled := common.MemoryCacheEnabled | ||
| common.RedisEnabled = false | ||
| common.MemoryCacheEnabled = false | ||
|
|
||
| dsn := fmt.Sprintf("file:%s?mode=memory&cache=shared", strings.ReplaceAll(t.Name(), "/", "_")) | ||
| db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{}) | ||
| require.NoError(t, err) | ||
| require.NoError(t, db.AutoMigrate(&model.User{}, &model.BillingSettlement{}, &model.Log{})) | ||
| model.DB = db | ||
| model.LOG_DB = db | ||
| t.Cleanup(func() { | ||
| if sqlDB, dbErr := db.DB(); dbErr == nil { | ||
| _ = sqlDB.Close() | ||
| } | ||
| model.DB = oldDB | ||
| model.LOG_DB = oldLogDB | ||
| common.RedisEnabled = oldRedisEnabled | ||
| common.MemoryCacheEnabled = oldMemoryCacheEnabled | ||
| }) | ||
|
|
||
| administrator := model.User{ | ||
| Id: 7101, | ||
| Username: "billing-review-admin", | ||
| AffCode: "billing-review-admin-aff", | ||
| Role: common.RoleRootUser, | ||
| Status: common.UserStatusEnabled, | ||
| Group: "default", | ||
| } | ||
| owner := model.User{ | ||
| Id: 7102, | ||
| Username: "billing-review-owner", | ||
| AffCode: "billing-review-owner-aff", | ||
| Role: common.RoleCommonUser, | ||
| Status: common.UserStatusEnabled, | ||
| Group: "default", | ||
| } | ||
| require.NoError(t, db.Create(&administrator).Error) | ||
| require.NoError(t, db.Create(&owner).Error) | ||
| settlement := model.BillingSettlement{ | ||
| OperationKey: "request:controller-review-audit:finalize", | ||
| Source: model.BillingSettlementSourceWallet, | ||
| UserID: owner.Id, | ||
| FundingDelta: 10, | ||
| TokenDelta: 10, | ||
| Status: model.BillingSettlementStatusPending, | ||
| CreatedAt: 1, | ||
| UpdatedAt: 1, | ||
| Revision: 1, | ||
| } | ||
| require.NoError(t, db.Create(&settlement).Error) | ||
|
|
||
| recorder := httptest.NewRecorder() | ||
| ctx, _ := gin.CreateTestContext(recorder) | ||
| ctx.Request = httptest.NewRequest( | ||
| http.MethodPost, | ||
| fmt.Sprintf("/api/smart-ops/billing-settlements/%d/review", settlement.ID), | ||
| bytes.NewBufferString(`{"block_user":false,"note":"Verified provider evidence"}`), | ||
| ) | ||
| ctx.Params = gin.Params{{Key: "id", Value: fmt.Sprintf("%d", settlement.ID)}} | ||
| ctx.Set("id", administrator.Id) | ||
| ctx.Set("username", administrator.Username) | ||
| ctx.Set("role", administrator.Role) | ||
|
|
||
| ReviewBillingSettlement(ctx) | ||
|
|
||
| require.Equal(t, http.StatusOK, recorder.Code, recorder.Body.String()) | ||
| var audit model.Log | ||
| require.NoError(t, db.Where("type = ?", model.LogTypeManage).Order("id DESC").First(&audit).Error) | ||
| assert.Equal(t, administrator.Id, audit.UserId) | ||
| assert.Equal(t, administrator.Username, audit.Username) | ||
| var other struct { | ||
| Op struct { | ||
| Action string `json:"action"` | ||
| Params map[string]interface{} `json:"params"` | ||
| } `json:"op"` | ||
| } | ||
| require.NoError(t, common.UnmarshalJsonStr(audit.Other, &other)) | ||
| assert.Equal(t, "billing.reconciliation_review", other.Op.Action) | ||
| assert.EqualValues(t, owner.Id, other.Op.Params["target_user_id"]) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.