-
Notifications
You must be signed in to change notification settings - Fork 0
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
cef9f84
commit 2e49dcf
Showing
5 changed files
with
195 additions
and
41 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
69 changes: 69 additions & 0 deletions
69
processor/test/services/converters/helper.converter.spec.ts
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { describe, test, expect, afterEach, jest, beforeEach } from '@jest/globals'; | ||
import { | ||
convertPaymentMethodFromAdyenFormat, | ||
convertPaymentMethodToAdyenFormat, | ||
populateCartAddress, | ||
} from '../../../src/services/converters/helper.converter'; | ||
import { Address as AdyenAddress } from '@adyen/api-library/lib/src/typings/checkout/address'; | ||
import { Address } from '@commercetools/platform-sdk'; | ||
describe('helper.converter', () => { | ||
beforeEach(() => { | ||
jest.setTimeout(10000); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
test('convertPaymentMethodFromAdyenFormat', async () => { | ||
const paymentMethod1 = 'scheme'; | ||
const paymentMethod2 = 'klarna'; | ||
const result1: string = convertPaymentMethodFromAdyenFormat(paymentMethod1); | ||
const result2: string = convertPaymentMethodFromAdyenFormat(paymentMethod2); | ||
expect(result1).toStrictEqual('card'); | ||
expect(result2).toStrictEqual('klarna'); | ||
}); | ||
|
||
test('convertPaymentMethodToAdyenFormat', async () => { | ||
const paymentMethod1 = 'card'; | ||
const paymentMethod2 = 'klarna'; | ||
const result1: string = convertPaymentMethodToAdyenFormat(paymentMethod1); | ||
const result2: string = convertPaymentMethodToAdyenFormat(paymentMethod2); | ||
expect(result1).toStrictEqual('scheme'); | ||
expect(result2).toStrictEqual('klarna'); | ||
}); | ||
|
||
test('populateCartAddress', async () => { | ||
const address1: Address = { | ||
country: 'Germany', | ||
city: 'Munich', | ||
streetName: 'Adam-Lehmann-Straße', | ||
streetNumber: '44', | ||
state: 'Bavaria', | ||
postalCode: '80797', | ||
}; | ||
|
||
const result1: AdyenAddress = populateCartAddress(address1); | ||
|
||
expect(result1?.country).toStrictEqual('Germany'); | ||
expect(result1?.city).toStrictEqual('Munich'); | ||
expect(result1?.street).toStrictEqual('Adam-Lehmann-Straße'); | ||
expect(result1?.stateOrProvince).toStrictEqual('Bavaria'); | ||
expect(result1?.houseNumberOrName).toStrictEqual('44'); | ||
expect(result1?.postalCode).toStrictEqual('80797'); | ||
|
||
const address2: Address = { | ||
country: '', | ||
}; | ||
|
||
const result2: AdyenAddress = populateCartAddress(address2); | ||
|
||
expect(result2?.country).toStrictEqual(''); | ||
expect(result2?.city).toStrictEqual(''); | ||
expect(result2?.street).toStrictEqual(''); | ||
expect(result2?.stateOrProvince).toStrictEqual(undefined); | ||
expect(result2?.houseNumberOrName).toStrictEqual(''); | ||
expect(result2?.postalCode).toStrictEqual(''); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { LineItem, CustomLineItem, ShippingInfo } from '@commercetools/platform-sdk'; | ||
import { randomUUID } from 'crypto'; | ||
import { Cart } from '@commercetools/platform-sdk'; | ||
|
||
export const mockGetCartResult = () => { | ||
const cartId = randomUUID(); | ||
const mockGetCartResult: Cart = { | ||
id: cartId, | ||
version: 1, | ||
lineItems: [lineItem], | ||
customLineItems: [customLineItem], | ||
totalPrice: { | ||
type: 'centPrecision', | ||
currencyCode: 'USD', | ||
centAmount: 150000, | ||
fractionDigits: 2, | ||
}, | ||
cartState: 'Ordered', | ||
origin: 'Customer', | ||
taxMode: 'ExternalAmount', | ||
taxRoundingMode: 'HalfEven', | ||
taxCalculationMode: 'LineItemLevel', | ||
shipping: [], | ||
discountCodes: [], | ||
directDiscounts: [], | ||
refusedGifts: [], | ||
itemShippingAddresses: [], | ||
inventoryMode: 'ReserveOnOrder', | ||
shippingMode: 'Single', | ||
shippingInfo: shippingInfo, | ||
createdAt: '2024-01-01T00:00:00Z', | ||
lastModifiedAt: '2024-01-01T00:00:00Z', | ||
}; | ||
return mockGetCartResult; | ||
}; | ||
|
||
const lineItem: LineItem = { | ||
id: 'lineitem-id-1', | ||
productId: 'product-id-1', | ||
name: { | ||
en: 'lineitem-name-1', | ||
}, | ||
productType: { | ||
id: 'product-type-reference-1', | ||
typeId: 'product-type', | ||
}, | ||
price: { | ||
id: 'price-id-1', | ||
value: { | ||
type: 'centPrecision', | ||
currencyCode: 'USD', | ||
centAmount: 150000, | ||
fractionDigits: 2, | ||
}, | ||
}, | ||
quantity: 1, | ||
totalPrice: { | ||
type: 'centPrecision', | ||
currencyCode: 'USD', | ||
centAmount: 150000, | ||
fractionDigits: 2, | ||
}, | ||
discountedPricePerQuantity: [], | ||
taxedPricePortions: [], | ||
state: [], | ||
perMethodTaxRate: [], | ||
priceMode: 'Platform', | ||
lineItemMode: 'Standard', | ||
variant: { | ||
id: 1, | ||
sku: 'variant-sku-1', | ||
}, | ||
}; | ||
|
||
const customLineItem: CustomLineItem = { | ||
id: 'customLineItem-id-1', | ||
name: { | ||
en: 'customLineItem-name-1', | ||
}, | ||
slug: '', | ||
money: { | ||
type: 'centPrecision', | ||
currencyCode: 'USD', | ||
centAmount: 150000, | ||
fractionDigits: 2, | ||
}, | ||
quantity: 1, | ||
totalPrice: { | ||
type: 'centPrecision', | ||
currencyCode: 'USD', | ||
centAmount: 150000, | ||
fractionDigits: 2, | ||
}, | ||
discountedPricePerQuantity: [], | ||
taxedPricePortions: [], | ||
state: [], | ||
perMethodTaxRate: [], | ||
priceMode: 'Platform', | ||
}; | ||
|
||
const shippingInfo: ShippingInfo = { | ||
shippingMethodName: 'shippingMethodName1', | ||
price: { | ||
type: 'centPrecision', | ||
currencyCode: 'USD', | ||
centAmount: 150000, | ||
fractionDigits: 2, | ||
}, | ||
shippingRate: { | ||
price: { | ||
type: 'centPrecision', | ||
currencyCode: 'USD', | ||
centAmount: 1000, | ||
fractionDigits: 2, | ||
}, | ||
tiers: [], | ||
}, | ||
shippingMethodState: 'MatchesCart', | ||
}; |
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