Skip to content

Commit d63bae5

Browse files
authored
Merge pull request #172 from commercetools/Fix-CartDiscount-FixedType-Issue
Adding FixedCartDiscountValue
2 parents bf1fdf1 + 1f67755 commit d63bae5

File tree

2 files changed

+66
-20
lines changed

2 files changed

+66
-20
lines changed

commercetools.Sdk/IntegrationTests/commercetools.Sdk.IntegrationTests/CartDiscounts/CartDiscountIntegrationTests.cs

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ await WithCartDiscount(
3232
cartDiscount => { Assert.Equal(key, (string) cartDiscount.Key); });
3333
}
3434

35+
[Fact]
36+
public async Task CreateCartDiscountWithFixedValue()
37+
{
38+
var key = $"CreateCartDiscount-{TestingUtility.RandomString()}";
39+
await WithCartDiscount(
40+
client,
41+
cartDiscountDraft =>
42+
{
43+
var draft = DefaultCartDiscountDraftWithKey(cartDiscountDraft, key);
44+
draft.Value = new FixedCartDiscountValue
45+
{
46+
Money = new List<Money>
47+
{
48+
new Money {CurrencyCode = "EUR", CentAmount = TestingUtility.RandomInt(100, 1000)}
49+
}
50+
};
51+
return draft;
52+
},
53+
cartDiscount =>
54+
{
55+
Assert.Equal(key, (string) cartDiscount.Key);
56+
Assert.Equal("fixed", cartDiscount.Value.Type);
57+
});
58+
}
59+
3560

3661
[Fact]
3762
public async Task GetCartDiscountById()
@@ -60,16 +85,20 @@ await WithCartDiscount(
6085
Assert.Equal(key, retrievedCartDiscount.Key);
6186
});
6287
}
63-
88+
6489
[Fact]
6590
public async Task GetMultiBuyLineItemCartDiscount()
6691
{
6792
await WithCartDiscount(
6893
client, cartDiscountDraft =>
6994
{
7095
var draft = DefaultCartDiscountDraft(cartDiscountDraft);
71-
draft.Value = new RelativeCartDiscountValue { Permyriad = 10000 };
72-
draft.Target = new MultiBuyLineItemTarget { Predicate = "1 = 1", TriggerQuantity = 2, MaxOccurrence = 1, DiscountedQuantity = 1, SelectionMode = SelectionMode.Cheapest};
96+
draft.Value = new RelativeCartDiscountValue {Permyriad = 10000};
97+
draft.Target = new MultiBuyLineItemTarget
98+
{
99+
Predicate = "1 = 1", TriggerQuantity = 2, MaxOccurrence = 1, DiscountedQuantity = 1,
100+
SelectionMode = SelectionMode.Cheapest
101+
};
73102
return draft;
74103
},
75104
async cartDiscount =>
@@ -87,8 +116,12 @@ await WithCartDiscount(
87116
client, cartDiscountDraft =>
88117
{
89118
var draft = DefaultCartDiscountDraft(cartDiscountDraft);
90-
draft.Value = new RelativeCartDiscountValue { Permyriad = 10000 };
91-
draft.Target = new MultiBuyCustomLineItemTarget { Predicate = "1 = 1", TriggerQuantity = 2, MaxOccurrence = 1, DiscountedQuantity = 1, SelectionMode = SelectionMode.Cheapest};
119+
draft.Value = new RelativeCartDiscountValue {Permyriad = 10000};
120+
draft.Target = new MultiBuyCustomLineItemTarget
121+
{
122+
Predicate = "1 = 1", TriggerQuantity = 2, MaxOccurrence = 1, DiscountedQuantity = 1,
123+
SelectionMode = SelectionMode.Cheapest
124+
};
92125
return draft;
93126
},
94127
async cartDiscount =>
@@ -98,7 +131,7 @@ await WithCartDiscount(
98131
Assert.IsType<MultiBuyCustomLineItemTarget>(retrievedCartDiscount.Target);
99132
});
100133
}
101-
134+
102135
[Fact]
103136
public async Task QueryCartDiscounts()
104137
{
@@ -155,7 +188,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
155188
{
156189
var updatedCartDiscount = await client
157190
.ExecuteAsync(cartDiscount.UpdateById(
158-
actions => actions.AddUpdate(new SetKeyUpdateAction() { Key = newKey })
191+
actions => actions.AddUpdate(new SetKeyUpdateAction() {Key = newKey})
159192
)
160193
);
161194

@@ -174,7 +207,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
174207
{
175208
var updatedCartDiscount = await client
176209
.ExecuteAsync(cartDiscount.UpdateByKey(actions =>
177-
actions.AddUpdate(new ChangeValueUpdateAction { Value = newAbsoluteValue })
210+
actions.AddUpdate(new ChangeValueUpdateAction {Value = newAbsoluteValue})
178211
)
179212
);
180213

@@ -213,7 +246,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
213246
[Fact]
214247
public async Task UpdateCartDiscountChangeTarget()
215248
{
216-
var newCartDiscountTarget = new LineItemsCartDiscountTarget() { Predicate = " 1 <> 1" };
249+
var newCartDiscountTarget = new LineItemsCartDiscountTarget() {Predicate = " 1 <> 1"};
217250
await WithUpdateableCartDiscount(client, async cartDiscount =>
218251
{
219252
var updateActions = new List<UpdateAction<CartDiscount>>();
@@ -241,7 +274,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
241274
{
242275
var newIsActive = !cartDiscount.IsActive;
243276
var updateActions = new List<UpdateAction<CartDiscount>>();
244-
var changeIsActiveAction = new ChangeIsActiveUpdateAction { IsActive = newIsActive };
277+
var changeIsActiveAction = new ChangeIsActiveUpdateAction {IsActive = newIsActive};
245278
updateActions.Add(changeIsActiveAction);
246279

247280
var updatedCartDiscount = await client
@@ -259,7 +292,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
259292
{
260293
var newName = new LocalizedString {{"en", TestingUtility.RandomString()}};
261294
var updateActions = new List<UpdateAction<CartDiscount>>();
262-
var action = new ChangeNameUpdateAction { Name = newName};
295+
var action = new ChangeNameUpdateAction {Name = newName};
263296
updateActions.Add(action);
264297

265298
var updatedCartDiscount = await client
@@ -277,7 +310,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
277310
{
278311
var newDescription = new LocalizedString {{"en", TestingUtility.RandomString()}};
279312
var updateActions = new List<UpdateAction<CartDiscount>>();
280-
var action = new SetDescriptionUpdateAction { Description = newDescription };
313+
var action = new SetDescriptionUpdateAction {Description = newDescription};
281314
updateActions.Add(action);
282315

283316
var updatedCartDiscount = await client
@@ -295,7 +328,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
295328
{
296329
var newSortOrder = TestingUtility.RandomSortOrder();
297330
var updateActions = new List<UpdateAction<CartDiscount>>();
298-
var action = new ChangeSortOrderUpdateAction { SortOrder = newSortOrder};
331+
var action = new ChangeSortOrderUpdateAction {SortOrder = newSortOrder};
299332
updateActions.Add(action);
300333

301334
var updatedCartDiscount = await client
@@ -313,7 +346,8 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
313346
{
314347
var newRequiresDiscountCode = !cartDiscount.RequiresDiscountCode;
315348
var updateActions = new List<UpdateAction<CartDiscount>>();
316-
var action = new ChangeRequiresDiscountCodeUpdateAction { RequiresDiscountCode = newRequiresDiscountCode};
349+
var action = new ChangeRequiresDiscountCodeUpdateAction
350+
{RequiresDiscountCode = newRequiresDiscountCode};
317351
updateActions.Add(action);
318352

319353
var updatedCartDiscount = await client
@@ -331,7 +365,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
331365
{
332366
var newValidFrom = cartDiscount.ValidFrom.AddDays(1);
333367
var updateActions = new List<UpdateAction<CartDiscount>>();
334-
var action = new SetValidFromUpdateAction { ValidFrom = newValidFrom };
368+
var action = new SetValidFromUpdateAction {ValidFrom = newValidFrom};
335369
updateActions.Add(action);
336370

337371
var updatedCartDiscount = await client
@@ -348,7 +382,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
348382
{
349383
var newValidUntil = cartDiscount.ValidUntil.AddDays(1);
350384
var updateActions = new List<UpdateAction<CartDiscount>>();
351-
var action = new SetValidUntilUpdateAction { ValidUntil = newValidUntil };
385+
var action = new SetValidUntilUpdateAction {ValidUntil = newValidUntil};
352386
updateActions.Add(action);
353387

354388
var updatedCartDiscount = await client
@@ -390,7 +424,7 @@ await WithUpdateableCartDiscount(client, async cartDiscount =>
390424
{
391425
var newStackingMode = StackingMode.StopAfterThisDiscount;
392426
var updateActions = new List<UpdateAction<CartDiscount>>();
393-
var action = new ChangeStackingModeUpdateAction { StackingMode = newStackingMode};
427+
var action = new ChangeStackingModeUpdateAction {StackingMode = newStackingMode};
394428
updateActions.Add(action);
395429

396430
var updatedCartDiscount = await client
@@ -419,7 +453,8 @@ await WithUpdateableCartDiscount(client,
419453
};
420454
updateActions.Add(setTypeAction);
421455

422-
var updatedCartDiscount = await client.ExecuteAsync(new UpdateByIdCommand<CartDiscount>(cartDiscount, updateActions));
456+
var updatedCartDiscount =
457+
await client.ExecuteAsync(new UpdateByIdCommand<CartDiscount>(cartDiscount, updateActions));
423458

424459
Assert.Equal(type.Id, updatedCartDiscount.Custom.Type.Id);
425460
return updatedCartDiscount;
@@ -446,7 +481,8 @@ await WithUpdateableCartDiscount(client,
446481
};
447482
updateActions.Add(setCustomFieldUpdateAction);
448483

449-
var updatedCartDiscount = await client.ExecuteAsync(new UpdateByIdCommand<CartDiscount>(cartDiscount, updateActions));
484+
var updatedCartDiscount =
485+
await client.ExecuteAsync(new UpdateByIdCommand<CartDiscount>(cartDiscount, updateActions));
450486

451487
Assert.Equal(newValue, updatedCartDiscount.Custom.Fields["string-field"]);
452488
return updatedCartDiscount;
@@ -456,4 +492,4 @@ await WithUpdateableCartDiscount(client,
456492

457493
#endregion
458494
}
459-
}
495+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace commercetools.Sdk.Domain.CartDiscounts
4+
{
5+
[TypeMarker("fixed")]
6+
public class FixedCartDiscountValue : CartDiscountValue
7+
{
8+
public List<Money> Money { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)