-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from sequra/feature/PAR-372-Implement-E2E-test…
…s-for-Magento Implement E2E tests for Magento
- Loading branch information
Showing
21 changed files
with
1,030 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
.docker/magento/HelperModule/Sequra/Helper/Api/WebhooksInterface.php
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,11 @@ | ||
<?php | ||
|
||
namespace Sequra\Helper\Api; | ||
|
||
interface WebhooksInterface | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function execute(); | ||
} |
46 changes: 46 additions & 0 deletions
46
.docker/magento/HelperModule/Sequra/Helper/Model/Api/Webhooks.php
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,46 @@ | ||
<?php | ||
namespace Sequra\Helper\Model\Api; | ||
|
||
use Sequra\Helper\Api\WebhooksInterface; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Sequra\Helper\Model\Task\ClearConfigurationTask; | ||
use Sequra\Helper\Model\Task\ConfigureDummyTask; | ||
use Sequra\Helper\Model\Task\Task; | ||
|
||
class Webhooks implements WebhooksInterface | ||
{ | ||
protected $request; | ||
|
||
/** | ||
* Resource connection | ||
*/ | ||
protected $conn; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public function __construct(ResourceConnection $resourceConnection) { | ||
$this->conn = $resourceConnection; | ||
} | ||
|
||
public function execute() | ||
{ | ||
return $this->getTaskForWebhook((string)($_GET['sq-webhook'] ?? null))->execute(); | ||
} | ||
|
||
|
||
/** | ||
* Get task for webhook | ||
*/ | ||
private function getTaskForWebhook( $webhook ): Task { | ||
$map = array( | ||
// 'dummy_services_config' => ConfigureDummy_Service_Task::class, | ||
'dummy_config' => ConfigureDummyTask::class, | ||
'clear_config' => ClearConfigurationTask::class, | ||
// 'remove_db_tables' => RemoveDbTablesTask::class | ||
|
||
); | ||
return ! isset( $map[ $webhook ] ) ? new Task($this->conn) : new $map[ $webhook ]($this->conn); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.docker/magento/HelperModule/Sequra/Helper/Model/Task/ClearConfigurationTask.php
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,24 @@ | ||
<?php | ||
/** | ||
* Task class | ||
* | ||
* @package SeQura/Helper | ||
*/ | ||
|
||
namespace Sequra\Helper\Model\Task; | ||
|
||
/** | ||
* Task class | ||
*/ | ||
class ClearConfigurationTask extends Task { | ||
|
||
/** | ||
* Execute the task | ||
* | ||
* @throws \Exception If the task fails | ||
*/ | ||
public function execute( array $args = array() ) { | ||
$this->removeStoreDataFromEntityTable(); | ||
return $this->httpSuccessResponse(); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
.docker/magento/HelperModule/Sequra/Helper/Model/Task/ConfigureDummyTask.php
Large diffs are not rendered by default.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
.docker/magento/HelperModule/Sequra/Helper/Model/Task/Task.php
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,79 @@ | ||
<?php | ||
/** | ||
* Task class | ||
* | ||
* @package SeQura/Helper | ||
*/ | ||
|
||
namespace Sequra\Helper\Model\Task; | ||
use Magento\Framework\DB\Ddl\Table; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\Webapi\Exception; | ||
use Magento\Framework\Phrase; | ||
use Sequra\Core\Setup\DatabaseHandler; | ||
|
||
/** | ||
* Task class | ||
*/ | ||
class Task { | ||
|
||
/** | ||
* Resource connection | ||
*/ | ||
protected $conn; | ||
protected $dbHandler; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public function __construct(ResourceConnection $resourceConnection) { | ||
$this->conn = $resourceConnection; | ||
$this->dbHandler = new DatabaseHandler($resourceConnection); | ||
} | ||
|
||
/** | ||
* Execute the task | ||
* | ||
* @throws \Exception If the task fails | ||
*/ | ||
public function execute( array $args = array() ) { | ||
throw new \Exception( 'Task not implemented', 500 ); | ||
} | ||
|
||
/** | ||
* Recreate tables in the database | ||
*/ | ||
protected function removeStoreDataFromEntityTable(): void { | ||
$connection = $this->conn->getConnection(); | ||
// DELETE all rows not having type in ('Configuration', 'Process') | ||
$connection->delete( | ||
DatabaseHandler::SEQURA_ENTITY_TABLE, | ||
[ | ||
'type NOT IN (?)' => ['Configuration', 'Process'] | ||
] | ||
); | ||
} | ||
|
||
protected function timeToString(int $timestamp): string { | ||
$time = (string) $timestamp; | ||
// append 0s to the left until reach 11 characters | ||
while (strlen($time) < 11) { | ||
$time = '0' . $time; | ||
} | ||
return $time; | ||
} | ||
|
||
/** | ||
* Response with an error message | ||
*/ | ||
public function httpErrorResponse( string $message, int $error_code ) { | ||
throw new Exception(new Phrase($message), $error_code, $error_code); | ||
} | ||
|
||
/** | ||
* Response with an error message | ||
*/ | ||
public function httpSuccessResponse() { | ||
return ['success' => true, 'data' => ['message' => 'Task executed']]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"> | ||
<route url="/V1/sequrahelper/webhook" method="POST"> | ||
<service class="Sequra\Helper\Api\WebhooksInterface" method="execute"/> | ||
<resources> | ||
<resource ref="anonymous"/> | ||
</resources> | ||
</route> | ||
</routes> |
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
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,41 @@ | ||
#!/bin/bash | ||
BASEDIR="$(dirname $(realpath $0))/.." | ||
|
||
cd "${BASEDIR}" || exit | ||
set -o allexport | ||
source .env | ||
set +o allexport | ||
|
||
if [ -z "$PUBLIC_URL" ]; then | ||
PUBLIC_URL="$M2_URL" | ||
fi | ||
|
||
wait_for() { | ||
local retry=60 | ||
local timeout=1 | ||
local start=$(date +%s) | ||
|
||
while [ $(($(date +%s) - $start)) -lt $retry ]; do | ||
if "$@" > /dev/null 2>&1; then | ||
return 0 | ||
fi | ||
sleep $timeout | ||
done | ||
return 1 | ||
} | ||
echo "🚀 Waiting for ngrok tunnel to be ready..." | ||
result=$(wait_for curl -H "ngrok-skip-browser-warning: 1" -s -o /dev/null --head --fail "${PUBLIC_URL}") | ||
if [ "$result" == "1" ]; then | ||
echo "❌ Magento is not available at: ${PUBLIC_URL}" | ||
exit 1 | ||
fi | ||
echo "✅ Magento is available at: ${PUBLIC_URL}" | ||
|
||
# Check if --headed is passed | ||
if [[ "$@" == *"--headed"* || "$@" == *"--ui"* ]]; then | ||
npx playwright test $@ | ||
else | ||
docker run \ | ||
--env-file "${BASEDIR}"/.env \ | ||
-it --rm -v "${BASEDIR}":/app -w /app mcr.microsoft.com/playwright:v1.49.1-jammy bash -c "npx playwright test $@" | ||
fi |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
{ | ||
"name": "magento2-core", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"description": "1. [About seQura](#about-sequra) 2. [Installation guide](https://sequra.atlassian.net/wiki/spaces/DOC/pages/1377304583/MAGENTO+2) 3. [Sign-up](#sign-up) 4. [For developers](#for-developers)", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@playwright/test": "^1.49.1", | ||
"@types/node": "^22.10.7", | ||
"playwright-fixture-for-plugins": "github:sequra/playwright-fixture-for-plugins" | ||
} | ||
} |
Oops, something went wrong.