diff --git a/client/client.go b/client/client.go index 05c8e53..077c60c 100644 --- a/client/client.go +++ b/client/client.go @@ -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) @@ -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 diff --git a/client/client_test.go b/client/client_test.go index 59decaa..3bab9c6 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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{ @@ -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"]}, @@ -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", @@ -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", @@ -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 { @@ -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"), diff --git a/client/mock_client.go b/client/mock_client.go index a7616d8..2a18b2f 100644 --- a/client/mock_client.go +++ b/client/mock_client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.3. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dbclient diff --git a/client/mock_reader.go b/client/mock_reader.go index 4cac7be..295c15d 100644 --- a/client/mock_reader.go +++ b/client/mock_reader.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.3. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dbclient diff --git a/client/mock_writer.go b/client/mock_writer.go index abc1f13..2450c0f 100644 --- a/client/mock_writer.go +++ b/client/mock_writer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.3. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dbclient diff --git a/go.mod b/go.mod index a50870e..7c8d8d8 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 646b2ce..e2a5a3c 100644 --- a/go.sum +++ b/go.sum @@ -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=