Skip to content

Commit

Permalink
Fixed workitems tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dginty4 committed Jul 25, 2024
1 parent d5952d4 commit 99a5b8c
Show file tree
Hide file tree
Showing 16 changed files with 708 additions and 710 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"

worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
Expand Down Expand Up @@ -39,12 +40,16 @@ func TestAccDataSourceTaskManagementWorkitem(t *testing.T) {
wtResName = "tf_worktype_1"
wtName = "tf-worktype" + uuid.NewString()
wtDescription = "tf-worktype-description"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"

// Worktype statuses
statusResourceOpen = "open-status"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
statusResourceClosed = "closed-status"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"

// basic workitem
workitemRes = "workitem_1"
Expand All @@ -64,22 +69,25 @@ func TestAccDataSourceTaskManagementWorkitem(t *testing.T) {
wtDescription,
fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
// Needs both an open and closed status or workitems cannot be created for worktype.
fmt.Sprintf(`
statuses {
name = "%s"
description = "%s"
category = "%s"
}
statuses {
name = "%s"
description = "%s"
category = "%s"
}
default_status_name = "%s"
`, wtOStatusName, wtOStatusDesc, wtOStatusCategory,
wtCStatusName, wtCStatusDesc, wtCStatusCategory,
wtOStatusName),
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceOpen,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtOStatusName,
wtOStatusCategory,
wtOStatusDesc,
util.NullValue,
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceClosed,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtCStatusName,
wtCStatusCategory,
wtCStatusDesc,
util.NullValue,
"",
)
)
resource.Test(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
)

/*
Expand Down Expand Up @@ -41,6 +42,7 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_task_management_workitem_schema"] = workitemSchema.ResourceTaskManagementWorkitemSchema()
providerResources["genesyscloud_task_management_workbin"] = workbin.ResourceTaskManagementWorkbin()
providerResources["genesyscloud_task_management_worktype"] = worktype.ResourceTaskManagementWorktype()
providerResources["genesyscloud_task_management_worktype_status"] = worktypeStatus.ResourceTaskManagementWorktypeStatus()
providerResources["genesyscloud_routing_language"] = gcloud.ResourceRoutingLanguage()
providerResources["genesyscloud_user"] = gcloud.ResourceUser()
providerResources["genesyscloud_externalcontacts_contact"] = externalContacts.ResourceExternalContact()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@ func (p *taskManagementWorkitemProxy) deleteTaskManagementWorkitem(ctx context.C

// createTaskManagementWorkitemFn is an implementation function for creating a Genesys Cloud task management workitem
func createTaskManagementWorkitemFn(ctx context.Context, p *taskManagementWorkitemProxy, taskManagementWorkitem *platformclientv2.Workitemcreate) (*platformclientv2.Workitem, *platformclientv2.APIResponse, error) {
log.Printf("Creating task management worktype: %s", *taskManagementWorkitem.Name)
workitem, resp, err := p.taskManagementApi.PostTaskmanagementWorkitems(*taskManagementWorkitem)
log.Printf("Completed call to create task management worktype %s with status code %d, correlation id %s and err %s", *taskManagementWorkitem.Name, resp.StatusCode, resp.CorrelationID, err)
if err != nil {
return nil, resp, fmt.Errorf("failed to create task management workitem: %s", err)
}
return workitem, resp, nil
return p.taskManagementApi.PostTaskmanagementWorkitems(*taskManagementWorkitem)
}

// getAllTaskManagementWorkitemFn is the implementation for retrieving all task management workitem in Genesys Cloud
Expand Down Expand Up @@ -231,27 +225,15 @@ func getTaskManagementWorkitemIdByNameFn(ctx context.Context, p *taskManagementW

// getTaskManagementWorkitemByIdFn is an implementation of the function to get a Genesys Cloud task management workitem by Id
func getTaskManagementWorkitemByIdFn(ctx context.Context, p *taskManagementWorkitemProxy, id string) (taskManagementWorkitem *platformclientv2.Workitem, resp *platformclientv2.APIResponse, err error) {
workitem, resp, err := p.taskManagementApi.GetTaskmanagementWorkitem(id, "")
if err != nil {
return nil, resp, fmt.Errorf("failed to retrieve task management workitem by id %s: %s", id, err)
}
return workitem, resp, nil
return p.taskManagementApi.GetTaskmanagementWorkitem(id, "")
}

// updateTaskManagementWorkitemFn is an implementation of the function to update a Genesys Cloud task management workitem
func updateTaskManagementWorkitemFn(ctx context.Context, p *taskManagementWorkitemProxy, id string, taskManagementWorkitem *platformclientv2.Workitemupdate) (*platformclientv2.Workitem, *platformclientv2.APIResponse, error) {
workitem, resp, err := p.taskManagementApi.PatchTaskmanagementWorkitem(id, *taskManagementWorkitem)
if err != nil {
return nil, resp, fmt.Errorf("failed to update task management workitem: %s", err)
}
return workitem, resp, nil
return p.taskManagementApi.PatchTaskmanagementWorkitem(id, *taskManagementWorkitem)
}

// deleteTaskManagementWorkitemFn is an implementation function for deleting a Genesys Cloud task management workitem
func deleteTaskManagementWorkitemFn(ctx context.Context, p *taskManagementWorkitemProxy, id string) (resp *platformclientv2.APIResponse, err error) {
resp, err = p.taskManagementApi.DeleteTaskmanagementWorkitem(id)
if err != nil {
return resp, fmt.Errorf("failed to delete task management workitem: %s", err)
}
return resp, nil
return p.taskManagementApi.DeleteTaskmanagementWorkitem(id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func createTaskManagementWorkitem(ctx context.Context, d *schema.ResourceData, m

taskManagementWorkitem, err := getWorkitemCreateFromResourceData(d)
if err != nil {
return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to build Workitem create from resource data"), err)
return util.BuildDiagnosticError(resourceName, "failed to build Workitem create from resource data", err)
}

log.Printf("Creating task management workitem %s", *taskManagementWorkitem.Name)
Expand Down Expand Up @@ -138,7 +138,7 @@ func updateTaskManagementWorkitem(ctx context.Context, d *schema.ResourceData, m

taskManagementWorkitem, err := getWorkitemUpdateFromResourceData(d)
if err != nil {
return util.BuildDiagnosticError(resourceName, fmt.Sprintf("failed to update Workitem create from resource data"), err)
return util.BuildDiagnosticError(resourceName, "failed to update Workitem create from resource data", err)
}

log.Printf("Updating task management workitem %s", *taskManagementWorkitem.Name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package task_management_workitem

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"terraform-provider-genesyscloud/genesyscloud/provider"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
"terraform-provider-genesyscloud/genesyscloud/util"
"terraform-provider-genesyscloud/genesyscloud/validators"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

/*
Expand Down Expand Up @@ -198,6 +199,7 @@ func TaskManagementWorkitemExporter() *resourceExporter.ResourceExporter {
"external_contact_id": {RefType: "genesyscloud_externalcontacts_contact"},
"queue_id": {RefType: "genesyscloud_routing_queue"},
"skills_ids": {RefType: "genesyscloud_routing_skill"},
"status_id": {RefType: "genesyscloud_task_management_worktype_status"},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
workbin "terraform-provider-genesyscloud/genesyscloud/task_management_workbin"
workitemSchema "terraform-provider-genesyscloud/genesyscloud/task_management_workitem_schema"
worktype "terraform-provider-genesyscloud/genesyscloud/task_management_worktype"
worktypeStatus "terraform-provider-genesyscloud/genesyscloud/task_management_worktype_status"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"

"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down Expand Up @@ -80,15 +81,19 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
wsDescription = "workitem schema created for CX as Code test case"

// worktype
wtResName = "tf_worktype_1"
wtName = "tf-worktype" + uuid.NewString()
wtDescription = "tf-worktype-description"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"
wtResName = "tf_worktype_1"
wtName = "tf-worktype" + uuid.NewString()
wtDescription = "tf-worktype-description"

// Worktype statuses
statusResourceOpen = "open-status"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
statusResourceClosed = "closed-status"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"

// language
resLang = "language_1"
Expand Down Expand Up @@ -147,7 +152,7 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
}},
}

// String configuration of task management objects needed for the workitem: schema, workbin, workitem.
// String configuration of task management objects needed for the workitem: schema, workbin, worktype, worktype_status.
// They don't really change so they are defined here instead of in each step.
taskMgmtConfig = workbin.GenerateWorkbinResource(wbResourceId, wbName, wbDescription, util.NullValue) +
workbin.GenerateWorkbinResource(wb2ResourceId, wb2Name, wb2Description, util.NullValue) +
Expand All @@ -158,22 +163,25 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
wtDescription,
fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
// Needs both an open and closed status or workitems cannot be created for worktype.
fmt.Sprintf(`
statuses {
name = "%s"
description = "%s"
category = "%s"
}
statuses {
name = "%s"
description = "%s"
category = "%s"
}
default_status_name = "%s"
`, wtOStatusName, wtOStatusDesc, wtOStatusCategory,
wtCStatusName, wtCStatusDesc, wtCStatusCategory,
wtOStatusName),
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceOpen,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtOStatusName,
wtOStatusCategory,
wtOStatusDesc,
util.NullValue,
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceClosed,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtCStatusName,
wtCStatusCategory,
wtCStatusDesc,
util.NullValue,
"",
)
)

Expand All @@ -184,7 +192,12 @@ func TestAccResourceTaskManagementWorkitem(t *testing.T) {
// Create basic workitem
{
Config: taskMgmtConfig +
generateWorkitemResourceBasic(workitemRes, workitem1.name, workitem1.worktype_id, ""),
generateWorkitemResourceBasic(
workitemRes,
workitem1.name,
workitem1.worktype_id,
fmt.Sprintf("depends_on = [genesyscloud_task_management_worktype_status.%s, genesyscloud_task_management_worktype_status.%s]", statusResourceOpen, statusResourceClosed),
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("genesyscloud_task_management_workitem."+workitemRes, "name", workitem1.name),
resource.TestCheckResourceAttrPair("genesyscloud_task_management_workitem."+workitemRes, "worktype_id", "genesyscloud_task_management_worktype."+wtResName, "id"),
Expand Down Expand Up @@ -397,12 +410,16 @@ func TestAccResourceTaskManagementWorkitemCustomFields(t *testing.T) {
wtResName = "tf_worktype_1"
wtName = "tf-worktype" + uuid.NewString()
wtDescription = "tf-worktype-description"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"

// Worktype statuses
statusResourceOpen = "open-status"
wtOStatusName = "Open Status"
wtOStatusDesc = "Description of open status"
wtOStatusCategory = "Open"
statusResourceClosed = "closed-status"
wtCStatusName = "Closed Status"
wtCStatusDesc = "Description of closed status"
wtCStatusCategory = "Closed"

// basic workitem
workitemRes = "workitem_1"
Expand Down Expand Up @@ -455,22 +472,25 @@ func TestAccResourceTaskManagementWorkitemCustomFields(t *testing.T) {
wtDescription,
fmt.Sprintf("genesyscloud_task_management_workbin.%s.id", wbResourceId),
fmt.Sprintf("genesyscloud_task_management_workitem_schema.%s.id", wsResourceId),
// Needs both an open and closed status or workitems cannot be created for worktype.
fmt.Sprintf(`
statuses {
name = "%s"
description = "%s"
category = "%s"
}
statuses {
name = "%s"
description = "%s"
category = "%s"
}
default_status_name = "%s"
`, wtOStatusName, wtOStatusDesc, wtOStatusCategory,
wtCStatusName, wtCStatusDesc, wtCStatusCategory,
wtOStatusName),
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceOpen,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtOStatusName,
wtOStatusCategory,
wtOStatusDesc,
util.NullValue,
"",
) +
worktypeStatus.GenerateWorktypeStatusResource(
statusResourceClosed,
fmt.Sprintf("genesyscloud_task_management_worktype.%s.id", wtResName),
wtCStatusName,
wtCStatusCategory,
wtCStatusDesc,
util.NullValue,
"",
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func (p *TaskManagementWorktypeProxy) getTaskManagementWorktypeByName(ctx contex
return p.getTaskManagementWorktypeByNameAttr(ctx, p, name)
}

// getTaskManagementWorktypeById returns a single Genesys Cloud task management worktype by Id
func (p *TaskManagementWorktypeProxy) getTaskManagementWorktypeById(ctx context.Context, id string) (taskManagementWorktype *platformclientv2.Worktype, resp *platformclientv2.APIResponse, err error) {
// GetTaskManagementWorktypeById returns a single Genesys Cloud task management worktype by Id
func (p *TaskManagementWorktypeProxy) GetTaskManagementWorktypeById(ctx context.Context, id string) (taskManagementWorktype *platformclientv2.Worktype, resp *platformclientv2.APIResponse, err error) {
return p.getTaskManagementWorktypeByIdAttr(ctx, p, id)
}

// updateTaskManagementWorktype updates a Genesys Cloud task management worktype
func (p *TaskManagementWorktypeProxy) updateTaskManagementWorktype(ctx context.Context, id string, taskManagementWorktype *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
// UpdateTaskManagementWorktype updates a Genesys Cloud task management worktype
func (p *TaskManagementWorktypeProxy) UpdateTaskManagementWorktype(ctx context.Context, id string, taskManagementWorktype *platformclientv2.Worktypeupdate) (*platformclientv2.Worktype, *platformclientv2.APIResponse, error) {
return p.updateTaskManagementWorktypeAttr(ctx, p, id, taskManagementWorktype)
}

Expand Down
Loading

0 comments on commit 99a5b8c

Please sign in to comment.