From 4f64d85da26a85d860c1da0829544c4b9c50da18 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Sat, 6 Apr 2024 08:29:03 -0500 Subject: [PATCH] Feat: Refactor for Project Role assignments for Team --- client/api_client.go | 4 +- client/api_client_mock.go | 12 +-- client/team_project_assignment.go | 39 ++++----- client/team_project_assignment_test.go | 43 ++++------ env0/resource_team_project_assignment.go | 23 ++--- env0/resource_team_project_assignment_test.go | 86 +++++++++---------- 6 files changed, 97 insertions(+), 110 deletions(-) diff --git a/client/api_client.go b/client/api_client.go index 45695e7a..d8aa83d3 100644 --- a/client/api_client.go +++ b/client/api_client.go @@ -61,8 +61,8 @@ type ApiClientInterface interface { TeamCreate(payload TeamCreatePayload) (Team, error) TeamUpdate(id string, payload TeamUpdatePayload) (Team, error) TeamDelete(id string) error - TeamProjectAssignmentCreateOrUpdate(payload TeamProjectAssignmentPayload) (TeamProjectAssignment, error) - TeamProjectAssignmentDelete(assignmentId string) error + TeamProjectAssignmentCreateOrUpdate(payload *TeamProjectAssignmentPayload) (*TeamProjectAssignment, error) + TeamProjectAssignmentDelete(projectId string, teamId string) error TeamProjectAssignments(projectId string) ([]TeamProjectAssignment, error) Environments() ([]Environment, error) ProjectEnvironments(projectId string) ([]Environment, error) diff --git a/client/api_client_mock.go b/client/api_client_mock.go index 9f6e8ad2..8a8ec0cf 100644 --- a/client/api_client_mock.go +++ b/client/api_client_mock.go @@ -1851,10 +1851,10 @@ func (mr *MockApiClientInterfaceMockRecorder) TeamDelete(arg0 any) *gomock.Call } // TeamProjectAssignmentCreateOrUpdate mocks base method. -func (m *MockApiClientInterface) TeamProjectAssignmentCreateOrUpdate(arg0 TeamProjectAssignmentPayload) (TeamProjectAssignment, error) { +func (m *MockApiClientInterface) TeamProjectAssignmentCreateOrUpdate(arg0 *TeamProjectAssignmentPayload) (*TeamProjectAssignment, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "TeamProjectAssignmentCreateOrUpdate", arg0) - ret0, _ := ret[0].(TeamProjectAssignment) + ret0, _ := ret[0].(*TeamProjectAssignment) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -1866,17 +1866,17 @@ func (mr *MockApiClientInterfaceMockRecorder) TeamProjectAssignmentCreateOrUpdat } // TeamProjectAssignmentDelete mocks base method. -func (m *MockApiClientInterface) TeamProjectAssignmentDelete(arg0 string) error { +func (m *MockApiClientInterface) TeamProjectAssignmentDelete(arg0, arg1 string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TeamProjectAssignmentDelete", arg0) + ret := m.ctrl.Call(m, "TeamProjectAssignmentDelete", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // TeamProjectAssignmentDelete indicates an expected call of TeamProjectAssignmentDelete. -func (mr *MockApiClientInterfaceMockRecorder) TeamProjectAssignmentDelete(arg0 any) *gomock.Call { +func (mr *MockApiClientInterfaceMockRecorder) TeamProjectAssignmentDelete(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TeamProjectAssignmentDelete", reflect.TypeOf((*MockApiClientInterface)(nil).TeamProjectAssignmentDelete), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TeamProjectAssignmentDelete", reflect.TypeOf((*MockApiClientInterface)(nil).TeamProjectAssignmentDelete), arg0, arg1) } // TeamProjectAssignments mocks base method. diff --git a/client/team_project_assignment.go b/client/team_project_assignment.go index 0ee80fcc..b42ba56b 100644 --- a/client/team_project_assignment.go +++ b/client/team_project_assignment.go @@ -1,9 +1,5 @@ package client -import ( - "errors" -) - type ProjectRole string const ( @@ -18,40 +14,35 @@ func IsBuiltinProjectRole(role string) bool { } type TeamProjectAssignmentPayload struct { - TeamId string `json:"teamId"` - ProjectId string `json:"projectId"` - ProjectRole string `json:"projectRole" tfschema:"-"` + TeamId string `json:"teamId"` + ProjectId string `json:"projectId"` + Role string `json:"role" tfschema:"-"` } type TeamProjectAssignment struct { - Id string `json:"id"` - TeamId string `json:"teamId"` - ProjectId string `json:"projectId"` - ProjectRole string `json:"projectRole" tfschema:"-"` + Id string `json:"id"` + TeamId string `json:"teamId"` + ProjectId string `json:"projectId"` + Role string `json:"role" tfschema:"-"` } -func (client *ApiClient) TeamProjectAssignmentCreateOrUpdate(payload TeamProjectAssignmentPayload) (TeamProjectAssignment, error) { +func (client *ApiClient) TeamProjectAssignmentCreateOrUpdate(payload *TeamProjectAssignmentPayload) (*TeamProjectAssignment, error) { var result TeamProjectAssignment - var err = client.http.Post("/teams/assignments", payload, &result) - - if err != nil { - return TeamProjectAssignment{}, err + if err := client.http.Post("/roles/assignments/teams", payload, &result); err != nil { + return nil, err } - return result, nil + + return &result, nil } -func (client *ApiClient) TeamProjectAssignmentDelete(assignmentId string) error { - if assignmentId == "" { - return errors.New("empty assignmentId") - } - return client.http.Delete("/teams/assignments/"+assignmentId, nil) +func (client *ApiClient) TeamProjectAssignmentDelete(projectId string, teamId string) error { + return client.http.Delete("/roles/assignments/teams", map[string]string{"projectId": projectId, "teamId": teamId}) } func (client *ApiClient) TeamProjectAssignments(projectId string) ([]TeamProjectAssignment, error) { - var result []TeamProjectAssignment - err := client.http.Get("/teams/assignments", map[string]string{"projectId": projectId}, &result) + err := client.http.Get("/roles/assignments/teams", map[string]string{"projectId": projectId}, &result) if err != nil { return []TeamProjectAssignment{}, err diff --git a/client/team_project_assignment_test.go b/client/team_project_assignment_test.go index e6a0327e..a3cad4d4 100644 --- a/client/team_project_assignment_test.go +++ b/client/team_project_assignment_test.go @@ -14,36 +14,34 @@ var _ = Describe("TeamProjectAssignment", func() { const dummyTeamId = "dummyTeamId" mockTeamProjectAssignment := TeamProjectAssignment{ - Id: dummyProjectAssignmentId, - ProjectId: dummyProjectId, - ProjectRole: dummyProjectRole, - TeamId: dummyTeamId, + Id: dummyProjectAssignmentId, + ProjectId: dummyProjectId, + Role: dummyProjectRole, + TeamId: dummyTeamId, } Describe("CreateOrUpdate", func() { Describe("Success", func() { - var teamProjectAssignment TeamProjectAssignment + var teamProjectAssignment *TeamProjectAssignment BeforeEach(func() { expectedPayload := TeamProjectAssignmentPayload{ - TeamId: dummyTeamId, - ProjectId: dummyProjectId, - ProjectRole: dummyProjectRole, + TeamId: dummyTeamId, + ProjectId: dummyProjectId, + Role: dummyProjectRole, } httpCall = mockHttpClient.EXPECT(). - Post("/teams/assignments", expectedPayload, gomock.Any()). + Post("/roles/assignments/teams", &expectedPayload, gomock.Any()). Do(func(path string, request interface{}, response *TeamProjectAssignment) { *response = mockTeamProjectAssignment }).Times(1) - teamProjectAssignment, _ = apiClient.TeamProjectAssignmentCreateOrUpdate(expectedPayload) + teamProjectAssignment, _ = apiClient.TeamProjectAssignmentCreateOrUpdate(&expectedPayload) }) - It("Should send POST request with params", func() { - httpCall.Times(1) - }) + It("Should send POST request with params", func() {}) It("Should return a new resource with id", func() { - Expect(teamProjectAssignment).To(Equal(mockTeamProjectAssignment)) + Expect(*teamProjectAssignment).To(Equal(mockTeamProjectAssignment)) }) }) }) @@ -53,16 +51,14 @@ var _ = Describe("TeamProjectAssignment", func() { var teamProjectAssignments []TeamProjectAssignment BeforeEach(func() { httpCall = mockHttpClient.EXPECT(). - Get("/teams/assignments", map[string]string{"projectId": mockTeamProjectAssignment.ProjectId}, gomock.Any()). + Get("/roles/assignments/teams", map[string]string{"projectId": mockTeamProjectAssignment.ProjectId}, gomock.Any()). Do(func(path string, request interface{}, response *[]TeamProjectAssignment) { *response = mockTeamProjectAssignments - }) + }).Times(1) teamProjectAssignments, _ = apiClient.TeamProjectAssignments(mockTeamProjectAssignment.ProjectId) }) - It("Should send GET request", func() { - httpCall.Times(1) - }) + It("Should send GET request", func() {}) It("Should return the projects assignments", func() { Expect(teamProjectAssignments).To(Equal(mockTeamProjectAssignments)) @@ -71,15 +67,12 @@ var _ = Describe("TeamProjectAssignment", func() { }) Describe("Delete", func() { - BeforeEach(func() { - httpCall = mockHttpClient.EXPECT().Delete("/teams/assignments/"+mockTeamProjectAssignment.Id, nil) - apiClient.TeamProjectAssignmentDelete(mockTeamProjectAssignment.Id) + httpCall = mockHttpClient.EXPECT().Delete("/roles/assignments/teams", map[string]string{"projectId": mockTeamProjectAssignment.ProjectId, "teamId": mockTeamProjectAssignment.TeamId}).Times(1) + apiClient.TeamProjectAssignmentDelete(mockTeamProjectAssignment.ProjectId, mockTeamProjectAssignment.TeamId) }) - It("Should send DELETE request with assignment id", func() { - httpCall.Times(1) - }) + It("Should send DELETE request with assignment id", func() {}) }) }) diff --git a/env0/resource_team_project_assignment.go b/env0/resource_team_project_assignment.go index 28069856..8bbb2b3e 100644 --- a/env0/resource_team_project_assignment.go +++ b/env0/resource_team_project_assignment.go @@ -68,10 +68,10 @@ func resourceTeamProjectAssignmentRead(ctx context.Context, d *schema.ResourceDa return diag.Errorf("schema resource data serialization failed: %v", err) } - if client.IsBuiltinProjectRole(assignment.ProjectRole) { - d.Set("role", assignment.ProjectRole) + if client.IsBuiltinProjectRole(assignment.Role) { + d.Set("role", assignment.Role) } else { - d.Set("custom_role_id", assignment.ProjectRole) + d.Set("custom_role_id", assignment.Role) } return nil @@ -96,14 +96,14 @@ func resourceTeamProjectAssignmentCreateOrUpdate(ctx context.Context, d *schema. if !ok { role = d.Get("custom_role_id") } - payload.ProjectRole = role.(string) + payload.Role = role.(string) - response, err := apiClient.TeamProjectAssignmentCreateOrUpdate(payload) + assignment, err := apiClient.TeamProjectAssignmentCreateOrUpdate(&payload) if err != nil { return diag.Errorf("could not Create or Update TeamProjectAssignment: %v", err) } - d.SetId(response.Id) + d.SetId(assignment.Id) return nil } @@ -111,7 +111,10 @@ func resourceTeamProjectAssignmentCreateOrUpdate(ctx context.Context, d *schema. func resourceTeamProjectAssignmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { apiClient := meta.(client.ApiClientInterface) - err := apiClient.TeamProjectAssignmentDelete(d.Id()) + projectId := d.Get("project_id").(string) + teamId := d.Get("team_id").(string) + + err := apiClient.TeamProjectAssignmentDelete(projectId, teamId) if err != nil { return diag.Errorf("could not delete TeamProjectAssignment: %v", err) } @@ -141,10 +144,10 @@ func resourceTeamProjectAssignmentImport(ctx context.Context, d *schema.Resource return nil, fmt.Errorf("schema resource data serialization failed: %w", err) } - if client.IsBuiltinProjectRole(assignment.ProjectRole) { - d.Set("role", assignment.ProjectRole) + if client.IsBuiltinProjectRole(assignment.Role) { + d.Set("role", assignment.Role) } else { - d.Set("custom_role_id", assignment.ProjectRole) + d.Set("custom_role_id", assignment.Role) } return []*schema.ResourceData{d}, nil } diff --git a/env0/resource_team_project_assignment_test.go b/env0/resource_team_project_assignment_test.go index 1c7a40f4..9b3306ba 100644 --- a/env0/resource_team_project_assignment_test.go +++ b/env0/resource_team_project_assignment_test.go @@ -20,31 +20,31 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { updatedCustomRole := "id2" assignment := client.TeamProjectAssignment{ - Id: "assignmentId", - TeamId: "teamId0", - ProjectId: "projectId0", - ProjectRole: string(client.Admin), + Id: "assignmentId", + TeamId: "teamId0", + ProjectId: "projectId0", + Role: string(client.Admin), } updateAssignment := client.TeamProjectAssignment{ - Id: "assignmentIdupdate", - TeamId: "teamIdUupdate", - ProjectId: "projectId0", - ProjectRole: string(client.Admin), + Id: "assignmentIdupdate", + TeamId: "teamIdUupdate", + ProjectId: "projectId0", + Role: string(client.Admin), } assignmentCustom := client.TeamProjectAssignment{ - Id: "assignmentId", - TeamId: "teamId0", - ProjectId: "projectId0", - ProjectRole: customRole, + Id: "assignmentId", + TeamId: "teamId0", + ProjectId: "projectId0", + Role: customRole, } updateAssignmentCustom := client.TeamProjectAssignment{ - Id: "assignmentIdupdate", - TeamId: "teamIdUupdate", - ProjectId: "projectId0", - ProjectRole: updatedCustomRole, + Id: "assignmentIdupdate", + TeamId: "teamIdUupdate", + ProjectId: "projectId0", + Role: updatedCustomRole, } t.Run("create", func(t *testing.T) { @@ -54,21 +54,21 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ "team_id": assignment.TeamId, "project_id": assignment.ProjectId, - "role": assignment.ProjectRole, + "role": assignment.Role, }), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(accessor, "team_id", assignment.TeamId), resource.TestCheckResourceAttr(accessor, "project_id", assignment.ProjectId), - resource.TestCheckResourceAttr(accessor, "role", assignment.ProjectRole), + resource.TestCheckResourceAttr(accessor, "role", assignment.Role), ), }, }, } runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) { - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, ProjectRole: assignment.ProjectRole}).Times(1).Return(assignment, nil) + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, Role: assignment.Role}).Times(1).Return(&assignment, nil) mock.EXPECT().TeamProjectAssignments(assignment.ProjectId).Times(1).Return([]client.TeamProjectAssignment{assignment}, nil) - mock.EXPECT().TeamProjectAssignmentDelete(assignment.Id).Times(1).Return(nil) + mock.EXPECT().TeamProjectAssignmentDelete(assignment.ProjectId, assignment.TeamId).Times(1).Return(nil) }) }) @@ -79,38 +79,38 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ "team_id": assignment.TeamId, "project_id": assignment.ProjectId, - "role": assignment.ProjectRole, + "role": assignment.Role, }), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(accessor, "team_id", assignment.TeamId), resource.TestCheckResourceAttr(accessor, "project_id", assignment.ProjectId), - resource.TestCheckResourceAttr(accessor, "role", assignment.ProjectRole), + resource.TestCheckResourceAttr(accessor, "role", assignment.Role), ), }, { Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ "team_id": updateAssignment.TeamId, "project_id": assignment.ProjectId, - "role": assignment.ProjectRole, + "role": assignment.Role, }), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(accessor, "team_id", updateAssignment.TeamId), resource.TestCheckResourceAttr(accessor, "project_id", assignment.ProjectId), - resource.TestCheckResourceAttr(accessor, "role", string(assignment.ProjectRole)), + resource.TestCheckResourceAttr(accessor, "role", string(assignment.Role)), ), }, }, } runUnitTest(t, driftTestCase, func(mock *client.MockApiClientInterface) { - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, ProjectRole: assignment.ProjectRole}).Times(1).Return(assignment, nil) - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: updateAssignment.TeamId, ProjectId: assignment.ProjectId, ProjectRole: assignment.ProjectRole}).Times(1).Return(updateAssignment, nil) + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, Role: assignment.Role}).Times(1).Return(&assignment, nil) + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: updateAssignment.TeamId, ProjectId: assignment.ProjectId, Role: assignment.Role}).Times(1).Return(&updateAssignment, nil) gomock.InOrder( mock.EXPECT().TeamProjectAssignments(assignment.ProjectId).Times(1).Return([]client.TeamProjectAssignment{assignment}, nil), mock.EXPECT().TeamProjectAssignments(assignment.ProjectId).Times(1).Return([]client.TeamProjectAssignment{updateAssignment}, nil), mock.EXPECT().TeamProjectAssignments(assignment.ProjectId).Times(1).Return([]client.TeamProjectAssignment{updateAssignment}, nil), ) - mock.EXPECT().TeamProjectAssignmentDelete(updateAssignment.Id).Times(1).Return(nil) + mock.EXPECT().TeamProjectAssignmentDelete(updateAssignment.ProjectId, updateAssignment.TeamId).Times(1).Return(nil) }) }) @@ -145,12 +145,12 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ "team_id": updateAssignmentCustom.TeamId, "project_id": updateAssignmentCustom.ProjectId, - "role": updateAssignment.ProjectRole, + "role": updateAssignment.Role, }), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(accessor, "team_id", updateAssignmentCustom.TeamId), resource.TestCheckResourceAttr(accessor, "project_id", updateAssignmentCustom.ProjectId), - resource.TestCheckResourceAttr(accessor, "role", updateAssignment.ProjectRole), + resource.TestCheckResourceAttr(accessor, "role", updateAssignment.Role), ), }, }, @@ -158,14 +158,14 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) { gomock.InOrder( - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: assignmentCustom.TeamId, ProjectId: assignmentCustom.ProjectId, ProjectRole: assignmentCustom.ProjectRole}).Times(1).Return(assignmentCustom, nil), + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: assignmentCustom.TeamId, ProjectId: assignmentCustom.ProjectId, Role: assignmentCustom.Role}).Times(1).Return(&assignmentCustom, nil), mock.EXPECT().TeamProjectAssignments(assignmentCustom.ProjectId).Times(2).Return([]client.TeamProjectAssignment{assignmentCustom}, nil), - mock.EXPECT().TeamProjectAssignmentDelete(assignmentCustom.Id).Times(1).Return(nil), - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: updateAssignmentCustom.TeamId, ProjectId: updateAssignmentCustom.ProjectId, ProjectRole: updateAssignmentCustom.ProjectRole}).Times(1).Return(updateAssignmentCustom, nil), + mock.EXPECT().TeamProjectAssignmentDelete(assignmentCustom.ProjectId, assignmentCustom.TeamId).Times(1).Return(nil), + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: updateAssignmentCustom.TeamId, ProjectId: updateAssignmentCustom.ProjectId, Role: updateAssignmentCustom.Role}).Times(1).Return(&updateAssignmentCustom, nil), mock.EXPECT().TeamProjectAssignments(assignmentCustom.ProjectId).Times(2).Return([]client.TeamProjectAssignment{updateAssignmentCustom}, nil), - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: updateAssignmentCustom.TeamId, ProjectId: updateAssignmentCustom.ProjectId, ProjectRole: updateAssignment.ProjectRole}).Times(1).Return(updateAssignment, nil), + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: updateAssignmentCustom.TeamId, ProjectId: updateAssignmentCustom.ProjectId, Role: updateAssignment.Role}).Times(1).Return(&updateAssignment, nil), mock.EXPECT().TeamProjectAssignments(assignmentCustom.ProjectId).Times(1).Return([]client.TeamProjectAssignment{updateAssignment}, nil), - mock.EXPECT().TeamProjectAssignmentDelete(updateAssignment.Id).Times(1).Return(nil), + mock.EXPECT().TeamProjectAssignmentDelete(updateAssignment.ProjectId, updateAssignment.TeamId).Times(1).Return(nil), ) }) }) @@ -177,7 +177,7 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ "team_id": assignment.TeamId, "project_id": assignment.ProjectId, - "role": assignment.ProjectRole, + "role": assignment.Role, }), }, { @@ -190,9 +190,9 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { } runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) { - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, ProjectRole: assignment.ProjectRole}).Times(1).Return(assignment, nil) + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, Role: assignment.Role}).Times(1).Return(&assignment, nil) mock.EXPECT().TeamProjectAssignments(assignment.ProjectId).Times(3).Return([]client.TeamProjectAssignment{assignment}, nil) - mock.EXPECT().TeamProjectAssignmentDelete(assignment.Id).Times(1).Return(nil) + mock.EXPECT().TeamProjectAssignmentDelete(assignment.ProjectId, assignment.TeamId).Times(1).Return(nil) }) }) @@ -203,7 +203,7 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ "team_id": assignmentCustom.TeamId, "project_id": assignmentCustom.ProjectId, - "custom_role_id": assignmentCustom.ProjectRole, + "custom_role_id": assignmentCustom.Role, }), }, { @@ -216,9 +216,9 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { } runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) { - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: assignmentCustom.TeamId, ProjectId: assignmentCustom.ProjectId, ProjectRole: assignmentCustom.ProjectRole}).Times(1).Return(assignmentCustom, nil) + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: assignmentCustom.TeamId, ProjectId: assignmentCustom.ProjectId, Role: assignmentCustom.Role}).Times(1).Return(&assignmentCustom, nil) mock.EXPECT().TeamProjectAssignments(assignmentCustom.ProjectId).Times(3).Return([]client.TeamProjectAssignment{assignmentCustom}, nil) - mock.EXPECT().TeamProjectAssignmentDelete(assignmentCustom.Id).Times(1).Return(nil) + mock.EXPECT().TeamProjectAssignmentDelete(assignmentCustom.ProjectId, assignmentCustom.TeamId).Times(1).Return(nil) }) }) @@ -229,7 +229,7 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ "team_id": assignment.TeamId, "project_id": assignment.ProjectId, - "role": assignment.ProjectRole, + "role": assignment.Role, }), }, { @@ -243,10 +243,10 @@ func TestUnitTeamProjectAssignmentResource(t *testing.T) { } runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) { - mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, ProjectRole: assignment.ProjectRole}).Times(1).Return(assignment, nil) + mock.EXPECT().TeamProjectAssignmentCreateOrUpdate(&client.TeamProjectAssignmentPayload{TeamId: assignment.TeamId, ProjectId: assignment.ProjectId, Role: assignment.Role}).Times(1).Return(&assignment, nil) mock.EXPECT().TeamProjectAssignments(assignment.ProjectId).Times(1).Return([]client.TeamProjectAssignment{assignment}, nil) mock.EXPECT().TeamProjectAssignments(assignment.ProjectId).Times(1).Return([]client.TeamProjectAssignment{}, nil) - mock.EXPECT().TeamProjectAssignmentDelete(assignment.Id).Times(1) + mock.EXPECT().TeamProjectAssignmentDelete(assignment.ProjectId, assignment.TeamId).Times(1) }) }) }