-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HMS-3155 test: add user update domain
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
Showing
3 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters