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

     1  package product_test
     2  
     3  import (
     4  	"database/sql"
     5  	"database/sql/driver"
     6  	"encoding/json"
     7  
     8  	"github.com/kyma-incubator/compass/components/director/pkg/str"
     9  
    10  	"github.com/kyma-incubator/compass/components/director/internal/repo"
    11  
    12  	"github.com/kyma-incubator/compass/components/director/internal/domain/product"
    13  	"github.com/kyma-incubator/compass/components/director/internal/model"
    14  )
    15  
    16  const (
    17  	productID            = "productID"
    18  	tenantID             = "b91b59f7-2563-40b2-aba9-fef726037aa3"
    19  	appID                = "appID"
    20  	appTemplateVersionID = "appTemplateVersionID"
    21  	ordID                = "com.compass.v1"
    22  	externalTenantID     = "externalTenantID"
    23  	correlationIDs       = `["id1", "id2"]`
    24  )
    25  
    26  func fixNilModelProduct() *model.Product {
    27  	return nil
    28  }
    29  
    30  func fixEntityProduct() *product.Entity {
    31  	return fixEntityProductWithTitle("title")
    32  }
    33  
    34  func fixEntityProductWithTitle(title string) *product.Entity {
    35  	return &product.Entity{
    36  		ID:               productID,
    37  		OrdID:            ordID,
    38  		Title:            title,
    39  		ShortDescription: "short desc",
    40  		Vendor:           "vendorID",
    41  		Parent: sql.NullString{
    42  			String: "parent",
    43  			Valid:  true,
    44  		},
    45  		CorrelationIDs: sql.NullString{
    46  			String: correlationIDs,
    47  			Valid:  true,
    48  		},
    49  		Tags:                repo.NewValidNullableString("[]"),
    50  		Labels:              repo.NewValidNullableString("{}"),
    51  		DocumentationLabels: repo.NewValidNullableString("{}"),
    52  	}
    53  }
    54  
    55  func fixEntityProductForApp() *product.Entity {
    56  	entity := fixEntityProduct()
    57  	entity.ApplicationID = repo.NewValidNullableString(appID)
    58  	return entity
    59  }
    60  
    61  func fixEntityProductWithTitleForApp(title string) *product.Entity {
    62  	entity := fixEntityProductWithTitle(title)
    63  	entity.ApplicationID = repo.NewValidNullableString(appID)
    64  	return entity
    65  }
    66  
    67  func fixEntityProductWithTitleForAppTemplateVersion(title string) *product.Entity {
    68  	entity := fixEntityProductWithTitle(title)
    69  	entity.ApplicationTemplateVersionID = repo.NewValidNullableString(appTemplateVersionID)
    70  	return entity
    71  }
    72  
    73  func fixProductModelForApp() *model.Product {
    74  	return fixProductModelWithTitleForApp("title")
    75  }
    76  
    77  func fixProductModelForAppTemplateVersion() *model.Product {
    78  	return fixProductModelWithTitleForAppTemplateVersion("title")
    79  }
    80  
    81  func fixProductModelWithTitle(title string) *model.Product {
    82  	parent := "parent"
    83  	return &model.Product{
    84  		ID:                  productID,
    85  		OrdID:               ordID,
    86  		Title:               title,
    87  		ShortDescription:    "short desc",
    88  		Vendor:              "vendorID",
    89  		Parent:              &parent,
    90  		CorrelationIDs:      json.RawMessage(correlationIDs),
    91  		Tags:                json.RawMessage("[]"),
    92  		Labels:              json.RawMessage("{}"),
    93  		DocumentationLabels: json.RawMessage("{}"),
    94  	}
    95  }
    96  
    97  func fixProductModelWithTitleForApp(title string) *model.Product {
    98  	product := fixProductModelWithTitle(title)
    99  	product.ApplicationID = str.Ptr(appID)
   100  	return product
   101  }
   102  
   103  func fixProductModelWithTitleForAppTemplateVersion(title string) *model.Product {
   104  	product := fixProductModelWithTitle(title)
   105  	product.ApplicationTemplateVersionID = str.Ptr(appTemplateVersionID)
   106  	return product
   107  }
   108  
   109  func fixGlobalProductModel() *model.Product {
   110  	parent := "parent"
   111  	return &model.Product{
   112  		ID:                  productID,
   113  		OrdID:               ordID,
   114  		Title:               "title",
   115  		ShortDescription:    "short desc",
   116  		Vendor:              "vendorID",
   117  		Parent:              &parent,
   118  		CorrelationIDs:      json.RawMessage(correlationIDs),
   119  		Tags:                json.RawMessage("[]"),
   120  		Labels:              json.RawMessage("{}"),
   121  		DocumentationLabels: json.RawMessage("{}"),
   122  	}
   123  }
   124  
   125  func fixProductModelInput() *model.ProductInput {
   126  	parent := "parent"
   127  	return &model.ProductInput{
   128  		OrdID:               ordID,
   129  		Title:               "title",
   130  		ShortDescription:    "short desc",
   131  		Vendor:              "vendorID",
   132  		Parent:              &parent,
   133  		CorrelationIDs:      json.RawMessage(correlationIDs),
   134  		Tags:                json.RawMessage("[]"),
   135  		Labels:              json.RawMessage("{}"),
   136  		DocumentationLabels: json.RawMessage("{}"),
   137  	}
   138  }
   139  
   140  func fixProductColumns() []string {
   141  	return []string{"ord_id", "app_id", "app_template_version_id", "title", "short_description", "vendor", "parent", "labels", "correlation_ids", "id", "tags", "documentation_labels"}
   142  }
   143  
   144  func fixProductRow() []driver.Value {
   145  	return fixProductRowWithTitleForApp("title")
   146  }
   147  
   148  func fixProductRowWithTitleForApp(title string) []driver.Value {
   149  	return []driver.Value{ordID, appID, repo.NewValidNullableString(""), title, "short desc", "vendorID", "parent",
   150  		repo.NewValidNullableString("{}"), repo.NewValidNullableString(correlationIDs), productID, repo.NewValidNullableString("[]"), repo.NewValidNullableString("{}")}
   151  }
   152  
   153  func fixProductRowWithTitleForAppTemplateVersion(title string) []driver.Value {
   154  	return []driver.Value{ordID, repo.NewValidNullableString(""), appTemplateVersionID, title, "short desc", "vendorID", "parent",
   155  		repo.NewValidNullableString("{}"), repo.NewValidNullableString(correlationIDs), productID, repo.NewValidNullableString("[]"), repo.NewValidNullableString("{}")}
   156  }
   157  
   158  func fixProductUpdateArgs() []driver.Value {
   159  	return []driver.Value{"title", "short desc", "vendorID", "parent", repo.NewValidNullableString("{}"), repo.NewValidNullableString(correlationIDs), repo.NewValidNullableString("[]"), repo.NewValidNullableString("{}")}
   160  }