Skip to content

Commit

Permalink
adde test for ApplicationTypeGet() and request with a tenant
Browse files Browse the repository at this point in the history
usually it is not needet to include a tenant to the request but
it is expected that it will work with or without a tenant
  • Loading branch information
petracihalova committed Jul 26, 2022
1 parent c9d8365 commit 890e064
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions application_type_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestApplicationTypeList(t *testing.T) {
}

// TestApplicationTypeListWithTenant tests that list of application types is returned
// even when tenant is provided (this request doesn't need a tenant)
// even when tenant is provided (the request usually doesn't need a tenant)
func TestApplicationTypeListWithTenant(t *testing.T) {
tenantId := int64(1)
c, rec := request.CreateTestContext(
Expand All @@ -318,7 +318,7 @@ func TestApplicationTypeListWithTenant(t *testing.T) {
"limit": 100,
"offset": 0,
"filters": []util.Filter{},
"tenant": tenantId,
"tenant": tenantId,
},
)

Expand Down Expand Up @@ -388,6 +388,42 @@ func TestApplicationTypeGet(t *testing.T) {
}
}

// TestApplicationTypeGetWithTenant tests that application type is returned
// even when tenant is provided (the request usually doesn't need a tenant)
func TestApplicationTypeGetWithTenant(t *testing.T) {
tenantId := int64(1)
c, rec := request.CreateTestContext(
http.MethodGet,
"/api/sources/v3.1/application_types/1",
nil,
map[string]interface{}{
"tenant": tenantId,
},
)

c.SetParamNames("id")
c.SetParamValues("1")

err := ApplicationTypeGet(c)
if err != nil {
t.Error(err)
}

if rec.Code != 200 {
t.Error("Did not return 200")
}

var outAppType m.ApplicationTypeResponse
err = json.Unmarshal(rec.Body.Bytes(), &outAppType)
if err != nil {
t.Error("Failed unmarshaling output")
}

if outAppType.DisplayName != "test app type" {
t.Error("ghosts infected the return")
}
}

func TestApplicationTypeGetNotFound(t *testing.T) {
c, rec := request.CreateTestContext(
http.MethodGet,
Expand Down

0 comments on commit 890e064

Please sign in to comment.