feat: add DailyEstimatedVolume field to KYBProfile and related struct…#693
feat: add DailyEstimatedVolume field to KYBProfile and related struct…#693onahprosper merged 4 commits intomainfrom
Conversation
…ures - Introduced the DailyEstimatedVolume field in the KYBProfile schema and updated the corresponding input and response types. - Enhanced the KYB submission handling to include DailyEstimatedVolume, ensuring it is processed and validated correctly. - Updated tests to reflect the addition of DailyEstimatedVolume, ensuring comprehensive coverage for the new field. - Added necessary mutations and predicates for DailyEstimatedVolume to support database operations and queries.
- Added assertion for DailyEstimatedVolume in the TestIndex function to ensure the new field is correctly processed and validated in the KYBProfile. - Updated test cases to reflect the recent addition of DailyEstimatedVolume, enhancing test coverage for the KYB submission process.
📝 WalkthroughWalkthroughAdds a new DailyEstimatedVolume field across KYB: API input/output types, Ent schema/mutations/builders, DB migration, controller wiring, and tests to accept, persist, query, and return daily estimated volume. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Controller as Controller
participant Types as TypesBinder
participant Ent as EntBuilder
participant DB as Database
Client->>Controller: POST/PUT KYB submission (dailyEstimatedVolume)
Controller->>Types: bind request -> KYBSubmissionInput.DailyEstimatedVolume
Controller->>Ent: call SetDailyEstimatedVolume on KYBProfile create/update
Ent->>DB: INSERT/UPDATE kyb_profiles.daily_estimated_volume
DB-->>Ent: confirm write
Ent-->>Controller: return KYBProfile with DailyEstimatedVolume
Controller->>Client: respond with KYBDocumentsResponse.dailyEstimatedVolume
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
controllers/index_test.go (1)
376-381: Add assertions to cover DailyEstimatedVolume in create + documents responses.
This will ensure the new field is validated end‑to‑end, not just on resubmission.🧪 Suggested test additions
@@ assert.Equal(t, validKYBSubmission.CompanyName, kybProfile.CompanyName) assert.Equal(t, validKYBSubmission.RegisteredBusinessAddress, kybProfile.RegisteredBusinessAddress) + assert.Equal(t, validKYBSubmission.DailyEstimatedVolume, kybProfile.DailyEstimatedVolume) @@ assert.Equal(t, kybData.CompanyName, data["companyName"]) assert.Equal(t, kybData.MobileNumber, data["mobileNumber"]) assert.Equal(t, kybData.RegisteredBusinessAddress, data["registeredBusinessAddress"]) + assert.Equal(t, kybData.DailyEstimatedVolume, data["dailyEstimatedVolume"])Also applies to: 775-780
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controllers/index_test.go` around lines 376 - 381, The tests currently set validKYBSubmission.DailyEstimatedVolume but do not assert it in the create and documents responses; update the tests in controllers/index_test.go to assert that the API responses include DailyEstimatedVolume (e.g., after calling the KYB creation helper and when fetching documents) by checking the response JSON/body contains the same DailyEstimatedVolume value from validKYBSubmission, and add the same assertion to the resubmission/document-related test paths (the tests around the validKYBSubmission variable and the create/documents response checks) so the new field is validated end-to-end.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ent/schema/kybprofile.go`:
- Line 30: The new schema adds a non-nullable column via
field.String("daily_estimated_volume") which will break migrations for the
existing kyb_profiles table; update the schema definition for
daily_estimated_volume to allow safe migration by making it have a default or be
optional (e.g., change field.String("daily_estimated_volume") to include
.Default("") if an empty string is acceptable or .Optional() if it should be
nullable) so ALTER TABLE can succeed without failing on existing rows.
---
Nitpick comments:
In `@controllers/index_test.go`:
- Around line 376-381: The tests currently set
validKYBSubmission.DailyEstimatedVolume but do not assert it in the create and
documents responses; update the tests in controllers/index_test.go to assert
that the API responses include DailyEstimatedVolume (e.g., after calling the KYB
creation helper and when fetching documents) by checking the response JSON/body
contains the same DailyEstimatedVolume value from validKYBSubmission, and add
the same assertion to the resubmission/document-related test paths (the tests
around the validKYBSubmission variable and the create/documents response checks)
so the new field is validated end-to-end.
…r DailyEstimatedVolume - Introduced SetNillableDailyEstimatedVolume method in KYBProfileCreate to conditionally set the daily_estimated_volume field. - Defined DefaultDailyEstimatedVolume in the KYBProfile schema to ensure a default value is used during creation. - Updated schema migration to set a default value for daily_estimated_volume in the database. - Enhanced runtime initialization to include the new default value for DailyEstimatedVolume.
- Introduced a new column "daily_estimated_volume" in the "kyb_profiles" table with a default value of an empty string. - Updated migration files to reflect this schema change, ensuring the database structure aligns with recent enhancements to the KYBProfile schema.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ent/migrate/migrations/20260218105934_add_daily_estimated_volume.sql`:
- Line 2: The migration adds kyb_profiles.daily_estimated_volume as NOT NULL
DEFAULT '' which leaves existing rows with a semantic empty string; either
backfill existing rows or make the column nullable so legacy rows can be
distinguished. Fix by one of: (A) add a backfill UPDATE in the migration that
sets a meaningful placeholder (e.g., 'unknown' or calculated historical value)
for all rows in kyb_profiles, then ALTER TABLE to set NOT NULL and keep/adjust
DEFAULT as desired; or (B) change the DDL to character varying NULL (remove NOT
NULL and DEFAULT '') so legacy rows remain NULL and the application (GET
/v1/kyb-submission and binding:"required" for new input) can treat NULL as "not
set"; if you choose (A) optionally add a CHECK constraint (CHECK
(daily_estimated_volume <> '')) only after the backfill completes.
Description
This PR updates the aggregator KYB flow to:
Add required Daily Estimated Volume
dailyEstimatedVolumeon KYB submission (company-level).kyb_profile.daily_estimated_volume, returned in GET/v1/kyb-submission.Align with company vs beneficial-owner proof of address
KYBSubmissionInputdoes not include company-levelproofOfResidentialAddressUrl; no breaking change if the dashboard already omits it.Implementation details
Types (
types/types.go):KYBSubmissionInput: addedDailyEstimatedVolumewithbinding:"required".KYBDocumentsResponse: addedDailyEstimatedVolumefor GET response.Ent schema (
ent/schema/kybprofile.go): addedfield.String("daily_estimated_volume").Ent codegen was run (
go generate ./ent).Controller (
controllers/index.go):DailyEstimatedVolumefrom input.DailyEstimatedVolumein response.Tests (
controllers/index_test.go):KYBSubmissionInputliterals and KYB profile creates includeDailyEstimatedVolume.DailyEstimatedVolume.Testing
Unit/integration:
go test ./controllers -run TestIndex/HandleKYBSubmission -vgo test ./controllers -run TestIndex/GetKYBDocuments -vDailyEstimatedVolume; resubmission case asserts the field is persisted and returned.Manual:
/v1/kyb-submissionand confirmdailyEstimatedVolumein response.dailyEstimatedVolumein POST body and confirm 400 "Invalid input".Environment: Go 1.25, Windows; tests use in-memory SQLite via enttest.
This change adds test coverage for new/changed/fixed functionality
(Existing tests updated for new field; no new dedicated test file.)
Checklist
mainBy submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.
Summary by CodeRabbit