Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(packaging): few enhancements #359

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @PrestaShopCorp/squad-cloud-sync
2 changes: 1 addition & 1 deletion .github/workflows/build-release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
if: github.event.release.tag_name != 'staging'
strategy:
matrix:
ps_version: ["1.7.8.10", "8.1.7"]
ps_version: ["1.6.1.11", "1.7.8.10", "8.1.7"]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Quality Control
name: PRs Quality Check

env:
NODE_BUILDER_VERSION: "20"
Expand Down Expand Up @@ -50,14 +50,13 @@ jobs:
run: make lint

phpstan:
name: PHPStan
name: PHPStan for PrestaShop ${{ matrix.presta-versions }}
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
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.6.1.11", "1.7.8.10", "8.1.7"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ docker-phpunit-cov: tools/vendor
phpstan: tools/vendor prestashop/prestashop-${PS_VERSION}
phpstan analyse --memory-limit=-1 --configuration=./tests/phpstan/phpstan-local.neon;
docker-phpstan:
@$(call in_docker,/usr/bin/phpstan,analyse --memory-limit=-1 --configuration=./tests/phpstan/phpstan-docker.neon)
@$(call in_docker,phpstan,analyse --memory-limit=-1 --configuration=./tests/phpstan/phpstan-docker.neon)

define COMMENT
Fixme: add "allure-framework/allure-phpunit" in composer.json to solve this.
Expand Down
19 changes: 11 additions & 8 deletions e2e-env/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ services:
mysql:
image: mariadb:${DOCKER_VERSION_MARIADB:?See e2e-env/.env.dist}
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect"]
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3
environment:
- MYSQL_HOST=mysql
- MYSQL_USER=prestashop
- MYSQL_PASSWORD=prestashop
- MYSQL_ROOT_PASSWORD=prestashop
- MYSQL_PORT=3306
- MYSQL_DATABASE=prestashop
- MARIADB_USER=prestashop
- MARIADB_PASSWORD=prestashop
- MARIADB_ROOT_PASSWORD=prestashop
- MARIADB_PORT=3306
- MARIADB_DATABASE=prestashop
ports:
- ${HOST_PORT_BIND_MYSQL:?See e2e-env/.env.dist}:3306
networks:
Expand All @@ -59,7 +62,7 @@ services:
- PMA_PORT=3306
- PMA_USER=prestashop
- PMA_PASSWORD=prestashop
- MYSQL_ROOT_PASSWORD=prestashop
- MARIADB_ROOT_PASSWORD=prestashop
networks:
- prestashop

Expand Down
33 changes: 17 additions & 16 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# e2e testing ps_eventbus

ps_eventbus works by listening to calls and pushing data to the Cloudsync server synchronously.
In order to test the calls made to Cloudsync, tests connect to mock Cloudsync servers using Websocket.
ps_eventbus works by listening to calls and pushing data to the CloudSync server synchronously.
In order to test the calls made to CloudSync, tests connect to mock CloudSync servers using Websocket.

## Running tests

First start e2e environment in ```e2e-env``` (see e2e-env [README.md](../e2e-env/README.md)) then simply run ```pnpm test:e2e```.
First start e2e environment in `e2e-env` (see e2e-env [README.md](../e2e-env/README.md)) then simply run `pnpm test:e2e`.

## Writing tests

The `MockProbe` object allows to connect to a mock and check uploaded contents against the query we made.

example :
```typescript
import { MockProbe } from './helpers/mock-probe';
import testConfig from './helpers/test.config';
import request from 'supertest';

const controller = 'apiCategories';
````typescript
import { MockProbe } from "./helpers/mock-probe";
import testConfig from "./helpers/test.config";
import request from "supertest";

const controller = "apiCategories";
const endpoint = `/index.php?fc=module&module=ps_eventbus&controller=${controller}&limit=5`;

describe('CategoriesController', () => {
describe("CategoriesController", () => {
it(`${controller} should upload to collector`, async () => {
// arrange
const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=${controller}&limit=5&full=1&job_id=${jobId}`;
// jobId starting with "valid-job-" will be considered valid by the mock sync-api and will always return 201;
// other values will be rejected by the mock
const jobId = 'valid-job-1'
const jobId = "valid-job-1";
// get values sent to the mock as Observable.
// only values maching the given parameter will be received, which allows to exclude values sent by other tests.
// The obsevable given by ```probe()``` establishes a websocket connection with the mock only on first subscribe,
Expand All @@ -36,15 +37,15 @@ describe('CategoriesController', () => {

// Define a random callId. This param is set into body for define the compat with PHP 5.6,
// with header 'Content-Type': 'application/x-www-form-urlencoded'
const callId = { 'call_id': Math.random().toString(36).substring(2, 11) };
const callId = { call_id: Math.random().toString(36).substring(2, 11) };

// act
// call ps_eventbus api, which should in turn upload data to the mock.
const request$ = from(
axios.post(url, callId, {
headers: {
Host: testConfig.prestaShopHostHeader,
'Content-Type': 'application/x-www-form-urlencoded' // for compat PHP 5.6
"Content-Type": "application/x-www-form-urlencoded", // for compat PHP 5.6
},
})
);
Expand Down Expand Up @@ -72,13 +73,13 @@ describe('CategoriesController', () => {
});
});
});
```
````

## Using fixtures

Fixtures for prestashop versions should be placed in [src/fixtures](src/fixtures). The correct version is loaded
automatically by ```loadFixture()```. If no fixture matches the version given by prestashop's healthcheck,
Fixtures for prestashop versions should be placed in [src/fixtures](src/fixtures). The correct version is loaded
automatically by `loadFixture()`. If no fixture matches the version given by prestashop's healthcheck,
[src/fixtures/latest](src/fixtures/latest) is loaded instead.

```dumpUploadData()``` will write data in [dumps](dumps) using the same format used by ```loadFixture()```
`dumpUploadData()` will write data in [dumps](dumps) using the same format used by `loadFixture()`
to make it easier to make or update fixtures.
Loading