Skip to content

Commit

Permalink
feat: pseventbus v4 cart products (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox-john authored Sep 12, 2024
1 parent 226d177 commit bf42d62
Show file tree
Hide file tree
Showing 33 changed files with 569 additions and 347 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
strategy:
matrix:
# @TODO: "1.6.1.24" is temporarily disabled here
ps_version: ["1.6.1.11", "1.7.8.10", "8.1.6"]
ps_version: ["1.7.8.10", "8.1.6"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -90,7 +90,8 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
ps_version: ["1.6.1.11", "1.7.8.10", "8.1.4", "nightly"]
# @TODO: "1.6.1.24" is temporarily disabled here
ps_version: ["1.7.8.10", "8.1.4", "nightly"]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
->exclude('vendor');

$config = (new PrestaShop\CodingStandards\CsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setUsingCache(false)
->setFinder($finder);

Expand Down
4 changes: 4 additions & 0 deletions config/common/new-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ services:
PrestaShop\Module\PsEventbus\Repository\NewRepository\CartRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CartRepository
public: true

PrestaShop\Module\PsEventbus\Repository\NewRepository\CartProductRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CartProductRepository
public: true
6 changes: 0 additions & 6 deletions config/common/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ services:
class: PrestaShop\Module\PsEventbus\Repository\GoogleTaxonomyRepository
public: true

PrestaShop\Module\PsEventbus\Repository\DeletedObjectsRepository:
class: PrestaShop\Module\PsEventbus\Repository\DeletedObjectsRepository
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandlerInterface'

PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository:
class: PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository
public: true
Expand Down
6 changes: 6 additions & 0 deletions config/front/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ services:
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CartRepository'

PrestaShop\Module\PsEventbus\Service\ShopContent\CartProductsService:
class: PrestaShop\Module\PsEventbus\Service\ShopContent\CartProductsService
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CartProductRepository'
228 changes: 227 additions & 1 deletion e2e/src/fixtures/1.7/carrier_details.json
Original file line number Diff line number Diff line change
@@ -1 +1,227 @@
[]
[
{
"id": "2-1-range_weight-1",
"collection": "carrier_details",
"properties": {
"id_reference": "2",
"id_zone": "1",
"id_range": "1",
"id_carrier_detail": "1",
"shipping_method": "range_weight",
"delimiter1": 0,
"delimiter2": 10000,
"country_ids": "",
"state_ids": "",
"price": 5
}
},
{
"id": "2-2-range_weight-1",
"collection": "carrier_details",
"properties": {
"id_reference": "2",
"id_zone": "2",
"id_range": "1",
"id_carrier_detail": "1",
"shipping_method": "range_weight",
"delimiter1": 0,
"delimiter2": 10000,
"country_ids": "",
"state_ids": "",
"price": 5
}
},
{
"id": "3-2-range_price-2",
"collection": "carrier_details",
"properties": {
"id_reference": "3",
"id_zone": "2",
"id_range": "2",
"id_carrier_detail": "2",
"shipping_method": "range_price",
"delimiter1": 0,
"delimiter2": 50,
"country_ids": "",
"state_ids": "",
"price": 4
}
},
{
"id": "3-1-range_price-2",
"collection": "carrier_details",
"properties": {
"id_reference": "3",
"id_zone": "1",
"id_range": "2",
"id_carrier_detail": "2",
"shipping_method": "range_price",
"delimiter1": 0,
"delimiter2": 50,
"country_ids": "",
"state_ids": "",
"price": 3
}
},
{
"id": "3-2-range_price-3",
"collection": "carrier_details",
"properties": {
"id_reference": "3",
"id_zone": "2",
"id_range": "3",
"id_carrier_detail": "3",
"shipping_method": "range_price",
"delimiter1": 50,
"delimiter2": 100,
"country_ids": "",
"state_ids": "",
"price": 2
}
},
{
"id": "3-1-range_price-3",
"collection": "carrier_details",
"properties": {
"id_reference": "3",
"id_zone": "1",
"id_range": "3",
"id_carrier_detail": "3",
"shipping_method": "range_price",
"delimiter1": 50,
"delimiter2": 100,
"country_ids": "",
"state_ids": "",
"price": 1
}
},
{
"id": "3-2-range_price-4",
"collection": "carrier_details",
"properties": {
"id_reference": "3",
"id_zone": "2",
"id_range": "4",
"id_carrier_detail": "4",
"shipping_method": "range_price",
"delimiter1": 100,
"delimiter2": 200,
"country_ids": "",
"state_ids": "",
"price": 0
}
},
{
"id": "3-1-range_price-4",
"collection": "carrier_details",
"properties": {
"id_reference": "3",
"id_zone": "1",
"id_range": "4",
"id_carrier_detail": "4",
"shipping_method": "range_price",
"delimiter1": 100,
"delimiter2": 200,
"country_ids": "",
"state_ids": "",
"price": 0
}
},
{
"id": "4-2-range_weight-2",
"collection": "carrier_details",
"properties": {
"id_reference": "4",
"id_zone": "2",
"id_range": "2",
"id_carrier_detail": "2",
"shipping_method": "range_weight",
"delimiter1": 0,
"delimiter2": 1,
"country_ids": "",
"state_ids": "",
"price": 0
}
},
{
"id": "4-1-range_weight-2",
"collection": "carrier_details",
"properties": {
"id_reference": "4",
"id_zone": "1",
"id_range": "2",
"id_carrier_detail": "2",
"shipping_method": "range_weight",
"delimiter1": 0,
"delimiter2": 1,
"country_ids": "",
"state_ids": "",
"price": 0
}
},
{
"id": "4-2-range_weight-3",
"collection": "carrier_details",
"properties": {
"id_reference": "4",
"id_zone": "2",
"id_range": "3",
"id_carrier_detail": "3",
"shipping_method": "range_weight",
"delimiter1": 1,
"delimiter2": 3,
"country_ids": "",
"state_ids": "",
"price": 3
}
},
{
"id": "4-1-range_weight-3",
"collection": "carrier_details",
"properties": {
"id_reference": "4",
"id_zone": "1",
"id_range": "3",
"id_carrier_detail": "3",
"shipping_method": "range_weight",
"delimiter1": 1,
"delimiter2": 3,
"country_ids": "",
"state_ids": "",
"price": 2
}
},
{
"id": "4-2-range_weight-4",
"collection": "carrier_details",
"properties": {
"id_reference": "4",
"id_zone": "2",
"id_range": "4",
"id_carrier_detail": "4",
"shipping_method": "range_weight",
"delimiter1": 3,
"delimiter2": 10000,
"country_ids": "",
"state_ids": "",
"price": 6
}
},
{
"id": "4-1-range_weight-4",
"collection": "carrier_details",
"properties": {
"id_reference": "4",
"id_zone": "1",
"id_range": "4",
"id_carrier_detail": "4",
"shipping_method": "range_weight",
"delimiter1": 3,
"delimiter2": 10000,
"country_ids": "",
"state_ids": "",
"price": 5
}
}
]

2 changes: 1 addition & 1 deletion e2e/src/fixtures/1.7/carriers.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"properties": {
"id_carrier": "1",
"id_reference": "1",
"name": "PrestaShop",
"name": "0",
"carrier_taxes_rates_group_id": "1",
"url": "",
"active": true,
Expand Down
39 changes: 25 additions & 14 deletions e2e/src/full-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
sortUploadData,
} from "./helpers/data-helper";
import { ShopContent, shopContentList } from "./helpers/shop-contents";
import { exit } from "process";
import { cp } from "fs";

expect.extend(matchers);

Expand Down Expand Up @@ -50,7 +52,7 @@ const specialFieldAssert: { [index: string]: (val) => void } = {
}

describe('Full Sync', () => {
let testTimestamp = 0;
let generatedNumber = 0;

// gérer les cas ou un shopContent n'existe pas (pas de fixture du coup)
const shopContents: ShopContent[] = shopContentList.filter(
Expand All @@ -60,8 +62,8 @@ describe('Full Sync', () => {
let jobId: string;

beforeEach(() => {
testTimestamp = Date.now();
jobId = `valid-job-full-${testTimestamp}`;
generatedNumber = Date.now() + Math.trunc(Math.random() * 100000000000000);
jobId = `valid-job-full-${generatedNumber}`;
});

// TODO : some versions of prestashop include ps_facebook out of the box, this test can't reliably be run for all versions
Expand Down Expand Up @@ -191,26 +193,35 @@ describe('Full Sync', () => {
const message$ = probe({ url: `/upload/${jobId}` }, { timeout: 4000 });

let syncedData: PsEventbusSyncUpload[];
let hasData = false;

try {
// act
syncedData = await lastValueFrom(
zip(fullSync$, message$).pipe(
map((msg) => {
return msg[1].body.file
}),
concatMap((syncedPage) => {
return from(syncedPage);
}),
toArray()
)
);
hasData = (await lastValueFrom(fullSync$)).total_objects != 0;

if (hasData) {
syncedData = await lastValueFrom(
zip(fullSync$, message$).pipe(
map((msg) => {
return msg[1].body.file
}),
concatMap((syncedPage) => {
return from(syncedPage);
}),
toArray()
)
);
}
} catch (error) {
if (error instanceof TimeoutError) {
throw new Error(`Upload complete dataset collector for "${shopContent}" throw TimeoutError with jobId "${jobId}"`)
}
}

if (!hasData) {
return;
}

// dump data for easier debugging or updating fixtures
if (testConfig.dumpFullSyncData) {
await dumpUploadData(syncedData, shopContent);
Expand Down
1 change: 1 addition & 0 deletions e2e/src/helpers/shop-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const shopContentMapping = {
'carrier_details': 'carrier-details',
'carrier_taxes': 'carrier-taxes',
'carts': 'carts',
'cart_products': 'cart-products',
'orders': 'orders',
'order_cart_rules': 'order-cart-rules',
'order_details': 'order-details',
Expand Down
6 changes: 3 additions & 3 deletions e2e/src/reject-invalid-job-id.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {probe} from "./helpers/mock-probe";
import { ShopContent, shopContentList } from "./helpers/shop-contents";

describe('Reject invalid job-id', () => {
let testTimestamp = 0;
let generatedNumber = 0;

const shopContents: ShopContent[] = shopContentList

let jobId: string;

beforeEach(() => {
testTimestamp = Date.now();
jobId = `invalid-job-id-${testTimestamp}`
generatedNumber = Date.now() + Math.trunc(Math.random() * 100000000000000);
jobId = `invalid-job-id-${generatedNumber}`
});

it.each(shopContents)(`%s should return 454 with an invalid job id (sync-api status 454)`, async (shopContent) => {
Expand Down
Loading

0 comments on commit bf42d62

Please sign in to comment.