Skip to content

Commit

Permalink
fix: e2e fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
fox-john committed Oct 29, 2024
1 parent 0017f11 commit 590e9b7
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 72 deletions.
1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"jest-expect-message": "^1.1.3",
"jest-extended": "^4.0.2",
"jest-mock-extended": "^3.0.7",
"object-hash": "3.0.0",
"prettier": "^3.3.3",
"ramda": "^0.30.1",
"rxjs": "^7.8.1",
Expand Down
8 changes: 8 additions & 0 deletions e2e/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

170 changes: 145 additions & 25 deletions e2e/src/fixtures/8/orders.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,46 @@
"conversion_rate": 1,
"total_paid_tax_excl": 66.8,
"total_paid_tax_incl": 68.2,
"new_customer": true,
"currency": "EUR",
"refund": 0,
"refund_tax_excl": 0,
"payment_module": "ps_checkpayment",
"payment_mode": "Payment by check",
"total_paid_real": "0.000000",
"shipping_cost": 7,
"created_at": "2024-02-06T20:24:53+0100",
"updated_at": "2024-02-06T20:24:53+0100",
"created_at": "2024-09-26T22:51:17+0200",
"updated_at": "2024-09-26T22:51:17+0200",
"id_carrier": 2,
"payment_name": "ps_checkpayment",
"is_validated": "0",
"is_paid": false,
"is_shipped": "0",
"status_label": "Canceled",
"id_shop_group": 1,
"id_shop": 1,
"id_lang": 1,
"id_currency": 1,
"recyclable": false,
"gift": false,
"total_discounts": 0,
"total_discounts_tax_incl": 0,
"total_discounts_tax_excl": 0,
"total_products": 59,
"total_products_wt": 59,
"total_shipping_tax_incl": 8,
"total_shipping_tax_excl": 7,
"carrier_tax_rate": 0,
"total_wrapping": 0,
"total_wrapping_tax_incl": 0,
"total_wrapping_tax_excl": 0,
"round_mode": 0,
"round_type": 0,
"invoice_number": 0,
"delivery_number": 0,
"invoice_date": "0000-00-00 00:00:00",
"delivery_date": "0000-00-00 00:00:00",
"valid": false,
"refund": 0,
"refund_tax_excl": 0,
"new_customer": true,
"total_paid_tax": 1.4000000000000057,
"delivery_country_code": "US",
"invoice_country_code": "US"
Expand All @@ -44,22 +68,46 @@
"conversion_rate": 1,
"total_paid_tax_excl": 169.9,
"total_paid_tax_incl": 169.9,
"new_customer": false,
"currency": "EUR",
"refund": 0,
"refund_tax_excl": 0,
"payment_module": "ps_checkpayment",
"payment_mode": "Payment by check",
"total_paid_real": "0.000000",
"shipping_cost": 0,
"created_at": "2024-02-06T20:24:53+0100",
"updated_at": "2024-02-06T20:24:53+0100",
"created_at": "2024-09-26T22:51:17+0200",
"updated_at": "2024-09-26T22:51:17+0200",
"id_carrier": 2,
"payment_name": "ps_checkpayment",
"is_validated": "0",
"is_paid": false,
"is_shipped": "0",
"status_label": "Awaiting check payment",
"id_shop_group": 1,
"id_shop": 1,
"id_lang": 1,
"id_currency": 1,
"recyclable": false,
"gift": false,
"total_discounts": 0,
"total_discounts_tax_incl": 0,
"total_discounts_tax_excl": 0,
"total_products": 169,
"total_products_wt": 169,
"total_shipping_tax_incl": 0,
"total_shipping_tax_excl": 0,
"carrier_tax_rate": 0,
"total_wrapping": 0,
"total_wrapping_tax_incl": 0,
"total_wrapping_tax_excl": 0,
"round_mode": 0,
"round_type": 0,
"invoice_number": 0,
"delivery_number": 0,
"invoice_date": "0000-00-00 00:00:00",
"delivery_date": "0000-00-00 00:00:00",
"valid": false,
"refund": 0,
"refund_tax_excl": 0,
"new_customer": false,
"total_paid_tax": 0,
"delivery_country_code": "US",
"invoice_country_code": "US"
Expand All @@ -77,22 +125,46 @@
"conversion_rate": 1,
"total_paid_tax_excl": 19.9,
"total_paid_tax_incl": 21.3,
"new_customer": false,
"currency": "EUR",
"refund": 0,
"refund_tax_excl": 0,
"payment_module": "ps_checkpayment",
"payment_mode": "Payment by check",
"total_paid_real": "0.000000",
"shipping_cost": 7,
"created_at": "2024-02-06T20:24:53+0100",
"updated_at": "2024-02-06T20:24:53+0100",
"created_at": "2024-09-26T22:51:17+0200",
"updated_at": "2024-09-26T22:51:17+0200",
"id_carrier": 2,
"payment_name": "ps_checkpayment",
"is_validated": "0",
"is_paid": false,
"is_shipped": "0",
"status_label": "Payment error",
"id_shop_group": 1,
"id_shop": 1,
"id_lang": 1,
"id_currency": 1,
"recyclable": false,
"gift": false,
"total_discounts": 0,
"total_discounts_tax_incl": 0,
"total_discounts_tax_excl": 0,
"total_products": 12,
"total_products_wt": 12,
"total_shipping_tax_incl": 8,
"total_shipping_tax_excl": 7,
"carrier_tax_rate": 0,
"total_wrapping": 0,
"total_wrapping_tax_incl": 0,
"total_wrapping_tax_excl": 0,
"round_mode": 0,
"round_type": 0,
"invoice_number": 0,
"delivery_number": 0,
"invoice_date": "0000-00-00 00:00:00",
"delivery_date": "0000-00-00 00:00:00",
"valid": false,
"refund": 0,
"refund_tax_excl": 0,
"new_customer": false,
"total_paid_tax": 1.4000000000000021,
"delivery_country_code": "US",
"invoice_country_code": "US"
Expand All @@ -110,22 +182,46 @@
"conversion_rate": 1,
"total_paid_tax_excl": 19.9,
"total_paid_tax_incl": 21.3,
"new_customer": false,
"currency": "EUR",
"refund": 0,
"refund_tax_excl": 0,
"payment_module": "ps_checkpayment",
"payment_mode": "Payment by check",
"total_paid_real": "0.000000",
"shipping_cost": 7,
"created_at": "2024-02-06T20:24:53+0100",
"updated_at": "2024-02-06T20:24:53+0100",
"created_at": "2024-09-26T22:51:17+0200",
"updated_at": "2024-09-26T22:51:17+0200",
"id_carrier": 2,
"payment_name": "ps_checkpayment",
"is_validated": "0",
"is_paid": false,
"is_shipped": "0",
"status_label": "Awaiting check payment",
"id_shop_group": 1,
"id_shop": 1,
"id_lang": 1,
"id_currency": 1,
"recyclable": false,
"gift": false,
"total_discounts": 0,
"total_discounts_tax_incl": 0,
"total_discounts_tax_excl": 0,
"total_products": 12,
"total_products_wt": 12,
"total_shipping_tax_incl": 8,
"total_shipping_tax_excl": 7,
"carrier_tax_rate": 0,
"total_wrapping": 0,
"total_wrapping_tax_incl": 0,
"total_wrapping_tax_excl": 0,
"round_mode": 0,
"round_type": 0,
"invoice_number": 0,
"delivery_number": 0,
"invoice_date": "0000-00-00 00:00:00",
"delivery_date": "0000-00-00 00:00:00",
"valid": false,
"refund": 0,
"refund_tax_excl": 0,
"new_customer": false,
"total_paid_tax": 1.4000000000000021,
"delivery_country_code": "US",
"invoice_country_code": "US"
Expand All @@ -143,22 +239,46 @@
"conversion_rate": 1,
"total_paid_tax_excl": 25.9,
"total_paid_tax_incl": 27.3,
"new_customer": false,
"currency": "EUR",
"refund": 0,
"refund_tax_excl": 0,
"payment_module": "ps_wirepayment",
"payment_mode": "Bank wire",
"total_paid_real": "0.000000",
"shipping_cost": 7,
"created_at": "2024-02-06T20:24:53+0100",
"updated_at": "2024-02-06T20:24:53+0100",
"created_at": "2024-09-26T22:51:17+0200",
"updated_at": "2024-09-26T22:51:17+0200",
"id_carrier": 2,
"payment_name": "ps_wirepayment",
"is_validated": "0",
"is_paid": false,
"is_shipped": "0",
"status_label": "Awaiting bank wire payment",
"id_shop_group": 1,
"id_shop": 1,
"id_lang": 1,
"id_currency": 1,
"recyclable": false,
"gift": false,
"total_discounts": 0,
"total_discounts_tax_incl": 0,
"total_discounts_tax_excl": 0,
"total_products": 18,
"total_products_wt": 18,
"total_shipping_tax_incl": 8,
"total_shipping_tax_excl": 7,
"carrier_tax_rate": 0,
"total_wrapping": 0,
"total_wrapping_tax_incl": 0,
"total_wrapping_tax_excl": 0,
"round_mode": 0,
"round_type": 0,
"invoice_number": 0,
"delivery_number": 0,
"invoice_date": "0000-00-00 00:00:00",
"delivery_date": "0000-00-00 00:00:00",
"valid": false,
"refund": 0,
"refund_tax_excl": 0,
"new_customer": false,
"total_paid_tax": 1.4000000000000021,
"delivery_country_code": "US",
"invoice_country_code": "US"
Expand Down
39 changes: 15 additions & 24 deletions e2e/src/full-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import axios from "axios";
import { doFullSync, probe, PsEventbusSyncUpload } from "./helpers/mock-probe";
import { lastValueFrom, toArray, withLatestFrom } from "rxjs";
import {
generatePredictableModuleId,
loadFixture,
omitProperties,
sortUploadData,
} from "./helpers/data-helper";
import { ShopContent, shopContentList } from "./helpers/shop-contents";
import { shopContentList } from "./helpers/shop-contents";

expect.extend(matchers);

Expand All @@ -26,6 +25,8 @@ const isBoolean = (val) =>
const specialFieldAssert: { [index: string]: (val) => void } = {
created_at: isDateString,
updated_at: isDateString,
delivery_date: isDateString,
invoice_date: isDateString,
last_connection_date: isDateString,
folder_created_at: isDateString,
date_add: isDateString,
Expand Down Expand Up @@ -100,38 +101,28 @@ describe("Full Sync", () => {
),
);

const syncedData: PsEventbusSyncUpload[] = messages.flat();
let dataFromModule: PsEventbusSyncUpload[] = messages.flat();
let fixtures = await loadFixture(shopContent);

// dump data for easier debugging or updating fixtures
let processedData = syncedData as PsEventbusSyncUpload[];
if (testConfig.dumpFullSyncData) {
await dumpUploadData(syncedData, shopContent);
await dumpUploadData(dataFromModule);
}

const fixture = await loadFixture(shopContent);

// we need to process fixtures and data returned from ps_eventbus to make them easier to compare
let processedFixture = fixture;
if (shopContent === ("modules" as ShopContent)) {
processedData = generatePredictableModuleId(processedData);
processedFixture = generatePredictableModuleId(processedFixture);
}
processedData = omitProperties(
processedData,
Object.keys(specialFieldAssert),
);
processedData = sortUploadData(processedData);
processedFixture = omitProperties(
processedFixture,
dataFromModule = omitProperties(
dataFromModule,
Object.keys(specialFieldAssert),
);
processedFixture = sortUploadData(processedFixture);

fixtures = omitProperties(fixtures, Object.keys(specialFieldAssert));

dataFromModule = sortUploadData(dataFromModule);
fixtures = sortUploadData(fixtures);

// assert
expect(processedData).toMatchObject(processedFixture);
expect(dataFromModule).toEqual(fixtures);

// assert special field using custom matcher
for (const data of processedData) {
for (const data of dataFromModule) {
for (const specialFieldName of Object.keys(specialFieldAssert)) {
if (data.properties[specialFieldName] !== undefined) {
specialFieldAssert[specialFieldName](
Expand Down
Loading

0 comments on commit 590e9b7

Please sign in to comment.