Skip to content
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

[Unit Tests] - ValidateTicketReviewRequest #2292

Closed
tomsmith8 opened this issue Dec 24, 2024 · 4 comments · Fixed by #2299
Closed

[Unit Tests] - ValidateTicketReviewRequest #2292

tomsmith8 opened this issue Dec 24, 2024 · 4 comments · Fixed by #2299
Assignees

Comments

@tomsmith8
Copy link

Unit Test Coverage for "ValidateTicketReviewRequest"


Stakwork Run


Unit Test Code


File: /tmp/stakwork/sphinx-tribes/utils/ticket_processor.go


package utils

import (
  "errors"
  "strings"
  "testing"

  "github.com/stretchr/testify/assert"
)

// Mock struct for testing
type TicketReviewRequest struct {
  Value struct {
  	FeatureUUID       string
  	PhaseUUID         string
  	TicketUUID        string
  	TicketDescription string
  }
}

func TestValidateTicketReviewRequest(t *testing.T) {
  tests := []struct {
  	name     string
  	input    *TicketReviewRequest
  	expected error
  }{
  	{
  		name: "Valid Input",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "123e4567-e89b-12d3-a456-426614174000",
  				TicketDescription: "This is a valid ticket description.",
  			},
  		},
  		expected: nil,
  	},
  	{
  		name: "Empty TicketUUID",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "",
  				TicketDescription: "This is a valid ticket description.",
  			},
  		},
  		expected: errors.New("ticketUUID is required"),
  	},
  	{
  		name: "Empty TicketDescription",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "123e4567-e89b-12d3-a456-426614174000",
  				TicketDescription: "",
  			},
  		},
  		expected: errors.New("ticketDescription is required"),
  	},
  	{
  		name: "Both TicketUUID and TicketDescription Empty",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "",
  				TicketDescription: "",
  			},
  		},
  		expected: errors.New("ticketUUID is required"),
  	},
  	{
  		name:     "Nil Request",
  		input:    nil,
  		expected: errors.New("nil request"),
  	},
  	{
  		name: "Whitespace TicketUUID",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "   ",
  				TicketDescription: "This is a valid ticket description.",
  			},
  		},
  		expected: errors.New("ticketUUID is required"),
  	},
  	{
  		name: "Whitespace TicketDescription",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "123e4567-e89b-12d3-a456-426614174000",
  				TicketDescription: "   ",
  			},
  		},
  		expected: errors.New("ticketDescription is required"),
  	},
  	{
  		name: "Large TicketDescription",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "123e4567-e89b-12d3-a456-426614174000",
  				TicketDescription: strings.Repeat("a", 10000),
  			},
  		},
  		expected: nil,
  	},
  	{
  		name: "Non-UUID TicketUUID",
  		input: &TicketReviewRequest{
  			Value: struct {
  				FeatureUUID       string
  				PhaseUUID         string
  				TicketUUID        string
  				TicketDescription string
  			}{
  				TicketUUID:        "not-a-uuid",
  				TicketDescription: "This is a valid ticket description.",
  			},
  		},
  		expected: nil,
  	},
  }

  for _, tt := range tests {
  	t.Run(tt.name, func(t *testing.T) {
  		var result error
  		if tt.input == nil {
  			result = errors.New("nil request")
  		} else {
  			result = ValidateTicketReviewRequest(tt.input)
  		}
  		assert.Equal(t, tt.expected, result)
  	})
  }
}
@saithsab877
Copy link
Contributor

@tomsmith8 assign me?

@aliraza556
Copy link
Contributor

@tomsmith8 Please assign me?

@MahtabBukhari
Copy link
Contributor

@tomsmith8 please assign

@AhsanFarooqDev
Copy link
Contributor

@tomsmith8 can I help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants