flamingo.me/flamingo-commerce/v3@v3.11.0/cart/domain/testutils/utils.go (about)

     1  package testutils
     2  
     3  import (
     4  	"testing"
     5  
     6  	"flamingo.me/flamingo-commerce/v3/cart/domain/cart"
     7  	"flamingo.me/flamingo-commerce/v3/price/domain"
     8  )
     9  
    10  // BuildItemWithDiscounts helper for item building
    11  func BuildItemWithDiscounts(t *testing.T) *cart.Item {
    12  	t.Helper()
    13  	item := cart.Item{ID: "id-1",
    14  		AppliedDiscounts: []cart.AppliedDiscount{
    15  			{
    16  				CampaignCode: "code-1",
    17  				Label:        "title-1",
    18  				Type:         "type-1",
    19  				Applied:      domain.NewFromFloat(-10.0, "$"),
    20  				SortOrder:    3,
    21  			},
    22  			{
    23  				CampaignCode: "code-2",
    24  				Label:        "title-2",
    25  				Type:         "type-1",
    26  				Applied:      domain.NewFromFloat(-15.0, "$"),
    27  				SortOrder:    2,
    28  			},
    29  			{
    30  				CampaignCode: "code-3",
    31  				Label:        "title-1",
    32  				Type:         "type-2",
    33  				Applied:      domain.NewFromFloat(-5.0, "$"),
    34  				SortOrder:    4,
    35  			},
    36  		},
    37  	}
    38  
    39  	// todo: add discount total
    40  
    41  	return &item
    42  }
    43  
    44  // BuildItemWithAlternativeDiscounts helper for item building with different discounts
    45  func BuildItemWithAlternativeDiscounts(t *testing.T) *cart.Item {
    46  	t.Helper()
    47  	item := cart.Item{
    48  		ID: "id-2",
    49  		AppliedDiscounts: []cart.AppliedDiscount{
    50  			cart.AppliedDiscount{
    51  				CampaignCode: "code-4",
    52  				Label:        "title-4",
    53  				Type:         "type-1",
    54  				Applied:      domain.NewFromFloat(-10.0, "$"),
    55  				SortOrder:    5,
    56  			},
    57  			cart.AppliedDiscount{
    58  				CampaignCode: "code-5",
    59  				Label:        "title-5",
    60  				Type:         "type-1",
    61  				Applied:      domain.NewFromFloat(-15.0, "$"),
    62  				SortOrder:    0,
    63  			},
    64  			cart.AppliedDiscount{
    65  				CampaignCode: "code-6",
    66  				Label:        "title-6",
    67  				Type:         "type-2",
    68  				Applied:      domain.NewFromFloat(-5.0, "$"),
    69  				SortOrder:    1,
    70  			},
    71  		},
    72  	} // todo: add discount total
    73  
    74  	return &item
    75  }
    76  
    77  // BuildItemWithDuplicateDiscounts helper for item building with duplicate discounts
    78  func BuildItemWithDuplicateDiscounts(t *testing.T) *cart.Item {
    79  	t.Helper()
    80  
    81  	item := cart.Item{
    82  		ID: "id-1",
    83  		AppliedDiscounts: []cart.AppliedDiscount{
    84  			cart.AppliedDiscount{
    85  				CampaignCode: "code-1",
    86  				Label:        "title-1",
    87  				Type:         "type-1",
    88  				Applied:      domain.NewFromFloat(-10.0, "$"),
    89  				SortOrder:    0,
    90  			},
    91  			cart.AppliedDiscount{
    92  				CampaignCode: "code-1",
    93  				Label:        "title-1",
    94  				Type:         "type-1",
    95  				Applied:      domain.NewFromFloat(-10.0, "$"),
    96  				SortOrder:    0,
    97  			},
    98  		},
    99  	} // todo: add discount total
   100  
   101  	return &item
   102  }
   103  
   104  // BuildShippingItemWithDiscounts helper for shipping item building
   105  func BuildShippingItemWithDiscounts(t *testing.T) *cart.ShippingItem {
   106  	t.Helper()
   107  	return &cart.ShippingItem{
   108  		Title:      "",
   109  		PriceNet:   domain.NewFromFloat(20.0, "$"),
   110  		TaxAmount:  domain.NewFromFloat(2.0, "$"),
   111  		PriceGross: domain.NewFromFloat(22.0, "$"),
   112  		AppliedDiscounts: cart.AppliedDiscounts{
   113  			cart.AppliedDiscount{
   114  				CampaignCode: "code-1",
   115  				Label:        "title-1",
   116  				Type:         "type-1",
   117  				Applied:      domain.NewFromFloat(-10.0, "$"),
   118  				SortOrder:    3,
   119  			},
   120  			cart.AppliedDiscount{
   121  				CampaignCode: "code-2",
   122  				Label:        "title-2",
   123  				Type:         "type-1",
   124  				Applied:      domain.NewFromFloat(-5.0, "$"),
   125  				SortOrder:    2,
   126  			},
   127  		},
   128  	}
   129  }
   130  
   131  // BuildShippingItemWithAlternativeDiscounts helper for shipping item building with different discounts
   132  func BuildShippingItemWithAlternativeDiscounts(t *testing.T) *cart.ShippingItem {
   133  	t.Helper()
   134  	return &cart.ShippingItem{
   135  		Title:      "",
   136  		PriceNet:   domain.NewFromFloat(30.0, "$"),
   137  		TaxAmount:  domain.NewFromFloat(2.0, "$"),
   138  		PriceGross: domain.NewFromFloat(32.0, "$"),
   139  		AppliedDiscounts: cart.AppliedDiscounts{
   140  			cart.AppliedDiscount{
   141  				CampaignCode: "code-3",
   142  				Label:        "title-1",
   143  				Type:         "type-2",
   144  				Applied:      domain.NewFromFloat(-5.0, "$"),
   145  				SortOrder:    4,
   146  			},
   147  			cart.AppliedDiscount{
   148  				CampaignCode: "code-4",
   149  				Label:        "title-4",
   150  				Type:         "type-1",
   151  				Applied:      domain.NewFromFloat(-20.0, "$"),
   152  				SortOrder:    5,
   153  			},
   154  		},
   155  	}
   156  }
   157  
   158  // BuildShippingItemWithDuplicateDiscounts helper for shipping item building with duplicate discounts
   159  func BuildShippingItemWithDuplicateDiscounts(t *testing.T) *cart.ShippingItem {
   160  	t.Helper()
   161  	return &cart.ShippingItem{
   162  		Title:      "",
   163  		PriceNet:   domain.NewFromFloat(40.0, "$"),
   164  		TaxAmount:  domain.NewFromFloat(2.0, "$"),
   165  		PriceGross: domain.NewFromFloat(42.0, "$"),
   166  		AppliedDiscounts: cart.AppliedDiscounts{
   167  			cart.AppliedDiscount{
   168  				CampaignCode: "code-1",
   169  				Label:        "title-1",
   170  				Type:         "type-1",
   171  				Applied:      domain.NewFromFloat(-15.0, "$"),
   172  				SortOrder:    0,
   173  			},
   174  			cart.AppliedDiscount{
   175  				CampaignCode: "code-1",
   176  				Label:        "title-1",
   177  				Type:         "type-1",
   178  				Applied:      domain.NewFromFloat(-15.0, "$"),
   179  				SortOrder:    0,
   180  			},
   181  		},
   182  	}
   183  }
   184  
   185  // BuildDeliveryWithDiscounts helper for delivery building
   186  // Adds an item with discount twice
   187  // This means when discounts are summed up (based on type + delivery)
   188  // The amount should be added to the previous discount
   189  func BuildDeliveryWithDiscounts(t *testing.T) *cart.Delivery {
   190  	t.Helper()
   191  	delivery := &cart.Delivery{
   192  		DeliveryInfo: cart.DeliveryInfo{Code: "code"},
   193  		Cartitems:    []cart.Item{*BuildItemWithDiscounts(t), *BuildItemWithDiscounts(t)},
   194  	}
   195  	return delivery
   196  }
   197  
   198  // BuildAlternativeDeliveryWithAlternativeDiscounts helper for delivery building
   199  // Adds an item with alternative discount twice
   200  // This means when discounts are summed up (based on type + delivery)
   201  // The amount should be added to the previous discount
   202  func BuildAlternativeDeliveryWithAlternativeDiscounts(t *testing.T) *cart.Delivery {
   203  	t.Helper()
   204  	delivery := &cart.Delivery{
   205  		DeliveryInfo: cart.DeliveryInfo{Code: "code-2"},
   206  		Cartitems:    []cart.Item{*BuildItemWithAlternativeDiscounts(t), *BuildItemWithAlternativeDiscounts(t)},
   207  	}
   208  	return delivery
   209  }
   210  
   211  // BuildDeliveryWithDifferentDiscounts helper for delivery building
   212  // Adds an item with alternative discount twice
   213  // This means when discounts are summed up (based on type + delivery)
   214  // The amount should be added to the previous discount
   215  func BuildDeliveryWithDifferentDiscounts(t *testing.T) *cart.Delivery {
   216  	t.Helper()
   217  	delivery := &cart.Delivery{
   218  		DeliveryInfo: cart.DeliveryInfo{Code: "code-1"},
   219  		Cartitems:    []cart.Item{*BuildItemWithDiscounts(t), *BuildItemWithAlternativeDiscounts(t)},
   220  	}
   221  	return delivery
   222  }
   223  
   224  // BuildDeliveryWithDuplicateDiscounts helper for delivery building
   225  // Adds an item with alternative discount twice
   226  // This means when discounts are summed up (based on type + delivery)
   227  // The amount should be added to the previous discount
   228  func BuildDeliveryWithDuplicateDiscounts(t *testing.T) *cart.Delivery {
   229  	t.Helper()
   230  	delivery := &cart.Delivery{
   231  		DeliveryInfo: cart.DeliveryInfo{Code: "code-1"},
   232  		Cartitems:    []cart.Item{*BuildItemWithDuplicateDiscounts(t)},
   233  	}
   234  	return delivery
   235  }
   236  
   237  // BuildDeliveryWithoutDiscounts helper for delivery building
   238  func BuildDeliveryWithoutDiscounts(t *testing.T) *cart.Delivery {
   239  	t.Helper()
   240  	delivery := &cart.Delivery{
   241  		DeliveryInfo: cart.DeliveryInfo{Code: "code"},
   242  		Cartitems:    []cart.Item{{}, {}},
   243  	}
   244  	return delivery
   245  }
   246  
   247  // BuildDeliveryWithoutDiscountsAndShippingDiscounts helper for delivery building
   248  func BuildDeliveryWithoutDiscountsAndShippingDiscounts(t *testing.T) *cart.Delivery {
   249  	t.Helper()
   250  
   251  	delivery := &cart.Delivery{
   252  		DeliveryInfo: cart.DeliveryInfo{Code: "code"},
   253  		Cartitems:    []cart.Item{{}, {}},
   254  		ShippingItem: *BuildShippingItemWithDiscounts(t),
   255  	}
   256  
   257  	return delivery
   258  }
   259  
   260  // BuildDeliveryWithDifferentDiscountsAndShippingDiscounts helper for delivery building
   261  // Adds an item with alternative discount twice
   262  // Adds a shipping item with discounts
   263  // This means when discounts are summed up (based on type + delivery)
   264  // The amount should be added to the previous discount
   265  func BuildDeliveryWithDifferentDiscountsAndShippingDiscounts(t *testing.T) *cart.Delivery {
   266  	t.Helper()
   267  	delivery := &cart.Delivery{
   268  		DeliveryInfo: cart.DeliveryInfo{Code: "code-1"},
   269  		Cartitems:    []cart.Item{*BuildItemWithDiscounts(t), *BuildItemWithAlternativeDiscounts(t)},
   270  		ShippingItem: *BuildShippingItemWithDiscounts(t),
   271  	}
   272  
   273  	return delivery
   274  }
   275  
   276  // BuildDeliveryWithDuplicateDiscountsAndShippingDiscounts helper for delivery building
   277  // Adds an item with duplicate discounts
   278  // Adds a shipping item with discounts
   279  // This means when discounts are summed up (based on type + delivery)
   280  // The amount should be added to the previous discount
   281  func BuildDeliveryWithDuplicateDiscountsAndShippingDiscounts(t *testing.T) *cart.Delivery {
   282  	t.Helper()
   283  	delivery := &cart.Delivery{
   284  		DeliveryInfo: cart.DeliveryInfo{Code: "code-1"},
   285  		Cartitems:    []cart.Item{*BuildItemWithDuplicateDiscounts(t)},
   286  		ShippingItem: *BuildShippingItemWithDiscounts(t),
   287  	}
   288  
   289  	return delivery
   290  }