Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Additional Unit test for missed branch #2765

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chart/compass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ global:
name: compass-pairing-adapter
director:
dir:
version: "PR-2741"
version: "PR-2765"
name: compass-director
hydrator:
dir:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,22 @@ func TestConverter_ApplicationFromTemplateInputFromGraphQL(t *testing.T) {
assert.Equal(t, expected, result)
}

func TestConverter_ApplicationFromTemplateInputFromGraphQLWithPlaceholderPayload(t *testing.T) {
// GIVEN
conv := apptemplate.NewConverter(nil, nil)
appTemplateModel := fixModelApplicationTemplateWithPlaceholdersPayload(testID, testName, fixModelApplicationTemplateWebhooks("webhook-id-1", testID))

in := fixGQLApplicationFromTemplateInputWithPlaceholderPayload(testName)
expected := fixModelApplicationFromTemplateInputWithPlaceholderPayload(testName)

// WHEN
result, err := conv.ApplicationFromTemplateInputFromGraphQL(appTemplateModel, in)

// THEN
require.NoError(t, err)
assert.Equal(t, expected, result)
}

func TestConverter_ToEntity(t *testing.T) {
// GIVEN
appTemplateModel := fixModelApplicationTemplate(testID, testName, fixModelApplicationTemplateWebhooks("webhook-id-1", testID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
var (
testUUID = "b3ea1977-582e-4d61-ae12-b3a837a3858e"
testDescription = "Lorem ipsum"
testJSONPath = ".displayName"
testJSONPath = "test"
testDescriptionWithPlaceholder = "Lorem ipsum {{test}}"
testProviderName = "provider-display-name"
testURL = "http://valid.url"
Expand All @@ -62,6 +62,22 @@ func fixModelApplicationTemplate(id, name string, webhooks []*model.Webhook) *mo
return &out
}

func fixModelApplicationTemplateWithPlaceholdersPayload(id, name string, webhooks []*model.Webhook) *model.ApplicationTemplate {
desc := testDescription
out := model.ApplicationTemplate{
ID: id,
Name: name,
Description: &desc,
ApplicationNamespace: str.Ptr("ns"),
ApplicationInputJSON: appInputJSONString,
Placeholders: fixModelPlaceholdersWithPayload(),
Webhooks: modelPtrsToWebhooks(webhooks),
AccessLevel: model.GlobalApplicationTemplateAccessLevel,
}

return &out
}

func fixModelAppTemplateWithAppInputJSON(id, name, appInputJSON string, webhooks []*model.Webhook) *model.ApplicationTemplate {
out := fixModelApplicationTemplate(id, name, webhooks)
out.ApplicationInputJSON = appInputJSON
Expand Down Expand Up @@ -295,6 +311,25 @@ func fixModelPlaceholders() []model.ApplicationTemplatePlaceholder {
}
}

func fixModelPlaceholdersWithPayload() []model.ApplicationTemplatePlaceholder {
placeholderTestDesc := testDescription
placeholderTestJSONPath := testJSONPath
placeholderNameDesc := "Application Name placeholder"
placeholderNameJSONPath := "name"
return []model.ApplicationTemplatePlaceholder{
{
Name: "test",
Description: &placeholderTestDesc,
JSONPath: &placeholderTestJSONPath,
},
{
Name: "name",
Description: &placeholderNameDesc,
JSONPath: &placeholderNameJSONPath,
},
}
}

func fixModelApplicationWebhooks(webhookID, applicationID string) []*model.Webhook {
return []*model.Webhook{
{
Expand Down Expand Up @@ -389,6 +424,24 @@ func fixModelApplicationFromTemplateInput(name string) model.ApplicationFromTemp
}
}

func fixGQLApplicationFromTemplateInputWithPlaceholderPayload(name string) graphql.ApplicationFromTemplateInput {
placeholdersPayload := `{"name": "appName", "test":"testValue"}`
return graphql.ApplicationFromTemplateInput{
TemplateName: name,
PlaceholdersPayload: &placeholdersPayload,
}
}

func fixModelApplicationFromTemplateInputWithPlaceholderPayload(name string) model.ApplicationFromTemplateInput {
return model.ApplicationFromTemplateInput{
TemplateName: name,
Values: []*model.ApplicationTemplateValueInput{
{Placeholder: "test", Value: "testValue"},
{Placeholder: "name", Value: "appName"},
},
}
}

func fixAppTemplateCreateArgs(entity apptemplate.Entity) []driver.Value {
return []driver.Value{entity.ID, entity.Name, entity.Description, entity.ApplicationNamespace, entity.ApplicationInputJSON, entity.PlaceholdersJSON, entity.AccessLevel}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ func TestService_PrepareApplicationCreateInputJSON(t *testing.T) {
InputAppTemplate: &model.ApplicationTemplate{
ApplicationInputJSON: `{"Name": "{{name}}", "Description": "Lorem ipsum"}`,
Placeholders: []model.ApplicationTemplatePlaceholder{
{Name: "name", Description: str.Ptr("Application name"), JSONPath: str.Ptr(".displayName")},
{Name: "name", Description: str.Ptr("Application name"), JSONPath: str.Ptr("displayName")},
},
},
InputValues: []*model.ApplicationTemplateValueInput{
Expand All @@ -1436,7 +1436,7 @@ func TestService_PrepareApplicationCreateInputJSON(t *testing.T) {
InputAppTemplate: &model.ApplicationTemplate{
ApplicationInputJSON: `{"Name": "{{name}}", "Description": "Lorem ipsum"}`,
Placeholders: []model.ApplicationTemplatePlaceholder{
{Name: "name", Description: str.Ptr("Application name"), JSONPath: str.Ptr(".displayName")},
{Name: "name", Description: str.Ptr("Application name"), JSONPath: str.Ptr("displayName")},
},
},
InputValues: []*model.ApplicationTemplateValueInput{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var (
testDescription = "{{display-name}}"
testJSONPath = ".displayName"
testJSONPath = "displayName"
testProviderName = "provider-display-name"
testURL = "http://valid.url"
appInputJSONString = `{"Name":"foo","ProviderName":"compass","Description":"Lorem ipsum","Labels":{"test":["val","val2"]},"HealthCheckURL":"https://foo.bar","Webhooks":[{"Type":"","URL":"webhook1.foo.bar","Auth":null},{"Type":"","URL":"webhook2.foo.bar","Auth":null}],"IntegrationSystemID":"iiiiiiiii-iiii-iiii-iiii-iiiiiiiiiiii"}`
Expand Down
26 changes: 13 additions & 13 deletions components/director/pkg/graphql/app_template_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestApplicationTemplateInput_Validate_Rule_ValidPlaceholders(t *testing.T)
{
Name: "Valid",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
},
Valid: true,
},
Expand All @@ -37,15 +37,15 @@ func TestApplicationTemplateInput_Validate_Rule_ValidPlaceholders(t *testing.T)
{
Name: "Invalid - not unique",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Different description"), JSONPath: str.Ptr(".displayName2")},
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Different description"), JSONPath: str.Ptr("displayName2")},
},
Valid: false,
},
{
Name: "Invalid - not used",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: "notused", Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: "notused", Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
},
Valid: false,
},
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestApplicationTemplateInput_Validate_Description(t *testing.T) {
Valid bool
}{
{
Name: "Valid",
Name: "Valid",
Value: str.Ptr("valid valid"),
Valid: true,
},
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestApplicationTemplateInput_Validate_Placeholders(t *testing.T) {
{
Name: "Valid",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
},
Valid: true,
},
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestApplicationTemplateUpdateInput_Validate_Rule_ValidPlaceholders(t *testi
{
Name: "Valid",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
},
Valid: true,
},
Expand All @@ -387,15 +387,15 @@ func TestApplicationTemplateUpdateInput_Validate_Rule_ValidPlaceholders(t *testi
{
Name: "Invalid - not unique",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Different description"), JSONPath: str.Ptr(".displayName2")},
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Different description"), JSONPath: str.Ptr("displayName2")},
},
Valid: false,
},
{
Name: "Invalid - not used",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: "notused", Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: "notused", Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
},
Valid: false,
},
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestApplicationTemplateUpdateInput_Validate_Description(t *testing.T) {
Valid bool
}{
{
Name: "Valid",
Name: "Valid",
Value: str.Ptr("valid valid"),
Valid: true,
},
Expand Down Expand Up @@ -524,7 +524,7 @@ func TestApplicationTemplateUpdateInput_Validate_Placeholders(t *testing.T) {
{
Name: "Valid",
Value: []*graphql.PlaceholderDefinitionInput{
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr(".displayName")},
{Name: testPlaceholderName, Description: str.Ptr("Test description"), JSONPath: str.Ptr("displayName")},
},
Valid: true,
},
Expand Down Expand Up @@ -716,7 +716,7 @@ func TestPlaceholderDefinitionInput_Validate_Description(t *testing.T) {
Valid bool
}{
{
Name: "Valid",
Name: "Valid",
Value: str.Ptr("valid valid"),
Valid: true,
},
Expand Down
Loading