Skip to content

Commit

Permalink
fix: add decline user invite functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal van Leeuwen committed Sep 22, 2023
1 parent 584abaf commit 7d33f32
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 48 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type (
WriteAccountUser(ctx context.Context, createUser types.CreateAccountUserAccess, time time.Time) (map[string]types.UserID, error)
// SetAccountUserRole updates the role for a single Account User - PUT `/v2/account/user/update_role`
SetAccountUserRole(ctx context.Context, updateUser types.UpdateAccountUserRole, time time.Time) (map[string]string, error)
// UpdateAcceptAccountUser accepts an Account User Access - PUT `/v2/account/user/accept`
// UpdateAcceptAccountUser accepts or declines an Account User Access - PUT `/v2/account/user/accept`
UpdateAcceptAccountUser(ctx context.Context, acceptUser types.UpdateAcceptAccountUser, time time.Time) (map[string]string, error)
// RemoveAccountUser removes an Account User's Role - PUT `/v2/account/user/remove`
RemoveAccountUser(ctx context.Context, removeUser types.UpdateRemoveAccountUser) (map[string]string, error)
Expand Down Expand Up @@ -867,7 +867,7 @@ func (db *DBClient) SetAccountUserRole(ctx context.Context, updateUser types.Upd
return putReq[map[string]string](endpoint, db.getAuthHeaderForWrite(), updateUserJSON, db.httpClient)
}

// UpdateAcceptAccountUser accepts an Account User Access - PUT `/v2/account/user/accept`
// UpdateAcceptAccountUser accepts or declines an Account User Access - PUT `/v2/account/user/accept`
func (db *DBClient) UpdateAcceptAccountUser(ctx context.Context, acceptUser types.UpdateAcceptAccountUser, time time.Time) (map[string]string, error) {
if acceptUser.PortalAppID == "" {
return nil, errNoPortalAppID
Expand Down
78 changes: 38 additions & 40 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,12 @@ func (ts *phdE2EReadTestSuite) Test_ReadTests() {
portalAppUsers: testdata.PortalAppUsers,
},
{
name: "Should get accounts for user_2 where user_2 is OWNER",
name: "Should get accounts for user_2 where user_2 is ADMIN or MEMBER",
userID: "user_2",
options: AccountOptions{
RoleNameFilters: []types.RoleName{
types.RoleOwner,
types.RoleAdmin,
types.RoleMember,
},
},
expectedAccs: map[types.AccountID]*types.Account{
Expand All @@ -664,24 +665,26 @@ func (ts *phdE2EReadTestSuite) Test_ReadTests() {
"account_1": testdata.PayPlans["basic_plan"],
"account_2": testdata.PayPlans["pro_plan"],
},
portalApps: map[types.AccountID]map[types.PortalAppID]*types.PortalApp{},
portalApps: map[types.AccountID]map[types.PortalAppID]*types.PortalApp{
"account_1": {"test_app_1": testdata.PortalApps["test_app_1"]},
"account_2": {"test_app_2": testdata.PortalApps["test_app_2"]},
},
portalAppUsers: testdata.PortalAppUsers,
},
{
name: "Should get accounts for user_2 where user_2 is ADMIN",
name: "Should get accounts for user_2 where user_2 is ADMIN and has accepted invite",
userID: "user_2",
options: AccountOptions{
RoleNameFilters: []types.RoleName{
types.RoleAdmin,
},
Accepted: BoolPtr(true),
},
expectedAccs: map[types.AccountID]*types.Account{
"account_1": testdata.Accounts["account_1"],
"account_2": testdata.Accounts["account_2"],
},
plans: map[types.AccountID]*types.Plan{
"account_1": testdata.PayPlans["basic_plan"],
"account_2": testdata.PayPlans["pro_plan"],
},
portalApps: map[types.AccountID]map[types.PortalAppID]*types.PortalApp{
"account_1": {"test_app_1": testdata.PortalApps["test_app_1"]},
Expand Down Expand Up @@ -721,23 +724,6 @@ func (ts *phdE2EReadTestSuite) Test_ReadTests() {
},
portalAppUsers: testdata.PortalAppUsers,
},
{
name: "Should get accounts for user_10 where user_10 has not signed up yet",
userID: "user_10",
options: AccountOptions{
Accepted: BoolPtr(false),
},
expectedAccs: map[types.AccountID]*types.Account{
"account_3": testdata.Accounts["account_3"],
},
plans: map[types.AccountID]*types.Plan{
"account_3": testdata.PayPlans["startup_plan"],
},
portalApps: map[types.AccountID]map[types.PortalAppID]*types.PortalApp{
"account_3": {"test_app_3": testdata.PortalApps["test_app_3"]},
},
portalAppUsers: testdata.PortalAppUsers,
},
{
name: "Should get accounts for user_2 where user_2 has signed up",
userID: "user_2",
Expand All @@ -758,23 +744,6 @@ func (ts *phdE2EReadTestSuite) Test_ReadTests() {
},
portalAppUsers: testdata.PortalAppUsers,
},
{
name: "Should get accounts for user_2 where user_2 has not signed up yet",
userID: "user_2",
options: AccountOptions{
Accepted: BoolPtr(false),
},
expectedAccs: map[types.AccountID]*types.Account{
"account_1": testdata.Accounts["account_1"],
"account_2": testdata.Accounts["account_2"],
},
plans: map[types.AccountID]*types.Plan{
"account_1": testdata.PayPlans["basic_plan"],
"account_2": testdata.PayPlans["pro_plan"],
},
portalApps: nil,
portalAppUsers: testdata.PortalAppUsers,
},
{
name: "Should get accounts for user_4",
userID: "user_4",
Expand All @@ -790,9 +759,37 @@ func (ts *phdE2EReadTestSuite) Test_ReadTests() {
},
portalApps: map[types.AccountID]map[types.PortalAppID]*types.PortalApp{
"account_2": {"test_app_2": testdata.PortalApps["test_app_2"]},
"account_4": {},
"account_5": {},
},
portalAppUsers: testdata.PortalAppUsers,
},
{
name: "Should fail to get accounts for user_2 where user_2 is OWNER (user_2 owns no accounts)",
userID: "user_2",
options: AccountOptions{
RoleNameFilters: []types.RoleName{
types.RoleOwner,
},
},
expectedAccs: map[types.AccountID]*types.Account{},
plans: map[types.AccountID]*types.Plan{},
portalApps: map[types.AccountID]map[types.PortalAppID]*types.PortalApp{},
portalAppUsers: testdata.PortalAppUsers,
err: fmt.Errorf("Response not OK. 404 Not Found: error in getUserAccounts: no accounts were found for user ID"),
},
{
name: "Should fail to get accounts for user_2 where user_2 has not signed up yet (should not return invited accounts)",
userID: "user_2",
options: AccountOptions{
Accepted: BoolPtr(false),
},
expectedAccs: map[types.AccountID]*types.Account{},
plans: map[types.AccountID]*types.Plan{},
portalApps: nil,
portalAppUsers: testdata.PortalAppUsers,
err: fmt.Errorf("Response not OK. 404 Not Found: error in getUserAccounts: no accounts were found for user ID"),
},
}

for _, test := range tests {
Expand Down Expand Up @@ -2166,6 +2163,7 @@ func (ts *phdE2EWriteTestSuite) Test_WriteTests() {
LegacyDailyLimit: 100,
CreatedAt: testdata.MockTimestamp,
},
PortalApps: map[types.PortalAppID]*types.PortalApp{},
},
expectedPlan: &types.Plan{
Type: types.PayPlanType("developer_plan"),
Expand Down
2 changes: 1 addition & 1 deletion client/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/mock_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/mock_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/pokt-foundation/db-client/v2
go 1.21

require (
github.com/pokt-foundation/portal-db/v2 v2.12.12
github.com/pokt-foundation/portal-db/v2 v2.13.1
github.com/stretchr/testify v1.8.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pokt-foundation/portal-db v1.11.0 h1:rI2JDc9RrB1Rz6nhOls23gaClQJeQdunUOksUVvI6pU=
github.com/pokt-foundation/portal-db v1.11.0/go.mod h1:Pf8IIeoj3mSIk0+eNdzssz3T7GvnWRkFKPwGsFT2D5w=
github.com/pokt-foundation/portal-db/v2 v2.12.12 h1:iYFsLG5Cp+VJ5+jUJC3pl4zD0dn7Y+VYACDi9G3j+NM=
github.com/pokt-foundation/portal-db/v2 v2.12.12/go.mod h1:b0pEpQPKXMelw+ZHz3nxbiBGvzGwV9zFOIdzZJEdkLM=
github.com/pokt-foundation/portal-db/v2 v2.13.1 h1:5HDd2+ctB8yHFSouMNiYzPci8QM+F/4J3CyqUSQqASk=
github.com/pokt-foundation/portal-db/v2 v2.13.1/go.mod h1:b0pEpQPKXMelw+ZHz3nxbiBGvzGwV9zFOIdzZJEdkLM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
Expand Down

0 comments on commit 7d33f32

Please sign in to comment.