-
Notifications
You must be signed in to change notification settings - Fork 17
Add Business Information Fields to Registration new
#464
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
478e934
feat: add monthly volume, business website, and nature of business fi…
sundayonah dc9c400
refactor: update monthly volume handling to support nullable values a…
sundayonah f413526
refactor: remove commented-out monthly volume validation code from Re…
sundayonah c2b70eb
fix: move business info validation to RegisterPayload
sundayonah fbc3e4c
fix: add extra_signup_fields migration and update atlas.sum
sundayonah 765b9ef
Merge branch 'main' into feature/add-business-info-registration-new
sundayonah 7bedbbd
feat: add monthly volume, business website, and nature of business fi…
sundayonah 96898f8
fix: add extra_signup_fields migration and update atlas.sum
sundayonah 9f708c0
fix: ent codegen errors for ProviderProfile and SenderProfile
sundayonah 8f84aed
fix: removed MonthlyVolume: nil from RegisterPayload in auth_test.go …
sundayonah 14344be
fix: monthlyvolume validation in RegisterPayload
sundayonah cd2aa5f
chore: remove current.sql from gitignore
sundayonah 66f4582
refactor: clean up sender and provider profile schemas and migrations
chibie df7b97b
fix: resolve test failures by regenerating Ent schema and updating deps
sundayonah 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ import ( | |
svc "github.com/paycrest/aggregator/services" | ||
db "github.com/paycrest/aggregator/storage" | ||
"github.com/paycrest/aggregator/types" | ||
"github.com/paycrest/aggregator/utils" | ||
"github.com/shopspring/decimal" | ||
"github.com/spf13/viper" | ||
"golang.org/x/crypto/bcrypt" | ||
|
||
|
@@ -98,12 +100,15 @@ func TestAuth(t *testing.T) { | |
t.Run("with valid payload and both sender and provider scopes", func(t *testing.T) { | ||
// Test register with valid payload | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Currencies: []string{"NGN"}, | ||
Scopes: []string{"sender", "provider"}, | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Currencies: []string{"NGN"}, | ||
Scopes: []string{"sender", "provider"}, | ||
MonthlyVolume: utils.DecimalPtr(decimal.NewFromInt(1000)), | ||
BusinessWebsite: "https://example.com", | ||
NatureOfBusiness: "Example business", | ||
} | ||
|
||
header := map[string]string{ | ||
|
@@ -166,11 +171,14 @@ func TestAuth(t *testing.T) { | |
t.Run("with only sender scope payload", func(t *testing.T) { | ||
// Test register with valid payload | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password1", | ||
Scopes: []string{"sender"}, | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password1", | ||
Scopes: []string{"sender"}, | ||
MonthlyVolume: utils.DecimalPtr(decimal.NewFromInt(1000)), | ||
BusinessWebsite: "https://example.com", | ||
NatureOfBusiness: "Example business", | ||
} | ||
|
||
res, err := test.PerformRequest(t, "POST", "/register", payload, nil, router) | ||
|
@@ -224,12 +232,13 @@ func TestAuth(t *testing.T) { | |
t.Run("with only provider scope payload", func(t *testing.T) { | ||
// Test register with valid payload | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password2", | ||
Currencies: []string{"NGN"}, | ||
Scopes: []string{"provider"}, | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password2", | ||
Currencies: []string{"NGN"}, | ||
Scopes: []string{"provider"}, | ||
MonthlyVolume: utils.DecimalPtr(decimal.NewFromInt(1000)), | ||
} | ||
|
||
header := map[string]string{ | ||
|
@@ -305,30 +314,139 @@ func TestAuth(t *testing.T) { | |
// assert.Equal(t, http.StatusInternalServerError, res.Code) | ||
// }) | ||
}) | ||
t.Run("with NatureOfBusiness exceeding 255 characters", func(t *testing.T) { | ||
longDescription := strings.Repeat("a", 256) | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Scopes: []string{"sender"}, | ||
MonthlyVolume: utils.DecimalPtr(decimal.NewFromInt(1000)), | ||
BusinessWebsite: "https://example.com", | ||
NatureOfBusiness: longDescription, | ||
} | ||
|
||
res, err := test.PerformRequest(t, "POST", "/register", payload, nil, router) | ||
assert.NoError(t, err) | ||
|
||
// Assert the response body | ||
assert.Equal(t, http.StatusBadRequest, res.Code) | ||
|
||
var response types.Response | ||
err = json.Unmarshal(res.Body.Bytes(), &response) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "Nature of business exceeds character limit", response.Message) | ||
assert.Nil(t, response.Data) | ||
}) | ||
t.Run("with invalid BusinessWebsite", func(t *testing.T) { | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Scopes: []string{"sender"}, | ||
MonthlyVolume: utils.DecimalPtr(decimal.NewFromInt(1000)), | ||
BusinessWebsite: "invalid-url", | ||
NatureOfBusiness: "Example business", | ||
} | ||
|
||
res, err := test.PerformRequest(t, "POST", "/register", payload, nil, router) | ||
assert.NoError(t, err) | ||
|
||
// Assert the response body | ||
assert.Equal(t, http.StatusBadRequest, res.Code) | ||
|
||
var response types.Response | ||
err = json.Unmarshal(res.Body.Bytes(), &response) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "Invalid business website URL", response.Message) | ||
assert.Nil(t, response.Data) | ||
}) | ||
t.Run("with missing MonthlyVolume", func(t *testing.T) { | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Scopes: []string{"sender"}, | ||
} | ||
|
||
res, err := test.PerformRequest(t, "POST", "/register", payload, nil, router) | ||
assert.NoError(t, err) | ||
|
||
// Assert the response body | ||
assert.Equal(t, http.StatusBadRequest, res.Code) | ||
|
||
var response types.Response | ||
err = json.Unmarshal(res.Body.Bytes(), &response) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "monthly volume must be provided and greater than zero", response.Message) | ||
assert.Nil(t, response.Data) | ||
}) | ||
t.Run("with MonthlyVolume as 0", func(t *testing.T) { | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Scopes: []string{"sender"}, | ||
MonthlyVolume: utils.DecimalPtr(decimal.NewFromInt(0)), | ||
} | ||
|
||
res, err := test.PerformRequest(t, "POST", "/register", payload, nil, router) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, http.StatusBadRequest, res.Code) | ||
|
||
var response types.Response | ||
err = json.Unmarshal(res.Body.Bytes(), &response) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "monthly volume must be a positive number", response.Message) | ||
assert.Nil(t, response.Data) | ||
}) | ||
t.Run("from the provider app", func(t *testing.T) { | ||
// Test register with valid payload | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Currencies: []string{"NGN", "KES"}, | ||
Scopes: []string{"provider"}, | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Currencies: []string{"NGN", "KES"}, | ||
Scopes: []string{"provider"}, | ||
MonthlyVolume: utils.DecimalPtr(decimal.NewFromInt(1000)), | ||
} | ||
|
||
headers := map[string]string{ | ||
"Client-Type": "mobile", | ||
} | ||
|
||
res, err := test.PerformRequest(t, "POST", "/register", payload, headers, router) | ||
// First, ensure the currency exists in the database | ||
ctx := context.Background() | ||
_, err := db.Client.FiatCurrency.Create(). | ||
SetCode("NG"). | ||
SetName("Nigerian Naira"). | ||
SetShortName("NGN"). | ||
SetSymbol("#"). | ||
SetMarketRate(decimal.NewFromInt(1000)). | ||
SetIsEnabled(true). | ||
Save(ctx) | ||
assert.NoError(t, err) | ||
|
||
// Assert the response body | ||
assert.Equal(t, http.StatusCreated, res.Code) | ||
res, err := test.PerformRequest(t, "POST", "/register", payload, headers, router) | ||
assert.NoError(t, err) | ||
|
||
var response types.Response | ||
err = json.Unmarshal(res.Body.Bytes(), &response) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, http.StatusCreated, res.Code) | ||
|
||
if res.Code != http.StatusCreated { | ||
t.Logf("Error Message: %s", response.Message) | ||
return | ||
} | ||
|
||
data, ok := response.Data.(map[string]interface{}) | ||
assert.True(t, ok, "response.Data is not of type map[string]interface{}") | ||
assert.NotNil(t, data, "response.Data is nil") | ||
|
@@ -346,7 +464,7 @@ func TestAuth(t *testing.T) { | |
q.WithAPIKey() | ||
}). | ||
WithSenderProfile(). | ||
Only(context.Background()) | ||
Only(ctx) | ||
assert.NoError(t, err) | ||
|
||
assert.NotNil(t, user) | ||
|
@@ -357,11 +475,12 @@ func TestAuth(t *testing.T) { | |
t.Run("with existing user", func(t *testing.T) { | ||
// Test register with existing user | ||
payload := types.RegisterPayload{ | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Scopes: []string{"sender"}, | ||
FirstName: "Ike", | ||
LastName: "Ayo", | ||
Email: "[email protected]", | ||
Password: "password", | ||
Scopes: []string{"sender"}, | ||
MonthlyVolume: nil, | ||
} | ||
|
||
res, err := test.PerformRequest(t, "POST", "/register", payload, nil, router) | ||
|
10 changes: 9 additions & 1 deletion
10
ent/migrate/migrations/20240905170202_sender_provider_id.sql
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 |
---|---|---|
@@ -1,4 +1,12 @@ | ||
-- Modify "provider_profiles" table | ||
ALTER TABLE "provider_profiles" DROP COLUMN "is_partner"; | ||
ALTER TABLE "provider_profiles" | ||
DROP COLUMN "is_partner", | ||
ADD COLUMN "monthly_volume" decimal DEFAULT NULL; | ||
|
||
-- Modify "sender_profiles" table | ||
ALTER TABLE "sender_profiles" ADD COLUMN "provider_id" character varying NULL; | ||
ALTER TABLE "sender_profiles" | ||
ADD COLUMN "provider_id" character varying NULL, | ||
ADD COLUMN "monthly_volume" decimal DEFAULT NULL, | ||
ADD COLUMN "business_website" varchar DEFAULT NULL, | ||
ADD COLUMN "nature_of_business" varchar(255) DEFAULT NULL; | ||
chibie marked this conversation as resolved.
Show resolved
Hide resolved
|
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.