From 323291753a4a9f3f8c09f9d08933d5740799d7a2 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Thu, 23 Feb 2023 16:39:48 +0000 Subject: [PATCH 1/8] Add tests to capture - https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/92 - https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/93 --- dev/tests/acceptance/CheckoutCest.php | 144 ++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/dev/tests/acceptance/CheckoutCest.php b/dev/tests/acceptance/CheckoutCest.php index b903e68..8fa7111 100644 --- a/dev/tests/acceptance/CheckoutCest.php +++ b/dev/tests/acceptance/CheckoutCest.php @@ -90,6 +90,150 @@ public function preventStockDeductionOnOrderShipment(Step\Acceptance\Magento $I) $I->assertEquals(97, $newQty, 'The quantity should have been decremented on creation of the order and not changed since that point'); } + /** + * @depends noInventoryIsReservedAndStockHasBeenDeducted + * @param Step\Acceptance\Magento $I + * + * @link https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/93#issuecomment-1362938362 + */ + public function preventDoubleRefundQuantityOnShippedOrder(Step\Acceptance\Magento $I) + { + $productId = $I->createSimpleProduct('amp_stock_refund_double_quantity', 100); + + $cartId = $I->getGuestQuote(); + $I->addSimpleProductToQuote($cartId, 'amp_stock_refund_double_quantity', 5); + $orderId = $I->completeGuestCheckout($cartId); + + $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); + $I->assertEquals(95, $newQty); + + $I->amBearerAuthenticated(Step\Acceptance\Magento::ACCESS_TOKEN); + $I->haveHttpHeader('Content-Type', 'application/json'); + // If the payment method chosen is banktransfer, you must invoice the order + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/invoice", json_encode([ + "capture" => true, + "notify" => false + ])); + + // Ship the order by creating a sales_shipment + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/ship"); + + $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); + $I->assertEquals(95, $newQty, 'The quantity should have been decremented on creation of the order'); + + $orderItemId = $I->grabFromDatabase('sales_order_item', 'item_id', ['order_id' => $orderId]); + //Create a creditmemo from the invoice and make sure to check the "Return to stock" checkbox + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/refund", json_encode([ + "items" => [ + [ + "order_item_id" => $orderItemId, + "qty" => 5 + ] + ], + "notify" => false, + "arguments" => [ + "shipping_amount" => 0, + "adjustment_positive" => 0, + "adjustment_negative" => 0, + "extension_attributes" => [ + "return_to_stock_items" => [ + $orderItemId + ] + ] + ] + ])); + + $refundedQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); + $I->assertEquals(100, $refundedQty, 'The quantity should be reset to 100 after the refund'); + } + + /** + * @link https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/92 + * + * @depends stockIsReturnedWhenOrderIsCancelled + * @param Step\Acceptance\Magento $I + */ + public function productGoesBackInStockWhenOrderIsRefunded(Step\Acceptance\Magento $I) + { + $productId = $I->createSimpleProduct('amp_stock_returns_in_stock_on_refund',1); + $I->assertEquals( + 1, + $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), + 'Product has not started with qty=1' + ); + $I->assertEquals( + 1, + $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), + 'Product has not started with is_in_stock=1' + ); + + $cartId = $I->getGuestQuote(); + $I->addSimpleProductToQuote($cartId, 'amp_stock_returns_in_stock_on_refund', 1); + $orderId = $I->completeGuestCheckout($cartId); + + $I->assertEquals( + 0, + $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), + 'Product did not go qty=0 after an order' + ); + $I->assertEquals( + 0, + $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), + 'Product did not go is_in_stock=0 after an order' + ); + + $I->amBearerAuthenticated(Step\Acceptance\Magento::ACCESS_TOKEN); + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/invoice", json_encode([ + "capture" => true, + "notify" => false + ])); + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/ship"); + + $I->assertEquals( + 0, + $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), + 'Product did not stay qty=0 after invoicing and shipping' + ); + $I->assertEquals( + 0, + $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), + 'Product did not stay is_in_stock=0 after invoicing and shipping' + ); + + $orderItemId = $I->grabFromDatabase('sales_order_item', 'item_id', ['order_id' => $orderId]); + + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/refund", json_encode([ + "items" => [ + [ + "order_item_id" => $orderItemId, + "qty" => 1 + ] + ], + "notify" => false, + "arguments" => [ + "shipping_amount" => 0, + "adjustment_positive" => 0, + "adjustment_negative" => 0, + "extension_attributes" => [ + "return_to_stock_items" => [ + $orderItemId + ] + ] + ] + ])); + + $I->assertEquals( + 1, + $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), + 'Product did not go to is_in_stock=1 after a refund' + ); + $I->assertEquals( + 1, + $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), + 'Product did not go to qty=1 after a refund' + ); + } + /** * @depends noInventoryIsReservedAndStockHasBeenDeducted * @param Step\Acceptance\Magento $I From 0a3c9f44f9850d37a57d6f590d58396af3d1e48b Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 13 Mar 2023 14:59:59 +0000 Subject: [PATCH 2/8] Update test runners --- .travis.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea4db83..c73760b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,17 +6,20 @@ git: depth: false dist: xenial env: - - TEST_GROUP=magento_latest + - TEST_GROUP=magento_245 - TEST_GROUP=magento_242 + - TEST_GROUP=magento_244 - TEST_GROUP=magento_23 jobs: exclude: - php: 8.1 env: TEST_GROUP=magento_23 + - php: 8.1 + env: TEST_GROUP=magento_244 - php: 8.1 env: TEST_GROUP=magento_242 - php: 7.4 - env: TEST_GROUP=magento_latest + env: TEST_GROUP=magento_245 install: @@ -27,10 +30,11 @@ install: # Magento coding standard check - vendor/bin/phpcs -s --standard=./ruleset.xml src/ # Install magento - - if [[ $TEST_GROUP = magento_242 ]]; then NAME=disablestockres VERSION=2.4.2 . ./vendor/bin/travis-install-magento.sh; fi - if [[ $TEST_GROUP = magento_23 ]]; then NAME=disablestockres VERSION=2.3.7-p2 . ./vendor/bin/travis-install-magento.sh; fi - - if [[ $TEST_GROUP = magento_latest ]]; then magerun2 self-update; fi - - if [[ $TEST_GROUP = magento_latest ]]; then NAME=disablestockres . ./vendor/bin/travis-install-magento.sh; fi + - if [[ $TEST_GROUP = magento_242 ]]; then NAME=disablestockres VERSION=2.4.2 . ./vendor/bin/travis-install-magento.sh; fi + - if [[ $TEST_GROUP = magento_244 ]]; then NAME=disablestockres VERSION=2.4.4-p2 . ./vendor/bin/travis-install-magento.sh; fi + - if [[ $TEST_GROUP = magento_245 ]]; then magerun2 self-update; fi + - if [[ $TEST_GROUP = magento_245 ]]; then NAME=disablestockres VERSION=2.4.5 . ./vendor/bin/travis-install-magento.sh; fi # Install this module - cd vendor/ampersand/travis-vanilla-magento/instances/disablestockres - export COMPOSER_MEMORY_LIMIT=-1 From 3ad2ff611a99da59c4a6f71faa0c4331f37c6ffc Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 13 Mar 2023 15:12:28 +0000 Subject: [PATCH 3/8] Update test runners --- .travis.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c73760b..17db977 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,16 +6,19 @@ git: depth: false dist: xenial env: - - TEST_GROUP=magento_245 + - TEST_GROUP=magento_23 - TEST_GROUP=magento_242 + - TEST_GROUP=magento_243 - TEST_GROUP=magento_244 - - TEST_GROUP=magento_23 + - TEST_GROUP=magento_245 jobs: exclude: - php: 8.1 env: TEST_GROUP=magento_23 - php: 8.1 env: TEST_GROUP=magento_244 + - php: 8.1 + env: TEST_GROUP=magento_243 - php: 8.1 env: TEST_GROUP=magento_242 - php: 7.4 @@ -31,7 +34,8 @@ install: - vendor/bin/phpcs -s --standard=./ruleset.xml src/ # Install magento - if [[ $TEST_GROUP = magento_23 ]]; then NAME=disablestockres VERSION=2.3.7-p2 . ./vendor/bin/travis-install-magento.sh; fi - - if [[ $TEST_GROUP = magento_242 ]]; then NAME=disablestockres VERSION=2.4.2 . ./vendor/bin/travis-install-magento.sh; fi + - if [[ $TEST_GROUP = magento_242 ]]; then NAME=disablestockres VERSION=2.4.2-p2 . ./vendor/bin/travis-install-magento.sh; fi + - if [[ $TEST_GROUP = magento_243 ]]; then NAME=disablestockres VERSION=2.4.3-p3 . ./vendor/bin/travis-install-magento.sh; fi - if [[ $TEST_GROUP = magento_244 ]]; then NAME=disablestockres VERSION=2.4.4-p2 . ./vendor/bin/travis-install-magento.sh; fi - if [[ $TEST_GROUP = magento_245 ]]; then magerun2 self-update; fi - if [[ $TEST_GROUP = magento_245 ]]; then NAME=disablestockres VERSION=2.4.5 . ./vendor/bin/travis-install-magento.sh; fi From d30a95a64e52e328159b18252ae9c363d111aad1 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 3 Apr 2023 14:20:05 +0100 Subject: [PATCH 4/8] Use docker for testing --- .travis.yml | 101 ++++++-------------------- composer.json | 13 +++- dev/README.MD | 23 ++++++ dev/codeception.MD | 16 ---- dev/tests/acceptance/CheckoutCest.php | 1 + 5 files changed, 58 insertions(+), 96 deletions(-) create mode 100644 dev/README.MD delete mode 100644 dev/codeception.MD diff --git a/.travis.yml b/.travis.yml index 17db977..3c8feb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,97 +1,40 @@ language: php -php: - - 7.4 - - 8.1 -git: - depth: false -dist: xenial +php: 8.1 + env: - - TEST_GROUP=magento_23 - - TEST_GROUP=magento_242 - - TEST_GROUP=magento_243 - - TEST_GROUP=magento_244 - - TEST_GROUP=magento_245 -jobs: - exclude: - - php: 8.1 - env: TEST_GROUP=magento_23 - - php: 8.1 - env: TEST_GROUP=magento_244 - - php: 8.1 - env: TEST_GROUP=magento_243 - - php: 8.1 - env: TEST_GROUP=magento_242 - - php: 7.4 - env: TEST_GROUP=magento_245 + - TEST_GROUP=2-3-7 + - TEST_GROUP=2-3-7 + - TEST_GROUP=2-4-0 + - TEST_GROUP=2-4-1 + - TEST_GROUP=2-4-2 + - TEST_GROUP=2-4-3 + - TEST_GROUP=2-4-5 + - TEST_GROUP=2-4-6 + - TEST_GROUP=2-latest +before_install: + - travis_retry wget https://github.com/docker/compose/releases/download/v2.17.0/docker-compose-linux-x86_64 + - sudo mv docker-compose-linux-x86_64 /usr/libexec/docker/cli-plugins/docker-compose + - sudo chmod +x /usr/libexec/docker/cli-plugins/docker-compose + - docker --version && docker compose version install: -# Composer install - composer install --no-interaction -# Do a quick code style check - PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --dry-run --rules=@PSR2 --diff src/ -# Magento coding standard check - vendor/bin/phpcs -s --standard=./ruleset.xml src/ -# Install magento - - if [[ $TEST_GROUP = magento_23 ]]; then NAME=disablestockres VERSION=2.3.7-p2 . ./vendor/bin/travis-install-magento.sh; fi - - if [[ $TEST_GROUP = magento_242 ]]; then NAME=disablestockres VERSION=2.4.2-p2 . ./vendor/bin/travis-install-magento.sh; fi - - if [[ $TEST_GROUP = magento_243 ]]; then NAME=disablestockres VERSION=2.4.3-p3 . ./vendor/bin/travis-install-magento.sh; fi - - if [[ $TEST_GROUP = magento_244 ]]; then NAME=disablestockres VERSION=2.4.4-p2 . ./vendor/bin/travis-install-magento.sh; fi - - if [[ $TEST_GROUP = magento_245 ]]; then magerun2 self-update; fi - - if [[ $TEST_GROUP = magento_245 ]]; then NAME=disablestockres VERSION=2.4.5 . ./vendor/bin/travis-install-magento.sh; fi -# Install this module - - cd vendor/ampersand/travis-vanilla-magento/instances/disablestockres - - export COMPOSER_MEMORY_LIMIT=-1 - - composer config repo.disablestockres git "../../../../../" - - composer require -vvv ampersand/magento2-disable-stock-reservation:"dev-$TRAVIS_BRANCH" || composer require -vvv ampersand/magento2-disable-stock-reservation $TRAVIS_BRANCH - - php bin/magento setup:upgrade -# compile magento - - php bin/magento setup:di:compile -# Set up test configuration - - magerun2 config:store:set oauth/consumer/enable_integration_as_bearer 1 - - magerun2 config:store:set checkout/options/guest_checkout 1 - - magerun2 config:store:set payment/checkmo/active 1 - - magerun2 integration:create disablestockres example@example.com https://example.com --access-token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - - magerun2 cache:flush -# warm caches - - php bin/magento - - magerun2 sys:info - - cd - - -before_install: - - if [ ! "$TRAVIS_PULL_REQUEST" = "false" ]; then git branch; git branch -D "$TRAVIS_BRANCH" || true; git checkout -b "$TRAVIS_BRANCH"; fi - - composer self-update --2 - - mkdir -p $HOME/bin/ -# Install magerun2 - - test -f $HOME/bin/magerun2 || (mkdir -p $HOME/bin/ && wget https://files.magerun.net/n98-magerun2-4.9.1.phar && chmod +x n98-magerun2-4.9.1.phar && mv n98-magerun2-4.9.1.phar $HOME/bin/magerun2) - + - CURRENT_EXTENSION="." FULL_INSTALL=1 vendor/bin/mtest-make $TEST_GROUP script: - - ADDITIONAL_ARGS="-v" - - if [[ $TRAVIS_COMMIT_MESSAGE == *"VERBOSE"* ]]; then ADDITIONAL_ARGS="-vvv"; fi; - - ./vendor/bin/codecept build -c dev - - URL="https://magento-disablestockres.localhost/" MYSQL_USER="root" MYSQL_HOST="127.0.0.1" MYSQL_DB="databasedisablestockres" MYSQL_PORT="3306" ./vendor/bin/codecept run acceptance -c dev $ADDITIONAL_ARGS - -addons: - apt: - packages: - - postfix - - apache2 - - libapache2-mod-fastcgi - -services: - - mysql - - elasticsearch + - composer docker-configure-magento + - composer docker-run-codeception cache: - apt: true directories: - $HOME/.composer/cache - $HOME/bin after_failure: - - test -d ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/report/ && for r in ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/report/*; do cat $r; done - - test -f ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/system.log && grep -v "Broken reference" ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/system.log - - test -f ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/exception.log && cat ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/exception.log - - test -f ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/support_report.log && grep -v "Broken reference" ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/support_report.log + - vendor/bin/mtest 'for r in ./var/report/*; do cat $r; done' + - vendor/bin/mtest 'cat /var/www/html/var/log/*.log' + - docker ps - sleep 10; # give log files time to render diff --git a/composer.json b/composer.json index 8186404..a768b4b 100644 --- a/composer.json +++ b/composer.json @@ -30,12 +30,23 @@ "codeception/module-phpbrowser": "^1.0.0", "codeception/module-asserts": "^1.1.0", "codeception/module-db": "^1.0.1", - "ampersand/travis-vanilla-magento": "^1.0", + "ampersand/magento-docker-test-instance": "^0.1", "codeception/module-rest": "^1.2.0", "friendsofphp/php-cs-fixer": "^2.16", "magento/magento-coding-standard": "<16" }, "scripts": { + "docker-configure-magento": [ + "vendor/bin/mtest 'vendor/bin/n98-magerun2 config:store:set checkout/options/guest_checkout 1'", + "vendor/bin/mtest 'vendor/bin/n98-magerun2 config:store:set payment/checkmo/active 1'", + "vendor/bin/mtest 'vendor/bin/n98-magerun2 config:store:set oauth/consumer/enable_integration_as_bearer 1'", + "vendor/bin/mtest 'vendor/bin/n98-magerun2 integration:create disablestockres example@example.com https://example.com --access-token=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'", + "vendor/bin/mtest 'php bin/magento cache:flush'", + "vendor/bin/mtest 'php bin/magento --version'" + ], + "docker-run-codeception": [ + "URL=\"http://0.0.0.0:1234/\" MYSQL_USER=\"root\" MYSQL_HOST=\"0.0.0.0\" MYSQL_DB=\"magento\" MYSQL_PORT=\"1235\" ./dev/run-codeception.sh" + ], "post-install-cmd": [ "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)" ], diff --git a/dev/README.MD b/dev/README.MD new file mode 100644 index 0000000..5414e18 --- /dev/null +++ b/dev/README.MD @@ -0,0 +1,23 @@ +**Do not run these tests in production, they delete from and insert into your database as well as generate an integration token.** + +To run these tests locally you will need to get a copy of the repo +``` +git clone https://github.com/AmpersandHQ/magento2-disable-stock-reservation/ +cd magento2-disable-stock-reservation +``` + +Boot the docker test instance for testing against (run `./vendor/bin/mtest-make` to see supported versions) +``` +CURRENT_EXTENSION="." FULL_INSTALL=1 vendor/bin/mtest-make 2-4-5 +``` + +Configure magento test settings +``` +composer docker-configure-magento +``` + +Run the tests +``` +composer docker-run-codeception +``` + diff --git a/dev/codeception.MD b/dev/codeception.MD deleted file mode 100644 index 9596cf7..0000000 --- a/dev/codeception.MD +++ /dev/null @@ -1,16 +0,0 @@ -**Do not run these tests in production, they delete from and insert into your database as well as generate an integration token.** - -To run these tests locally you will need to - -1. Install a vanilla magento instance locally -2. Install this module, run `setup:upgrade` -3. `magerun2 config:store:set checkout/options/guest_checkout 1` -4. `magerun2 config:store:set payment/checkmo/active 1` -5. `magerun2 config:store:set oauth/consumer/enable_integration_as_bearer 1` -6. `magerun2 integration:create disablestockres example@example.com https://example.com --access-token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"` -7. `magerun2 cache:flush` -8. Run with the appropriate environment vars set, - - ``` - URL="https://magento-community-245.ampdev.co/" MYSQL_USER="root" MYSQL_HOST="127.0.0.1" MYSQL_DB="community2.4.5" MYSQL_PORT="24010" ./dev/run-codeception.sh - ``` diff --git a/dev/tests/acceptance/CheckoutCest.php b/dev/tests/acceptance/CheckoutCest.php index 8fa7111..0776793 100644 --- a/dev/tests/acceptance/CheckoutCest.php +++ b/dev/tests/acceptance/CheckoutCest.php @@ -8,6 +8,7 @@ class CheckoutCest public function dependenciesAreConfigured(Step\Acceptance\Magento $I) { $I->seeNumRecords(1, 'inventory_source'); + $I->seeInDatabase('core_config_data', ['path' => 'oauth/consumer/enable_integration_as_bearer', 'value' => '1']); $I->seeInDatabase('core_config_data', ['path' => 'checkout/options/guest_checkout', 'value' => '1']); $I->seeInDatabase('core_config_data', ['path' => 'payment/checkmo/active', 'value' => '1']); $I->seeInDatabase('oauth_token', ['token' => Step\Acceptance\Magento::ACCESS_TOKEN]); From af2fe5da5c3cc66a1d505fbe1079490f328849e2 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 3 Apr 2023 16:52:06 +0100 Subject: [PATCH 5/8] Update test code --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++++ .travis.yml | 5 ++--- dev/run-codeception.sh | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..a2748e2 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,4 @@ +### Checklist +- [ ] Pull request has a meaningful description of its purpose, include affected Magento versions if it is a bug. +- [ ] All commits are accompanied by meaningful commit messages +- [ ] Tests have been ran / updated (see `./dev/README.md` for how to run tests) \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 3c8feb1..45dcd28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,15 +2,14 @@ language: php php: 8.1 env: - - TEST_GROUP=2-3-7 - TEST_GROUP=2-3-7 - TEST_GROUP=2-4-0 - TEST_GROUP=2-4-1 - TEST_GROUP=2-4-2 - TEST_GROUP=2-4-3 + - TEST_GROUP=2-4-4 - TEST_GROUP=2-4-5 - TEST_GROUP=2-4-6 - - TEST_GROUP=2-latest before_install: - travis_retry wget https://github.com/docker/compose/releases/download/v2.17.0/docker-compose-linux-x86_64 @@ -34,7 +33,7 @@ cache: - $HOME/bin after_failure: - - vendor/bin/mtest 'for r in ./var/report/*; do cat $r; done' + - vendor/bin/mtest 'for r in /var/www/html/var/report/*; do cat $r; done' - vendor/bin/mtest 'cat /var/www/html/var/log/*.log' - docker ps - sleep 10; # give log files time to render diff --git a/dev/run-codeception.sh b/dev/run-codeception.sh index ac46551..78d473d 100755 --- a/dev/run-codeception.sh +++ b/dev/run-codeception.sh @@ -3,4 +3,4 @@ DIR_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" $DIR_BASE/../vendor/bin/codecept build -c dev -$DIR_BASE/../vendor/bin/codecept run acceptance -c dev $1 -vvv +$DIR_BASE/../vendor/bin/codecept run acceptance -c dev $1 -v From 8edc4406df36f24cec0aed6e31bc5f31357b2f8d Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 3 Apr 2023 16:53:50 +0100 Subject: [PATCH 6/8] Add `allow_failures` in travis --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 45dcd28..8fcaac8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,13 @@ env: - TEST_GROUP=2-4-5 - TEST_GROUP=2-4-6 +jobs: + allow_failures: + - env: TEST_GROUP=2-4-3 + - env: TEST_GROUP=2-4-4 + - env: TEST_GROUP=2-4-5 + - env: TEST_GROUP=2-4-6 + before_install: - travis_retry wget https://github.com/docker/compose/releases/download/v2.17.0/docker-compose-linux-x86_64 - sudo mv docker-compose-linux-x86_64 /usr/libexec/docker/cli-plugins/docker-compose From 6eb20bbaa964457deed12f6ab2f5d91bc616886f Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 3 Apr 2023 17:15:30 +0100 Subject: [PATCH 7/8] Add refund test `Refund on shipped order does not affect quantity when not returned to stock` Verify that when a refund on a shipped order occurs but the `return_to_stock_items` is not set, that nothing happens. --- dev/tests/acceptance/CheckoutCest.php | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/dev/tests/acceptance/CheckoutCest.php b/dev/tests/acceptance/CheckoutCest.php index 0776793..5bf5cfd 100644 --- a/dev/tests/acceptance/CheckoutCest.php +++ b/dev/tests/acceptance/CheckoutCest.php @@ -148,6 +148,56 @@ public function preventDoubleRefundQuantityOnShippedOrder(Step\Acceptance\Magent $I->assertEquals(100, $refundedQty, 'The quantity should be reset to 100 after the refund'); } + /** + * @depends noInventoryIsReservedAndStockHasBeenDeducted + * @param Step\Acceptance\Magento $I + */ + public function refundOnShippedOrderDoesNotAffectQuantityWhenNotReturnedToStock(Step\Acceptance\Magento $I) + { + $productId = $I->createSimpleProduct('amp_stock_refund_double_quantity_not_returned', 100); + + $cartId = $I->getGuestQuote(); + $I->addSimpleProductToQuote($cartId, 'amp_stock_refund_double_quantity_not_returned', 5); + $orderId = $I->completeGuestCheckout($cartId); + + $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); + $I->assertEquals(95, $newQty); + + $I->amBearerAuthenticated(Step\Acceptance\Magento::ACCESS_TOKEN); + $I->haveHttpHeader('Content-Type', 'application/json'); + // If the payment method chosen is banktransfer, you must invoice the order + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/invoice", json_encode([ + "capture" => true, + "notify" => false + ])); + + // Ship the order by creating a sales_shipment + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/ship"); + + $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); + $I->assertEquals(95, $newQty, 'The quantity should have been decremented on creation of the order'); + + $orderItemId = $I->grabFromDatabase('sales_order_item', 'item_id', ['order_id' => $orderId]); + //Create a creditmemo from the invoice and make sure return_to_stock_items is not set + $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/refund", json_encode([ + "items" => [ + [ + "order_item_id" => $orderItemId, + "qty" => 5 + ] + ], + "notify" => false, + "arguments" => [ + "shipping_amount" => 0, + "adjustment_positive" => 0, + "adjustment_negative" => 0 + ] + ])); + + $refundedQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); + $I->assertEquals(95, $refundedQty, 'The quantity should remain at 95 when not returned'); + } + /** * @link https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/92 * From fdff1d2f7237e45bfff808a2e0bad5b595e29da0 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 3 Apr 2023 17:52:03 +0100 Subject: [PATCH 8/8] Remove tests for clear baseline Temporarily remove tests, going to reintroduce them during their own PRs while they are relevant --- .travis.yml | 12 +- dev/tests/acceptance/CheckoutCest.php | 194 -------------------------- 2 files changed, 6 insertions(+), 200 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fcaac8..39d4e5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,12 +11,12 @@ env: - TEST_GROUP=2-4-5 - TEST_GROUP=2-4-6 -jobs: - allow_failures: - - env: TEST_GROUP=2-4-3 - - env: TEST_GROUP=2-4-4 - - env: TEST_GROUP=2-4-5 - - env: TEST_GROUP=2-4-6 +#jobs: +# allow_failures: +# - env: TEST_GROUP=2-4-3 +# - env: TEST_GROUP=2-4-4 +# - env: TEST_GROUP=2-4-5 +# - env: TEST_GROUP=2-4-6 before_install: - travis_retry wget https://github.com/docker/compose/releases/download/v2.17.0/docker-compose-linux-x86_64 diff --git a/dev/tests/acceptance/CheckoutCest.php b/dev/tests/acceptance/CheckoutCest.php index 5bf5cfd..136300a 100644 --- a/dev/tests/acceptance/CheckoutCest.php +++ b/dev/tests/acceptance/CheckoutCest.php @@ -91,200 +91,6 @@ public function preventStockDeductionOnOrderShipment(Step\Acceptance\Magento $I) $I->assertEquals(97, $newQty, 'The quantity should have been decremented on creation of the order and not changed since that point'); } - /** - * @depends noInventoryIsReservedAndStockHasBeenDeducted - * @param Step\Acceptance\Magento $I - * - * @link https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/93#issuecomment-1362938362 - */ - public function preventDoubleRefundQuantityOnShippedOrder(Step\Acceptance\Magento $I) - { - $productId = $I->createSimpleProduct('amp_stock_refund_double_quantity', 100); - - $cartId = $I->getGuestQuote(); - $I->addSimpleProductToQuote($cartId, 'amp_stock_refund_double_quantity', 5); - $orderId = $I->completeGuestCheckout($cartId); - - $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); - $I->assertEquals(95, $newQty); - - $I->amBearerAuthenticated(Step\Acceptance\Magento::ACCESS_TOKEN); - $I->haveHttpHeader('Content-Type', 'application/json'); - // If the payment method chosen is banktransfer, you must invoice the order - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/invoice", json_encode([ - "capture" => true, - "notify" => false - ])); - - // Ship the order by creating a sales_shipment - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/ship"); - - $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); - $I->assertEquals(95, $newQty, 'The quantity should have been decremented on creation of the order'); - - $orderItemId = $I->grabFromDatabase('sales_order_item', 'item_id', ['order_id' => $orderId]); - //Create a creditmemo from the invoice and make sure to check the "Return to stock" checkbox - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/refund", json_encode([ - "items" => [ - [ - "order_item_id" => $orderItemId, - "qty" => 5 - ] - ], - "notify" => false, - "arguments" => [ - "shipping_amount" => 0, - "adjustment_positive" => 0, - "adjustment_negative" => 0, - "extension_attributes" => [ - "return_to_stock_items" => [ - $orderItemId - ] - ] - ] - ])); - - $refundedQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); - $I->assertEquals(100, $refundedQty, 'The quantity should be reset to 100 after the refund'); - } - - /** - * @depends noInventoryIsReservedAndStockHasBeenDeducted - * @param Step\Acceptance\Magento $I - */ - public function refundOnShippedOrderDoesNotAffectQuantityWhenNotReturnedToStock(Step\Acceptance\Magento $I) - { - $productId = $I->createSimpleProduct('amp_stock_refund_double_quantity_not_returned', 100); - - $cartId = $I->getGuestQuote(); - $I->addSimpleProductToQuote($cartId, 'amp_stock_refund_double_quantity_not_returned', 5); - $orderId = $I->completeGuestCheckout($cartId); - - $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); - $I->assertEquals(95, $newQty); - - $I->amBearerAuthenticated(Step\Acceptance\Magento::ACCESS_TOKEN); - $I->haveHttpHeader('Content-Type', 'application/json'); - // If the payment method chosen is banktransfer, you must invoice the order - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/invoice", json_encode([ - "capture" => true, - "notify" => false - ])); - - // Ship the order by creating a sales_shipment - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/ship"); - - $newQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); - $I->assertEquals(95, $newQty, 'The quantity should have been decremented on creation of the order'); - - $orderItemId = $I->grabFromDatabase('sales_order_item', 'item_id', ['order_id' => $orderId]); - //Create a creditmemo from the invoice and make sure return_to_stock_items is not set - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/refund", json_encode([ - "items" => [ - [ - "order_item_id" => $orderItemId, - "qty" => 5 - ] - ], - "notify" => false, - "arguments" => [ - "shipping_amount" => 0, - "adjustment_positive" => 0, - "adjustment_negative" => 0 - ] - ])); - - $refundedQty = $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]); - $I->assertEquals(95, $refundedQty, 'The quantity should remain at 95 when not returned'); - } - - /** - * @link https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/92 - * - * @depends stockIsReturnedWhenOrderIsCancelled - * @param Step\Acceptance\Magento $I - */ - public function productGoesBackInStockWhenOrderIsRefunded(Step\Acceptance\Magento $I) - { - $productId = $I->createSimpleProduct('amp_stock_returns_in_stock_on_refund',1); - $I->assertEquals( - 1, - $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), - 'Product has not started with qty=1' - ); - $I->assertEquals( - 1, - $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), - 'Product has not started with is_in_stock=1' - ); - - $cartId = $I->getGuestQuote(); - $I->addSimpleProductToQuote($cartId, 'amp_stock_returns_in_stock_on_refund', 1); - $orderId = $I->completeGuestCheckout($cartId); - - $I->assertEquals( - 0, - $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), - 'Product did not go qty=0 after an order' - ); - $I->assertEquals( - 0, - $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), - 'Product did not go is_in_stock=0 after an order' - ); - - $I->amBearerAuthenticated(Step\Acceptance\Magento::ACCESS_TOKEN); - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/invoice", json_encode([ - "capture" => true, - "notify" => false - ])); - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/ship"); - - $I->assertEquals( - 0, - $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), - 'Product did not stay qty=0 after invoicing and shipping' - ); - $I->assertEquals( - 0, - $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), - 'Product did not stay is_in_stock=0 after invoicing and shipping' - ); - - $orderItemId = $I->grabFromDatabase('sales_order_item', 'item_id', ['order_id' => $orderId]); - - $I->sendPOSTAndVerifyResponseCodeIs200("V1/order/{$orderId}/refund", json_encode([ - "items" => [ - [ - "order_item_id" => $orderItemId, - "qty" => 1 - ] - ], - "notify" => false, - "arguments" => [ - "shipping_amount" => 0, - "adjustment_positive" => 0, - "adjustment_negative" => 0, - "extension_attributes" => [ - "return_to_stock_items" => [ - $orderItemId - ] - ] - ] - ])); - - $I->assertEquals( - 1, - $I->grabFromDatabase('cataloginventory_stock_item', 'is_in_stock', ['product_id' => $productId]), - 'Product did not go to is_in_stock=1 after a refund' - ); - $I->assertEquals( - 1, - $I->grabFromDatabase('cataloginventory_stock_item', 'qty', ['product_id' => $productId]), - 'Product did not go to qty=1 after a refund' - ); - } - /** * @depends noInventoryIsReservedAndStockHasBeenDeducted * @param Step\Acceptance\Magento $I