Skip to content

Commit

Permalink
HMS-3155 test: add user update domain
Browse files Browse the repository at this point in the history
This change add a smoke test to verify a success user update operation on an
existing domain.

Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo committed Dec 1, 2023
1 parent d371fe4 commit f013c0a
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
47 changes: 47 additions & 0 deletions internal/test/builder/api/builder_update_domain_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package api

import (
"github.com/openlyinc/pointy"
"github.com/podengo-project/idmsvc-backend/internal/api/public"
"github.com/podengo-project/idmsvc-backend/internal/test/builder/helper"
)

type UpdateDomainUserJSONRequestBody interface {
Build() *public.UpdateDomainUserJSONRequestBody
WithTitle(value *string) UpdateDomainUserJSONRequestBody
WithDescription(value *string) UpdateDomainUserJSONRequestBody
WithAutoEnrollmentEnabled(value *bool) UpdateDomainUserJSONRequestBody
}

type updateDomainUserJSONRequestBody public.UpdateDomainUserJSONRequestBody

// NewUpdateDomainUserJSONRequestBody instantiate a new generator for
// the user domain patch operation.
func NewUpdateDomainUserJSONRequestBody() UpdateDomainUserJSONRequestBody {
letters := []rune("abcdefghijklmnopqrstuvwxyz 0123456789")
return &updateDomainUserJSONRequestBody{
// TODO Enhance generator
Title: pointy.String(helper.GenRandomString(letters, 30)),
AutoEnrollmentEnabled: pointy.Bool(helper.GenRandBool()),
Description: pointy.String(helper.GenLorempIpsum()),
}
}

func (b *updateDomainUserJSONRequestBody) Build() *public.UpdateDomainUserJSONRequestBody {
return (*public.UpdateDomainUserJSONRequestBody)(b)
}

func (b *updateDomainUserJSONRequestBody) WithTitle(value *string) UpdateDomainUserJSONRequestBody {
b.Title = value
return b
}

func (b *updateDomainUserJSONRequestBody) WithDescription(value *string) UpdateDomainUserJSONRequestBody {
b.Description = value
return b
}

func (b *updateDomainUserJSONRequestBody) WithAutoEnrollmentEnabled(value *bool) UpdateDomainUserJSONRequestBody {
b.AutoEnrollmentEnabled = value
return b
}
76 changes: 76 additions & 0 deletions internal/test/smoke/domain_update_user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package smoke

import (
"fmt"
"net/http"
"testing"

"github.com/podengo-project/idmsvc-backend/internal/api/header"
"github.com/podengo-project/idmsvc-backend/internal/api/public"
builder_api "github.com/podengo-project/idmsvc-backend/internal/test/builder/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// SuiteDomainUpdateUser is the suite to validate the smoke test when a user update the domain endpoint at PATCH /api/idmsvc/v1/domains/:domain_id
type SuiteDomainUpdateUser struct {
SuiteReadDomain
}

func (s *SuiteDomainUpdateUser) SetupTest() {
s.SuiteReadDomain.SetupTest()
}

func (s *SuiteDomainUpdateUser) TearDownTest() {
s.SuiteReadDomain.TearDownTest()
}

func (s *SuiteDomainUpdateUser) TestReadDomain() {
t := s.T()
t.Skip("skipping parent duplicated test")
}

func (s *SuiteDomainUpdateUser) TestPatchDomain() {
xrhidEncoded := header.EncodeXRHID(&s.UserXRHID)
url := fmt.Sprintf("%s/%s/%s", s.DefaultPublicBaseURL(), "domains", s.Domains[0].DomainId.String())
patchedDomain := builder_api.NewUpdateDomainUserJSONRequestBody().Build()

// Prepare the tests
testCases := []TestCase{
{
Name: "TestPatchDomain",
Given: TestCaseGiven{
Method: http.MethodPatch,
URL: url,
Header: http.Header{
"X-Rh-Insights-Request-Id": {"test_domain_patch"},
"X-Rh-Identity": {xrhidEncoded},
},
Body: patchedDomain,
},
Expected: TestCaseExpect{
StatusCode: http.StatusOK,
Header: http.Header{
"X-Rh-Insights-Request-Id": {"test_domain_patch"},
"X-Rh-Identity": nil,
},
BodyFunc: WrapBodyFuncDomainResponse(func(t *testing.T, body *public.Domain) error {
require.NotNil(t, body)
if patchedDomain.Title != nil {
assert.Equal(t, patchedDomain.Title, body.Title)
}
if patchedDomain.Description != nil {
assert.Equal(t, patchedDomain.Description, body.Description)
}
if patchedDomain.AutoEnrollmentEnabled != nil {
assert.Equal(t, patchedDomain.AutoEnrollmentEnabled, body.AutoEnrollmentEnabled)
}
return nil
}),
},
},
}

// Execute the test cases
s.RunTestCases(testCases)
}
4 changes: 2 additions & 2 deletions internal/test/smoke/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ func TestSuite(t *testing.T) {
// TODO Add here your test suites
suite.Run(t, new(SuiteTokenCreate))
suite.Run(t, new(SuiteRegisterDomain))
// suite.Run(t, new(SuiteDomainUpdateUser))
// suite.Run(t, new(SuiteDomainUpdateAgent))
suite.Run(t, new(SuiteReadDomain))
suite.Run(t, new(SuiteDomainUpdateUser))
// suite.Run(t, new(SuiteDomainUpdateAgent))
suite.Run(t, new(SuiteListDomains))
// suite.Run(t, new(SuiteDomainDelete))
}

0 comments on commit f013c0a

Please sign in to comment.