Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mzanoni committed Mar 26, 2024
1 parent 8cd945a commit 9f3c93c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions full-sync/src/mapping/mapProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default function mapProduct(product: ProductProjection, unixTimeStamp: nu
const builder = new ProductUpdateBuilder({
id: product.key ?? product.id,
productUpdateKind: 'ReplaceProvidedProperties',
variantUpdateKind: 'ReplaceProvidedProperties',
replaceExistingVariants: true
})
.variants(mapVariants(variants, product))
.displayName(localizedToLanguageLookUp(product.name))
Expand Down Expand Up @@ -68,6 +70,7 @@ function mapVariants(variants: CTProductVariant[], product: ProductProjection):
return builder.build();
});
}

function mapPriceOnProduct(builder: ProductUpdateBuilder, variants: CTProductVariant[]) {
const lowestListPrice = Object.entries(groupBy(
variants.flatMap(v => v.prices?.map(p => ({ amount: p.value.centAmount / 100, currency: p.value.currencyCode })) ?? []),
Expand Down
35 changes: 25 additions & 10 deletions full-sync/tests/mapping/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from '@jest/globals';
import { localizedToMultilingual } from '../../src/mapping/helpers';
import { localizedToLanguageLookUp, localizedToMultilingual } from '../../src/mapping/helpers';
import { DataValueFactory } from '@relewise/client';

describe('Testing helpers', () => {
Expand All @@ -8,31 +8,28 @@ describe('Testing helpers', () => {
const result = localizedToMultilingual(undefined)
expect(result).toBe(null);
});
});

describe('Testing helpers', () => {

test('localizedToMultilingual 1 language', () => {

const subject = localizedToMultilingual({
const result = localizedToMultilingual({
"en": "test"
});

expect(subject).toStrictEqual(DataValueFactory.multilingual([{
expect(result).toStrictEqual(DataValueFactory.multilingual([{
language: "en",
value: "test"
}]));
});
});

describe('Testing helpers', () => {
test('localizedToMultilingual 2 languages', () => {

const subject = localizedToMultilingual({
const result = localizedToMultilingual({
"en": "test",
"da": "test2",
});

expect(subject).toStrictEqual(DataValueFactory.multilingual([
expect(result).toStrictEqual(DataValueFactory.multilingual([
{
language: "en",
value: "test"
Expand All @@ -43,5 +40,23 @@ describe('Testing helpers', () => {
}
]));
});
});

test('localizedToMultilingual 2 languages', () => {

const result = localizedToLanguageLookUp({
"en": "test",
"da": "test2",
});

expect(result).toStrictEqual([
{
language: "en",
value: "test"
},
{
language: "da",
value: "test2"
}
]);
});
});

0 comments on commit 9f3c93c

Please sign in to comment.