-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
007d36c
commit bb32977
Showing
5 changed files
with
80 additions
and
1,686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ describe("SaleorOrderConfirmedEvent", () => { | |
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
const result = SaleorOrderConfirmedEvent.createFromGraphQL({ | ||
...payload, | ||
// @ts-expect-error testing | ||
order: null, | ||
}); | ||
|
||
|
@@ -38,13 +37,10 @@ describe("SaleorOrderConfirmedEvent", () => { | |
|
||
it("should return false if order has other status than FULLFILLED", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
const event = SaleorOrderConfirmedEvent.createFromGraphQL({ | ||
...payload, | ||
order: { | ||
...payload.order, | ||
status: "CANCELED", | ||
}, | ||
})._unsafeUnwrap(); | ||
|
||
payload.order!.status = "CANCELED"; | ||
|
||
const event = SaleorOrderConfirmedEvent.createFromGraphQL(payload)._unsafeUnwrap(); | ||
|
||
expect(event.isFulfilled()).toBe(false); | ||
}); | ||
|
@@ -60,20 +56,17 @@ describe("SaleorOrderConfirmedEvent", () => { | |
|
||
it("should return true if order has tax calculation strategy set to FLAT_RATES", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
const event = SaleorOrderConfirmedEvent.createFromGraphQL({ | ||
...payload, | ||
order: { | ||
...payload.order, | ||
channel: { | ||
slug: "channel-slug", | ||
id: "channel-id", | ||
taxConfiguration: { | ||
pricesEnteredWithTax: true, | ||
taxCalculationStrategy: "FLAT_RATES", | ||
}, | ||
}, | ||
|
||
payload.order!.channel = { | ||
slug: "channel-slug", | ||
id: "channel-id", | ||
taxConfiguration: { | ||
pricesEnteredWithTax: true, | ||
taxCalculationStrategy: "FLAT_RATES", | ||
}, | ||
})._unsafeUnwrap(); | ||
}; | ||
|
||
const event = SaleorOrderConfirmedEvent.createFromGraphQL(payload)._unsafeUnwrap(); | ||
|
||
expect(event.isStrategyFlatRates()).toBe(true); | ||
}); | ||
|
@@ -82,20 +75,17 @@ describe("SaleorOrderConfirmedEvent", () => { | |
describe("hasShipping method", () => { | ||
it("should return false if order has shippingPrice net set to 0", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
const event = SaleorOrderConfirmedEvent.createFromGraphQL({ | ||
...payload, | ||
order: { | ||
...payload.order, | ||
shippingPrice: { | ||
gross: { | ||
amount: 10, | ||
}, | ||
net: { | ||
amount: 0, | ||
}, | ||
}, | ||
|
||
payload.order!.shippingPrice = { | ||
gross: { | ||
amount: 10, | ||
}, | ||
})._unsafeUnwrap(); | ||
net: { | ||
amount: 0, | ||
}, | ||
}; | ||
|
||
const event = SaleorOrderConfirmedEvent.createFromGraphQL(payload)._unsafeUnwrap(); | ||
|
||
expect(event.hasShipping()).toEqual(false); | ||
}); | ||
|
@@ -113,40 +103,38 @@ describe("SaleorOrderConfirmedEvent", () => { | |
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
const event = SaleorOrderConfirmedEvent.createFromGraphQL(payload)._unsafeUnwrap(); | ||
|
||
expect(event.getShippingAmount()).toEqual(payload.order.shippingPrice.gross.amount); | ||
expect(event.getShippingAmount()).toEqual(payload.order!.shippingPrice.gross.amount); | ||
}); | ||
|
||
it("should get shipping amount as shippingPrice net without tax included", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
const event = SaleorOrderConfirmedEvent.createFromGraphQL({ | ||
...payload, | ||
order: { | ||
...payload.order, | ||
channel: { | ||
slug: "channel-slug", | ||
id: "channel-id", | ||
taxConfiguration: { | ||
pricesEnteredWithTax: false, | ||
taxCalculationStrategy: "FLAT_RATES", | ||
}, | ||
}, | ||
|
||
payload.order!.channel = { | ||
slug: "channel-slug", | ||
id: "channel-id", | ||
taxConfiguration: { | ||
pricesEnteredWithTax: false, | ||
taxCalculationStrategy: "FLAT_RATES", | ||
}, | ||
})._unsafeUnwrap(); | ||
}; | ||
|
||
const event = SaleorOrderConfirmedEvent.createFromGraphQL(payload)._unsafeUnwrap(); | ||
|
||
expect(event.getShippingAmount()).toEqual(payload.order.shippingPrice.net.amount); | ||
expect(event.getShippingAmount()).toEqual(payload.order!.shippingPrice.net.amount); | ||
}); | ||
}); | ||
|
||
describe("resolveUserEmailOrEmpty", () => { | ||
it("Returns order.user.email if exists", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
|
||
payload.order.user = { | ||
payload.order!.user = { | ||
email: "[email protected]", | ||
id: "1", | ||
avataxCustomerCode: null, | ||
}; | ||
|
||
payload.order.userEmail = "[email protected]"; | ||
payload.order!.userEmail = "[email protected]"; | ||
|
||
const result = SaleorOrderConfirmedEvent.createFromGraphQL(payload); | ||
|
||
|
@@ -156,9 +144,9 @@ describe("SaleorOrderConfirmedEvent", () => { | |
it("Returns order.userEmail.email if exists and user.email doesnt", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
|
||
payload.order.user = undefined; | ||
payload.order!.user = null; | ||
|
||
payload.order.userEmail = "[email protected]"; | ||
payload.order!.userEmail = "[email protected]"; | ||
|
||
const result = SaleorOrderConfirmedEvent.createFromGraphQL(payload); | ||
|
||
|
@@ -168,8 +156,8 @@ describe("SaleorOrderConfirmedEvent", () => { | |
it("Returns empty string if neither user.email or userEmail exist", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
|
||
payload.order.user = null; | ||
payload.order.userEmail = null; | ||
payload.order!.user = null; | ||
payload.order!.userEmail = null; | ||
|
||
const result = SaleorOrderConfirmedEvent.createFromGraphQL(payload); | ||
|
||
|
@@ -180,7 +168,7 @@ describe("SaleorOrderConfirmedEvent", () => { | |
describe("Resolving addresses", () => { | ||
const payload = SaleorOrderConfirmedEventMockFactory.getGraphqlPayload(); | ||
|
||
payload.order.shippingAddress = { | ||
payload.order!.shippingAddress = { | ||
streetAddress2: "streetAddress2-shipping", | ||
city: "city-shipping", | ||
postalCode: "postalCode-shipping", | ||
|
@@ -191,7 +179,7 @@ describe("SaleorOrderConfirmedEvent", () => { | |
streetAddress1: "streetAddress1-shipping", | ||
}; | ||
|
||
payload.order.billingAddress = { | ||
payload.order!.billingAddress = { | ||
streetAddress2: "streetAddress2-billing", | ||
city: "city-billing", | ||
postalCode: "postalCode-billing", | ||
|
@@ -205,11 +193,11 @@ describe("SaleorOrderConfirmedEvent", () => { | |
const event = SaleorOrderConfirmedEvent.createFromGraphQL(payload)._unsafeUnwrap(); | ||
|
||
it("Returns shipping address", () => { | ||
expect(event.getOrderShippingAddress()).toEqual(payload.order.shippingAddress); | ||
expect(event.getOrderShippingAddress()).toEqual(payload.order!.shippingAddress); | ||
}); | ||
|
||
it("Returns billing address", () => { | ||
expect(event.getOrderBillingAddress()).toEqual(payload.order.billingAddress); | ||
expect(event.getOrderBillingAddress()).toEqual(payload.order!.billingAddress); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.