github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/bundle/fixtures_test.go (about)

     1  package bundle_test
     2  
     3  import (
     4  	"database/sql"
     5  	"database/sql/driver"
     6  	"encoding/json"
     7  	"fmt"
     8  
     9  	"time"
    10  
    11  	"github.com/kyma-incubator/compass/components/director/internal/domain/api"
    12  
    13  	"github.com/kyma-incubator/compass/components/director/internal/repo"
    14  	"github.com/kyma-incubator/compass/components/director/pkg/str"
    15  
    16  	"github.com/kyma-incubator/compass/components/director/internal/domain/bundle"
    17  
    18  	"github.com/kyma-incubator/compass/components/director/internal/model"
    19  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
    20  	"github.com/kyma-incubator/compass/components/director/pkg/pagination"
    21  )
    22  
    23  var fixedTimestamp = time.Now()
    24  
    25  func fixModelAPIDefinition(id string, name, description string, group string) *model.APIDefinition {
    26  	return &model.APIDefinition{
    27  		Name:        name,
    28  		Description: &description,
    29  		Group:       &group,
    30  		BaseEntity:  &model.BaseEntity{ID: id},
    31  	}
    32  }
    33  
    34  func fixGQLAPIDefinition(id string, bndlID string, name, description string, group string) *graphql.APIDefinition {
    35  	return &graphql.APIDefinition{
    36  		BaseEntity: &graphql.BaseEntity{
    37  			ID: id,
    38  		},
    39  		BundleID:    bndlID,
    40  		Name:        name,
    41  		Description: &description,
    42  		Group:       &group,
    43  	}
    44  }
    45  
    46  func fixAPIDefinitionPage(apiDefinitions []*model.APIDefinition) *model.APIDefinitionPage {
    47  	return &model.APIDefinitionPage{
    48  		Data: apiDefinitions,
    49  		PageInfo: &pagination.Page{
    50  			StartCursor: "start",
    51  			EndCursor:   "end",
    52  			HasNextPage: false,
    53  		},
    54  		TotalCount: len(apiDefinitions),
    55  	}
    56  }
    57  
    58  func fixGQLAPIDefinitionPage(apiDefinitions []*graphql.APIDefinition) *graphql.APIDefinitionPage {
    59  	return &graphql.APIDefinitionPage{
    60  		Data: apiDefinitions,
    61  		PageInfo: &graphql.PageInfo{
    62  			StartCursor: "start",
    63  			EndCursor:   "end",
    64  			HasNextPage: false,
    65  		},
    66  		TotalCount: len(apiDefinitions),
    67  	}
    68  }
    69  
    70  func fixModelEventAPIDefinition(id string, name, description string, group string) *model.EventDefinition {
    71  	return &model.EventDefinition{
    72  		Name:        name,
    73  		Description: &description,
    74  		Group:       &group,
    75  		BaseEntity:  &model.BaseEntity{ID: id},
    76  	}
    77  }
    78  
    79  func fixGQLEventDefinition(id string, bundleID string, name, description string, group string) *graphql.EventDefinition {
    80  	return &graphql.EventDefinition{
    81  		BaseEntity: &graphql.BaseEntity{
    82  			ID: id,
    83  		},
    84  		BundleID:    bundleID,
    85  		Name:        name,
    86  		Description: &description,
    87  		Group:       &group,
    88  	}
    89  }
    90  
    91  func fixEventAPIDefinitionPage(eventAPIDefinitions []*model.EventDefinition) *model.EventDefinitionPage {
    92  	return &model.EventDefinitionPage{
    93  		Data: eventAPIDefinitions,
    94  		PageInfo: &pagination.Page{
    95  			StartCursor: "start",
    96  			EndCursor:   "end",
    97  			HasNextPage: false,
    98  		},
    99  		TotalCount: len(eventAPIDefinitions),
   100  	}
   101  }
   102  
   103  func fixGQLEventDefinitionPage(eventAPIDefinitions []*graphql.EventDefinition) *graphql.EventDefinitionPage {
   104  	return &graphql.EventDefinitionPage{
   105  		Data: eventAPIDefinitions,
   106  		PageInfo: &graphql.PageInfo{
   107  			StartCursor: "start",
   108  			EndCursor:   "end",
   109  			HasNextPage: false,
   110  		},
   111  		TotalCount: len(eventAPIDefinitions),
   112  	}
   113  }
   114  
   115  var (
   116  	docKind              = "fookind"
   117  	docTitle             = "footitle"
   118  	docData              = "foodata"
   119  	docCLOB              = graphql.CLOB(docData)
   120  	desc                 = "Lorem Ipsum"
   121  	appID                = "aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
   122  	appTemplateVersionID = "bbbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
   123  )
   124  
   125  func fixModelDocument(bundleID, id string) *model.Document {
   126  	return &model.Document{
   127  		BundleID:   bundleID,
   128  		Title:      docTitle,
   129  		Format:     model.DocumentFormatMarkdown,
   130  		Kind:       &docKind,
   131  		Data:       &docData,
   132  		BaseEntity: &model.BaseEntity{ID: id},
   133  	}
   134  }
   135  
   136  func fixModelDocumentPage(documents []*model.Document) *model.DocumentPage {
   137  	return &model.DocumentPage{
   138  		Data: documents,
   139  		PageInfo: &pagination.Page{
   140  			StartCursor: "start",
   141  			EndCursor:   "end",
   142  			HasNextPage: false,
   143  		},
   144  		TotalCount: len(documents),
   145  	}
   146  }
   147  
   148  func fixGQLDocument(id string) *graphql.Document {
   149  	return &graphql.Document{
   150  		BaseEntity: &graphql.BaseEntity{
   151  			ID: id,
   152  		},
   153  		Title:  docTitle,
   154  		Format: graphql.DocumentFormatMarkdown,
   155  		Kind:   &docKind,
   156  		Data:   &docCLOB,
   157  	}
   158  }
   159  
   160  func fixGQLDocumentPage(documents []*graphql.Document) *graphql.DocumentPage {
   161  	return &graphql.DocumentPage{
   162  		Data: documents,
   163  		PageInfo: &graphql.PageInfo{
   164  			StartCursor: "start",
   165  			EndCursor:   "end",
   166  			HasNextPage: false,
   167  		},
   168  		TotalCount: len(documents),
   169  	}
   170  }
   171  
   172  const (
   173  	bundleID         = "ddddddddd-dddd-dddd-dddd-dddddddddddd"
   174  	tenantID         = "b91b59f7-2563-40b2-aba9-fef726037aa3"
   175  	externalTenantID = "eeeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee"
   176  	ordID            = "com.compass.v1"
   177  	localTenantID    = "localTenantID"
   178  	correlationIDs   = `["id1", "id2"]`
   179  	version          = "1.2.2"
   180  	resourceHash     = "123456"
   181  )
   182  
   183  func fixBundleModel(name, desc string) *model.Bundle {
   184  	return fixBundleModelWithIDAndAppID(bundleID, name, desc)
   185  }
   186  
   187  func fixBundleModelWithID(id, name, desc string) *model.Bundle {
   188  	return &model.Bundle{
   189  		Name:                           name,
   190  		Description:                    &desc,
   191  		Version:                        str.Ptr(version),
   192  		InstanceAuthRequestInputSchema: fixBasicSchema(),
   193  		DefaultInstanceAuth:            fixModelAuth(),
   194  		OrdID:                          str.Ptr(ordID),
   195  		LocalTenantID:                  str.Ptr(localTenantID),
   196  		ShortDescription:               str.Ptr("short_description"),
   197  		Links:                          json.RawMessage("[]"),
   198  		Labels:                         json.RawMessage("[]"),
   199  		CredentialExchangeStrategies:   json.RawMessage("[]"),
   200  		CorrelationIDs:                 json.RawMessage(correlationIDs),
   201  		Tags:                           json.RawMessage("[]"),
   202  		ResourceHash:                   str.Ptr(resourceHash),
   203  		DocumentationLabels:            json.RawMessage("[]"),
   204  		BaseEntity: &model.BaseEntity{
   205  			ID:        id,
   206  			Ready:     true,
   207  			Error:     nil,
   208  			CreatedAt: &fixedTimestamp,
   209  			UpdatedAt: &time.Time{},
   210  			DeletedAt: &time.Time{},
   211  		},
   212  	}
   213  }
   214  
   215  func fixBundleModelWithIDAndAppID(id, name, desc string) *model.Bundle {
   216  	bundle := fixBundleModelWithID(id, name, desc)
   217  	bundle.ApplicationID = &appID
   218  	return bundle
   219  }
   220  func fixBundleModelWithIDAndAppTemplateVersionID(id, name, desc string) *model.Bundle {
   221  	bundle := fixBundleModelWithID(id, name, desc)
   222  	bundle.ApplicationTemplateVersionID = &appTemplateVersionID
   223  	return bundle
   224  }
   225  
   226  func fixGQLBundle(id, name, desc string) *graphql.Bundle {
   227  	schema := graphql.JSONSchema(`{"$id":"https://example.com/person.schema.json","$schema":"http://json-schema.org/draft-07/schema#","properties":{"age":{"description":"Age in years which must be equal to or greater than zero.","minimum":0,"type":"integer"},"firstName":{"description":"The person's first name.","type":"string"},"lastName":{"description":"The person's last name.","type":"string"}},"title":"Person","type":"object"}`)
   228  	var correlationIDsAsSlice []string
   229  	err := json.Unmarshal([]byte(correlationIDs), &correlationIDsAsSlice)
   230  	if err != nil {
   231  		panic(err)
   232  	}
   233  	return &graphql.Bundle{
   234  		Name:                           name,
   235  		Description:                    &desc,
   236  		InstanceAuthRequestInputSchema: &schema,
   237  		DefaultInstanceAuth:            fixGQLAuth(),
   238  		CorrelationIDs:                 correlationIDsAsSlice,
   239  		BaseEntity: &graphql.BaseEntity{
   240  			ID:        id,
   241  			Ready:     true,
   242  			Error:     nil,
   243  			CreatedAt: timeToTimestampPtr(fixedTimestamp),
   244  			UpdatedAt: timeToTimestampPtr(time.Time{}),
   245  			DeletedAt: timeToTimestampPtr(time.Time{}),
   246  		},
   247  	}
   248  }
   249  
   250  func fixGQLBundleCreateInput(name, description string) graphql.BundleCreateInput {
   251  	basicCredentialDataInput := graphql.BasicCredentialDataInput{
   252  		Username: "test",
   253  		Password: "pwd",
   254  	}
   255  
   256  	credentialDataInput := graphql.CredentialDataInput{Basic: &basicCredentialDataInput}
   257  	defaultAuth := graphql.AuthInput{
   258  		Credential: &credentialDataInput,
   259  	}
   260  
   261  	return graphql.BundleCreateInput{
   262  		Name:                           name,
   263  		Description:                    &description,
   264  		InstanceAuthRequestInputSchema: fixBasicInputSchema(),
   265  		DefaultInstanceAuth:            &defaultAuth,
   266  		APIDefinitions: []*graphql.APIDefinitionInput{
   267  			{Name: "api1", TargetURL: "foo.bar"},
   268  			{Name: "api2", TargetURL: "foo.bar2"},
   269  		},
   270  		EventDefinitions: []*graphql.EventDefinitionInput{
   271  			{Name: "event1", Description: &desc},
   272  			{Name: "event2", Description: &desc},
   273  		},
   274  		Documents: []*graphql.DocumentInput{
   275  			{DisplayName: "doc1", Kind: &docKind},
   276  			{DisplayName: "doc2", Kind: &docKind},
   277  		},
   278  	}
   279  }
   280  
   281  func fixModelBundleCreateInput(name, description string) model.BundleCreateInput {
   282  	basicCredentialDataInput := model.BasicCredentialDataInput{
   283  		Username: "test",
   284  		Password: "pwd",
   285  	}
   286  	authInput := model.AuthInput{
   287  		Credential: &model.CredentialDataInput{Basic: &basicCredentialDataInput},
   288  	}
   289  
   290  	specData1 := "spec_data1"
   291  	specData2 := "spec_data2"
   292  
   293  	return model.BundleCreateInput{
   294  		Name:                           name,
   295  		Description:                    &description,
   296  		InstanceAuthRequestInputSchema: fixBasicSchema(),
   297  		DefaultInstanceAuth:            &authInput,
   298  		APIDefinitions: []*model.APIDefinitionInput{
   299  			{Name: "api1", TargetURLs: api.ConvertTargetURLToJSONArray("foo.bar")},
   300  			{Name: "api2", TargetURLs: api.ConvertTargetURLToJSONArray("foo.bar2")},
   301  		},
   302  		APISpecs: []*model.SpecInput{
   303  			{Data: &specData1},
   304  			{Data: &specData2},
   305  		},
   306  		EventDefinitions: []*model.EventDefinitionInput{
   307  			{Name: "event1", Description: &desc},
   308  			{Name: "event2", Description: &desc},
   309  		},
   310  		EventSpecs: []*model.SpecInput{
   311  			{Data: &specData1},
   312  			{Data: &specData2},
   313  		},
   314  		Documents: []*model.DocumentInput{
   315  			{DisplayName: "doc1", Kind: &docKind},
   316  			{DisplayName: "doc2", Kind: &docKind},
   317  		},
   318  	}
   319  }
   320  
   321  func fixGQLBundleUpdateInput(name, description string) graphql.BundleUpdateInput {
   322  	basicCredentialDataInput := graphql.BasicCredentialDataInput{
   323  		Username: "test",
   324  		Password: "pwd",
   325  	}
   326  
   327  	credentialDataInput := graphql.CredentialDataInput{Basic: &basicCredentialDataInput}
   328  	defaultAuth := graphql.AuthInput{
   329  		Credential: &credentialDataInput,
   330  	}
   331  
   332  	return graphql.BundleUpdateInput{
   333  		Name:                           name,
   334  		Description:                    &description,
   335  		InstanceAuthRequestInputSchema: fixBasicInputSchema(),
   336  		DefaultInstanceAuth:            &defaultAuth,
   337  	}
   338  }
   339  
   340  func fixModelBundleUpdateInput(name, description string) model.BundleUpdateInput {
   341  	basicCredentialDataInput := model.BasicCredentialDataInput{
   342  		Username: "test",
   343  		Password: "pwd",
   344  	}
   345  	authInput := model.AuthInput{
   346  		Credential: &model.CredentialDataInput{Basic: &basicCredentialDataInput},
   347  	}
   348  
   349  	return model.BundleUpdateInput{
   350  		Name:                           name,
   351  		Description:                    &description,
   352  		InstanceAuthRequestInputSchema: fixBasicSchema(),
   353  		DefaultInstanceAuth:            &authInput,
   354  	}
   355  }
   356  
   357  func fixModelAuth() *model.Auth {
   358  	return &model.Auth{
   359  		Credential: model.CredentialData{
   360  			Basic: &model.BasicCredentialData{
   361  				Username: "foo",
   362  				Password: "bar",
   363  			},
   364  		},
   365  		AdditionalHeaders:     map[string][]string{"test": {"foo", "bar"}},
   366  		AdditionalQueryParams: map[string][]string{"test": {"foo", "bar"}},
   367  		RequestAuth: &model.CredentialRequestAuth{
   368  			Csrf: &model.CSRFTokenCredentialRequestAuth{
   369  				TokenEndpointURL: "foo.url",
   370  				Credential: model.CredentialData{
   371  					Basic: &model.BasicCredentialData{
   372  						Username: "boo",
   373  						Password: "far",
   374  					},
   375  				},
   376  				AdditionalHeaders:     map[string][]string{"test": {"foo", "bar"}},
   377  				AdditionalQueryParams: map[string][]string{"test": {"foo", "bar"}},
   378  			},
   379  		},
   380  	}
   381  }
   382  
   383  func fixGQLAuth() *graphql.Auth {
   384  	return &graphql.Auth{
   385  		Credential: &graphql.BasicCredentialData{
   386  			Username: "foo",
   387  			Password: "bar",
   388  		},
   389  		AdditionalHeaders:     graphql.HTTPHeaders{"test": {"foo", "bar"}},
   390  		AdditionalQueryParams: graphql.QueryParams{"test": {"foo", "bar"}},
   391  		RequestAuth: &graphql.CredentialRequestAuth{
   392  			Csrf: &graphql.CSRFTokenCredentialRequestAuth{
   393  				TokenEndpointURL: "foo.url",
   394  				Credential: &graphql.BasicCredentialData{
   395  					Username: "boo",
   396  					Password: "far",
   397  				},
   398  				AdditionalHeaders:     graphql.HTTPHeaders{"test": {"foo", "bar"}},
   399  				AdditionalQueryParams: graphql.QueryParams{"test": {"foo", "bar"}},
   400  			},
   401  		},
   402  	}
   403  }
   404  
   405  func fixEntityBundleWithAppID(id, name, desc string) *bundle.Entity {
   406  	entity := fixEntityBundle(id, name, desc)
   407  	entity.ApplicationID = repo.NewValidNullableString(appID)
   408  	return entity
   409  }
   410  
   411  func fixEntityBundleWithAppTemplateVersionID(id, name, desc string) *bundle.Entity {
   412  	entity := fixEntityBundle(id, name, desc)
   413  	entity.ApplicationTemplateVersionID = repo.NewValidNullableString(appTemplateVersionID)
   414  	return entity
   415  }
   416  
   417  func fixEntityBundle(id, name, desc string) *bundle.Entity {
   418  	descSQL := sql.NullString{String: desc, Valid: true}
   419  	schemaSQL := sql.NullString{
   420  		String: inputSchemaString(),
   421  		Valid:  true,
   422  	}
   423  	authSQL := sql.NullString{
   424  		String: `{"Credential":{"Basic":{"Username":"foo","Password":"bar"},"Oauth":null,"CertificateOAuth":null},"AccessStrategy":null,"AdditionalHeaders":{"test":["foo","bar"]},"AdditionalQueryParams":{"test":["foo","bar"]},"RequestAuth":{"Csrf":{"TokenEndpointURL":"foo.url","Credential":{"Basic":{"Username":"boo","Password":"far"},"Oauth":null,"CertificateOAuth":null},"AdditionalHeaders":{"test":["foo","bar"]},"AdditionalQueryParams":{"test":["foo","bar"]}}},"OneTimeToken":null,"CertCommonName":""}`,
   425  		Valid:  true,
   426  	}
   427  
   428  	return &bundle.Entity{
   429  		Name:                          name,
   430  		Description:                   descSQL,
   431  		Version:                       repo.NewValidNullableString(version),
   432  		InstanceAuthRequestJSONSchema: schemaSQL,
   433  		DefaultInstanceAuth:           authSQL,
   434  		OrdID:                         repo.NewValidNullableString(ordID),
   435  		LocalTenantID:                 repo.NewValidNullableString(localTenantID),
   436  		ShortDescription:              repo.NewValidNullableString("short_description"),
   437  		Links:                         repo.NewValidNullableString("[]"),
   438  		Labels:                        repo.NewValidNullableString("[]"),
   439  		CredentialExchangeStrategies:  repo.NewValidNullableString("[]"),
   440  		CorrelationIDs:                repo.NewValidNullableString(correlationIDs),
   441  		Tags:                          repo.NewValidNullableString("[]"),
   442  		ResourceHash:                  repo.NewValidNullableString(resourceHash),
   443  		DocumentationLabels:           repo.NewValidNullableString("[]"),
   444  		BaseEntity: &repo.BaseEntity{
   445  			ID:        id,
   446  			Ready:     true,
   447  			Error:     sql.NullString{},
   448  			CreatedAt: &fixedTimestamp,
   449  			UpdatedAt: &time.Time{},
   450  			DeletedAt: &time.Time{},
   451  		},
   452  	}
   453  }
   454  
   455  func fixBundleColumns() []string {
   456  	return []string{"id", "app_id", "app_template_version_id", "name", "description", "version", "instance_auth_request_json_schema", "default_instance_auth", "ord_id", "local_tenant_id", "short_description", "links", "labels", "credential_exchange_strategies", "ready", "created_at", "updated_at", "deleted_at", "error", "correlation_ids", "tags", "resource_hash", "documentation_labels"}
   457  }
   458  
   459  func fixBundleRowWithAppID(id string) []driver.Value {
   460  	return []driver.Value{id, appID, repo.NewValidNullableString(""), "foo", "bar", version, fixSchema(), fixDefaultAuth(), ordID, localTenantID, str.Ptr("short_description"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), true, fixedTimestamp, time.Time{}, time.Time{}, nil, repo.NewValidNullableString(correlationIDs), repo.NewValidNullableString("[]"), repo.NewValidNullableString(resourceHash), repo.NewValidNullableString("[]")}
   461  }
   462  
   463  func fixBundleRowWithAppTemplateVersionID(id string) []driver.Value {
   464  	return []driver.Value{id, repo.NewValidNullableString(""), appTemplateVersionID, "foo", "bar", version, fixSchema(), fixDefaultAuth(), ordID, localTenantID, str.Ptr("short_description"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), true, fixedTimestamp, time.Time{}, time.Time{}, nil, repo.NewValidNullableString(correlationIDs), repo.NewValidNullableString("[]"), repo.NewValidNullableString(resourceHash), repo.NewValidNullableString("[]")}
   465  }
   466  
   467  func fixBundleRowWithCustomAppID(id, applicationID string) []driver.Value {
   468  	return []driver.Value{id, applicationID, repo.NewValidNullableString(""), "foo", "bar", version, fixSchema(), fixDefaultAuth(), ordID, localTenantID, str.Ptr("short_description"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), repo.NewValidNullableString("[]"), true, fixedTimestamp, time.Time{}, time.Time{}, nil, repo.NewValidNullableString(correlationIDs), repo.NewValidNullableString("[]"), repo.NewValidNullableString(resourceHash), repo.NewValidNullableString("[]")}
   469  }
   470  
   471  func fixBundleCreateArgsForApp(defAuth, schema string, bndl *model.Bundle) []driver.Value {
   472  	return []driver.Value{bundleID, appID, repo.NewValidNullableString(""), bndl.Name, bndl.Description, bndl.Version, schema, defAuth, ordID, bndl.LocalTenantID, bndl.ShortDescription, repo.NewNullableStringFromJSONRawMessage(bndl.Links), repo.NewNullableStringFromJSONRawMessage(bndl.Labels), repo.NewNullableStringFromJSONRawMessage(bndl.CredentialExchangeStrategies), bndl.Ready, bndl.CreatedAt, bndl.UpdatedAt, bndl.DeletedAt, bndl.Error, repo.NewNullableStringFromJSONRawMessage(bndl.CorrelationIDs), repo.NewNullableStringFromJSONRawMessage(bndl.Tags), bndl.ResourceHash, repo.NewNullableStringFromJSONRawMessage(bndl.DocumentationLabels)}
   473  }
   474  
   475  func fixBundleCreateArgsForAppTemplateVersion(defAuth, schema string, bndl *model.Bundle) []driver.Value {
   476  	return []driver.Value{bundleID, repo.NewValidNullableString(""), appTemplateVersionID, bndl.Name, bndl.Description, bndl.Version, schema, defAuth, ordID, bndl.LocalTenantID, bndl.ShortDescription, repo.NewNullableStringFromJSONRawMessage(bndl.Links), repo.NewNullableStringFromJSONRawMessage(bndl.Labels), repo.NewNullableStringFromJSONRawMessage(bndl.CredentialExchangeStrategies), bndl.Ready, bndl.CreatedAt, bndl.UpdatedAt, bndl.DeletedAt, bndl.Error, repo.NewNullableStringFromJSONRawMessage(bndl.CorrelationIDs), repo.NewNullableStringFromJSONRawMessage(bndl.Tags), bndl.ResourceHash, repo.NewNullableStringFromJSONRawMessage(bndl.DocumentationLabels)}
   477  }
   478  
   479  func fixDefaultAuth() string {
   480  	return `{"Credential":{"Basic":{"Username":"foo","Password":"bar"},"Oauth":null,"CertificateOAuth":null},"AccessStrategy":null,"AdditionalHeaders":{"test":["foo","bar"]},"AdditionalQueryParams":{"test":["foo","bar"]},"RequestAuth":{"Csrf":{"TokenEndpointURL":"foo.url","Credential":{"Basic":{"Username":"boo","Password":"far"},"Oauth":null,"CertificateOAuth":null},"AdditionalHeaders":{"test":["foo","bar"]},"AdditionalQueryParams":{"test":["foo","bar"]}}},"OneTimeToken":null,"CertCommonName":""}`
   481  }
   482  
   483  func inputSchemaString() string {
   484  	return `{"$id":"https://example.com/person.schema.json","$schema":"http://json-schema.org/draft-07/schema#","properties":{"age":{"description":"Age in years which must be equal to or greater than zero.","minimum":0,"type":"integer"},"firstName":{"description":"The person's first name.","type":"string"},"lastName":{"description":"The person's last name.","type":"string"}},"title":"Person","type":"object"}`
   485  }
   486  
   487  func fixBasicInputSchema() *graphql.JSONSchema {
   488  	sch := inputSchemaString()
   489  	jsonSchema := graphql.JSONSchema(sch)
   490  	return &jsonSchema
   491  }
   492  
   493  func fixBasicSchema() *string {
   494  	sch := inputSchemaString()
   495  	return &sch
   496  }
   497  
   498  func fixSchema() string {
   499  	return `{"$id":"https://example.com/person.schema.json","$schema":"http://json-schema.org/draft-07/schema#","properties":{"age":{"description":"Age in years which must be equal to or greater than zero.","minimum":0,"type":"integer"},"firstName":{"description":"The person's first name.","type":"string"},"lastName":{"description":"The person's last name.","type":"string"}},"title":"Person","type":"object"}`
   500  }
   501  
   502  func fixModelBundleInstanceAuth(id string) *model.BundleInstanceAuth {
   503  	status := model.BundleInstanceAuthStatus{
   504  		Condition: model.BundleInstanceAuthStatusConditionPending,
   505  		Timestamp: time.Time{},
   506  		Message:   "test-message",
   507  		Reason:    "test-reason",
   508  	}
   509  
   510  	context := "ctx"
   511  	params := "test-param"
   512  	return &model.BundleInstanceAuth{
   513  		ID:          id,
   514  		BundleID:    bundleID,
   515  		Context:     &context,
   516  		InputParams: &params,
   517  		Auth:        fixModelAuth(),
   518  		Status:      &status,
   519  	}
   520  }
   521  
   522  func fixGQLBundleInstanceAuth(id string) *graphql.BundleInstanceAuth {
   523  	msg := "test-message"
   524  	reason := "test-reason"
   525  	status := graphql.BundleInstanceAuthStatus{
   526  		Condition: graphql.BundleInstanceAuthStatusConditionPending,
   527  		Timestamp: graphql.Timestamp{},
   528  		Message:   msg,
   529  		Reason:    reason,
   530  	}
   531  
   532  	params := graphql.JSON("test-param")
   533  	ctx := graphql.JSON("ctx")
   534  	return &graphql.BundleInstanceAuth{
   535  		ID:          id,
   536  		Context:     &ctx,
   537  		InputParams: &params,
   538  		Auth:        fixGQLAuth(),
   539  		Status:      &status,
   540  	}
   541  }
   542  
   543  func fixModelAPIBundleReference(bundleID, apiID string) *model.BundleReference {
   544  	return &model.BundleReference{
   545  		BundleID:            str.Ptr(bundleID),
   546  		ObjectType:          model.BundleAPIReference,
   547  		ObjectID:            str.Ptr(apiID),
   548  		APIDefaultTargetURL: str.Ptr(fmt.Sprintf("https://%s.com", apiID)),
   549  	}
   550  }
   551  
   552  func fixModelEventBundleReference(bundleID, eventID string) *model.BundleReference {
   553  	return &model.BundleReference{
   554  		BundleID:   str.Ptr(bundleID),
   555  		ObjectType: model.BundleEventReference,
   556  		ObjectID:   str.Ptr(eventID),
   557  	}
   558  }
   559  
   560  func fixBasicModelBundle(id, name string) *model.Bundle {
   561  	return &model.Bundle{
   562  		Name:                           name,
   563  		Description:                    &desc,
   564  		InstanceAuthRequestInputSchema: fixBasicSchema(),
   565  		DefaultInstanceAuth:            &model.Auth{},
   566  		BaseEntity: &model.BaseEntity{
   567  			ID:    id,
   568  			Ready: true,
   569  		},
   570  	}
   571  }
   572  
   573  func timeToTimestampPtr(time time.Time) *graphql.Timestamp {
   574  	t := graphql.Timestamp(time)
   575  	return &t
   576  }