Skip to content

Commit

Permalink
RHINENG-14351: add tests for system authenticated API for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMraka committed Dec 11, 2024
1 parent 7905aa4 commit a1c1af9
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions manager/controllers/template_subscribed_systems_update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package controllers

import (
"app/base/core"
"app/base/database"
"app/base/utils"
"net/http"
"net/http/httptest"
"testing"

"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)

var subscriptionUUID = "cccccccc-0000-0000-0001-000000000004"
var templateSystemUUID = "00000000-0000-0000-0000-000000000004"

func TestSubscribedSystemID(t *testing.T) {
core.SetupTest(t)

c, _ := gin.CreateTestContext(httptest.NewRecorder())
c.Set(utils.KeyAccount, templateAccount)
c.Set(utils.KeySystem, subscriptionUUID)
account, systemID, err := getSubscribedSystem(c, database.DB)

assert.Nil(t, err)
assert.Equal(t, templateAccount, account)
assert.Equal(t, templateSystemUUID, systemID)
}

func TestUnknownSubscribedSystemID(t *testing.T) {
core.SetupTest(t)

c, _ := gin.CreateTestContext(httptest.NewRecorder())
c.Set(utils.KeyAccount, templateAccount)
c.Set(utils.KeySystem, "unknown-uuid")
account, systemID, err := getSubscribedSystem(c, database.DB)

assert.EqualError(t, err, "System unknown-uuid not found")
assert.Equal(t, 0, account)
assert.Equal(t, "", systemID)
}

func TestUpdateTemplateSubscribedSystems(t *testing.T) {
core.SetupTest(t)

database.CreateTemplate(t, templateAccount, templateUUID, nil)

w := CreateRequestRouterWithParams("PATCH", "/:template_id/subscribed-systems", templateUUID, "", nil, "",
TemplateSubscribedSystemsUpdateHandler, templateAccount,
core.ContextKV{Key: utils.KeySystem, Value: subscriptionUUID})

assert.Equal(t, http.StatusOK, w.Code)
database.CheckTemplateSystems(t, templateAccount, templateUUID, []string{templateSystemUUID})
database.DeleteTemplate(t, templateAccount, templateUUID)
}

0 comments on commit a1c1af9

Please sign in to comment.