-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add username to get account #265
base: main
Are you sure you want to change the base?
Changes from all commits
4f2e0bb
b02a711
457bd6f
927c32d
354c647
14d9b99
f610612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,29 @@ import ( | |
|
||
func TestAccountGetter(t *testing.T) { | ||
|
||
t.Run("get username", func(t *testing.T) { | ||
accountStore := mock.NewAccountStore() | ||
acc, err := accountStore.Create("[email protected]", []byte("password")) | ||
require.NoError(t, err) | ||
|
||
accountID := acc.ID | ||
|
||
account, err := services.AccountGetter(accountStore, services.AccountGetterParams{ | ||
Username: &acc.Username, | ||
}) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, accountID, account.ID) | ||
}) | ||
|
||
t.Run("get non existing account", func(t *testing.T) { | ||
accountStore := mock.NewAccountStore() | ||
account, err := services.AccountGetter(accountStore, 9999) | ||
|
||
accountID := 9999 | ||
|
||
account, err := services.AccountGetter(accountStore, services.AccountGetterParams{ | ||
AccountID: &accountID, | ||
}) | ||
|
||
require.NotNil(t, err) | ||
require.Nil(t, account) | ||
|
@@ -24,7 +44,11 @@ func TestAccountGetter(t *testing.T) { | |
acc, err := accountStore.Create("[email protected]", []byte("password")) | ||
require.NoError(t, err) | ||
|
||
account, err := services.AccountGetter(accountStore, acc.ID) | ||
accountID := acc.ID | ||
|
||
account, err := services.AccountGetter(accountStore, services.AccountGetterParams{ | ||
AccountID: &accountID, | ||
}) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, 0, len(account.OauthAccounts)) | ||
|
@@ -41,7 +65,11 @@ func TestAccountGetter(t *testing.T) { | |
err = accountStore.AddOauthAccount(acc.ID, "trial", "ID2", "email2", "TOKEN2") | ||
require.NoError(t, err) | ||
|
||
account, err := services.AccountGetter(accountStore, acc.ID) | ||
accountID := acc.ID | ||
|
||
account, err := services.AccountGetter(accountStore, services.AccountGetterParams{ | ||
AccountID: &accountID, | ||
}) | ||
require.NoError(t, err) | ||
|
||
oAccounts := account.OauthAccounts | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,26 @@ func TestGetAccount(t *testing.T) { | |
|
||
assertGetAccountResponse(t, res, account, oauthAccounts) | ||
}) | ||
|
||
t.Run("valid account username", func(t *testing.T) { | ||
account, err := app.AccountStore.Create("[email protected]", []byte("bar")) | ||
require.NoError(t, err) | ||
|
||
err = app.AccountStore.AddOauthAccount(account.ID, "test2", "ID21", "email21", "TOKEN21") | ||
require.NoError(t, err) | ||
|
||
err = app.AccountStore.AddOauthAccount(account.ID, "trial2", "ID22", "email22", "TOKEN22") | ||
require.NoError(t, err) | ||
|
||
oauthAccounts, err := app.AccountStore.GetOauthAccounts(account.ID) | ||
require.NoError(t, err) | ||
|
||
res, err := client.Get(fmt.Sprintf("/accounts/%v", account.Username)) | ||
require.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, res.StatusCode) | ||
|
||
assertGetAccountResponse(t, res, account, oauthAccounts) | ||
}) | ||
} | ||
|
||
func assertGetAccountResponse(t *testing.T, res *http.Response, acc *models.Account, oAccs []*models.OauthAccount) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ func PrivateRoutes(app *app.App) []*route.HandledRoute { | |
SecuredWith(authentication). | ||
Handle(handlers.PostAccountsImport(app)), | ||
|
||
route.Get("/accounts/{id:[0-9]+}"). | ||
route.Get("/accounts/{id}"). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cainlevy, one of the tests (for available account) fails because this overrides the public route "/accounts/available". Any suggestions to work around this? Can't use the older [0-9] since it rejects accept emails. I think we ideally want to put the overriden route above this route definition, but being in separate files, it might be difficult. |
||
SecuredWith(authentication). | ||
Handle(handlers.GetAccount(app)), | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't seen structs used for params, so let me know if this should be changed