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

feat: add acceptance tests #97

Draft
wants to merge 12 commits into
base: 6.6.x
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .github/actions/setup-paypal/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ inputs:
default: "6.6.x"
required: false
description: "Which version/branch of shopware should be used"
env:
description: "Environment for Shopware"
required: true
default: "test"

runs:
using: composite
Expand Down Expand Up @@ -94,6 +98,7 @@ runs:
install: true
install-admin: ${{ inputs.install-admin }}
install-storefront: ${{ inputs.install-storefront }}
env: ${{ inputs.env }}
dependencies: ${{ steps.dependency-list.outputs.deps }}
extraRepositories: ${{ steps.dependency-list.outputs.repos }}
- name: Prepare Administration
Expand Down
11 changes: 11 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ updates:
all:
patterns:
- '*'

- package-ecosystem: npm
directory: '/tests/acceptance'
schedule:
interval: monthly
commit-message:
prefix: 'build: '
groups:
all:
patterns:
- '*'
90 changes: 90 additions & 0 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Acceptance
on:
push:
branches:
- 6.6.x
pull_request:
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
tests:
runs-on: ubuntu-latest
services:
redis:
image: redis:7.0
ports:
- '9200:9200'
mailpit:
image: axllent/mailpit:latest
ports:
- '1025:1025'
- '8025:8025'
env:
APP_ENV: prod
APP_DEBUG: '1'
MAILER_DSN: smtp://localhost:1025
PLUGIN_PATH: './custom/plugins/${{ github.event.repository.name }}'
PAYPAL_CLIENT_ID: ${{ secrets.PAYPAL_CLIENT_ID }}
PAYPAL_CLIENT_SECRET: ${{ secrets.PAYPAL_CLIENT_SECRET }}
PAYPAL_MERCHANT_ID: ${{ secrets.PAYPAL_MERCHANT_ID }}
PAYPAL_SANDBOX: ${{ secrets.PAYPAL_SANDBOX }}
PAYPAL_SETTINGS_TWEAKS: 1
steps:
- name: Checkout SwagPayPal
uses: actions/checkout@v4
with:
path: ${{ env.PLUGIN_PATH }}

- name: Setup SwagPayPal
uses: ./custom/plugins/SwagPayPal/.github/actions/setup-paypal
with:
install-admin: true
install-storefront: true
env: prod

- name: Prepare environment variables
run: |
symfony console cache:clear --env="${APP_ENV}" || true
echo "APP_URL=${APP_URL}" >> "${PLUGIN_PATH}/tests/acceptance/.env"
symfony console integration:create AcceptanceTest --admin >> "${PLUGIN_PATH}/tests/acceptance/.env"

- name: Install playwright
working-directory: ${{ env.PLUGIN_PATH }}/tests/acceptance
run: |
npm ci
npx playwright install --with-deps

- name: Run Playwright
working-directory: ${{ env.PLUGIN_PATH }}/tests/acceptance
run: npx playwright test --reporter=${{ github.event.act && 'line' || 'github' }} --trace=on-first-retry

- uses: actions/upload-artifact@v4
if: always()
with:
name: acceptance-${{ github.event.repository.name }}-${{ github.sha }}
path: ${{ env.PLUGIN_PATH }}/tests/acceptance/test-results/
retention-days: 3

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout SwagPayPal
uses: actions/checkout@v4
with:
path: custom/plugins/${{ github.event.repository.name }}
- name: Setup SwagPayPal
uses: ./custom/plugins/SwagPayPal/.github/actions/setup-paypal
with:
install-admin: false
install-storefront: false
install-commercial: false
- name: Install dependencies
working-directory: ./custom/plugins/SwagPayPal/tests/acceptance
run: npm ci
- name: Run ESLint
working-directory: ./custom/plugins/SwagPayPal/tests/acceptance
run: npm run lint
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
</template>
</sw-single-select>

<sw-password-field
v-else-if="type === 'password'"
v-bind="formAttrs"
:name="path"
:disabled="props.isInherited || disabled"
:value="props.currentValue"
@update:value="props.updateCurrentValue"
>
<template v-if="attrs.hasOwnProperty('hintText')" #hint>
{{ attrs.hintText }}
</template>
</sw-password-field>

<sw-text-field
v-else-if="type === 'string'"
v-bind="formAttrs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default Shopware.Component.wrapComponentConfig({
switch (SystemConfigDefinition[this.path]) {
case 'array': return (value: unknown) => !Array.isArray(value);
case 'boolean': return (value: unknown) => typeof value !== 'boolean';
case 'string': return (value: unknown) => typeof value !== 'string';
case 'string':
case 'password': return (value: unknown) => typeof value !== 'string';
default: throw new Error(`Unhandled or undefined definition for system-config path "${this.path}"`);
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/app/administration/src/types/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export declare type SystemConfig = {
/**
* @private
*/
export const SystemConfigDefinition: Record<SYSTEM_CONFIG, 'string' | 'boolean' | 'array'> = {
export const SystemConfigDefinition: Record<SYSTEM_CONFIG, 'string' | 'password' | 'boolean' | 'array'> = {
'SwagPayPal.settings.clientId': 'string',
'SwagPayPal.settings.clientSecret': 'string',
'SwagPayPal.settings.clientSecret': 'password',
'SwagPayPal.settings.clientIdSandbox': 'string',
'SwagPayPal.settings.clientSecretSandbox': 'string',
'SwagPayPal.settings.clientSecretSandbox': 'password',
'SwagPayPal.settings.merchantPayerId': 'string',
'SwagPayPal.settings.merchantPayerIdSandbox': 'string',
'SwagPayPal.settings.sandbox': 'boolean',
Expand Down
8 changes: 8 additions & 0 deletions tests/acceptance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
.vscode
/test-results/
/playwright-report/
/playwright/.cache/
/playwright/.auth/
.env
tmp
47 changes: 47 additions & 0 deletions tests/acceptance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Setup

Navigate to this directory if you haven't yet.

```
cd tests/acceptance
```

Install the project dependencies.

```
npm install
```

Install Playwright.

```
npx playwright install
npx playwright install-deps
```

Make sure to add the required environment variables to your `.env` file in the acceptance test directory of the PayPal plugin (not the shopware root).

```
APP_URL="<shop base url>"
PAYPAL_CLIENT_ID="<...>"
PAYPAL_CLIENT_SECRET="<...>"
PAYPAL_MERCHANT_ID="<...>"

# optional with default dev setup
SHOPWARE_ACCESS_KEY_ID="<your-api-client-id>"
SHOPWARE_SECRET_ACCESS_KEY="<your-api-secret>"
```

To generate the access key you can use the following Symfony command:

```
bin/console integration:create AcceptanceTest --admin
```

## Running Tests

Navigate to `[paypal-repo]/tests/acceptance` and run:

```
npx playwright test
```
9 changes: 9 additions & 0 deletions tests/acceptance/data-fixtures/DataFixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { mergeTests } from '@shopware-ag/acceptance-test-suite';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface DataFixtureTypes {
}

export const test = mergeTests(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes, it's a skeleton and properly needed in the future - at least it does no harm

);
54 changes: 54 additions & 0 deletions tests/acceptance/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import tseslint from 'typescript-eslint';
import eslint from '@eslint/js';
import playwright from 'eslint-plugin-playwright';
import stylistic from '@stylistic/eslint-plugin';
import globals from 'globals';

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
playwright.configs['flat/recommended'],
stylistic.configs['recommended-flat'],
{
languageOptions: {
ecmaVersion: 'latest',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
globals: globals.node,
},

plugins: { '@stylistic': stylistic },

rules: {
/* stylistic rules */
'@stylistic/semi': ['error', 'always'],
'@stylistic/indent': ['error', 4, { SwitchCase: 1 }],
'@stylistic/member-delimiter-style': ['error'],
'@stylistic/no-multi-spaces': ['error'],
'@stylistic/object-curly-spacing': ['error', 'always'],
'@stylistic/space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
}],
'@stylistic/spaced-comment': ['error', 'always'],
'@stylistic/no-tabs': ['error'],
'@stylistic/no-mixed-spaces-and-tabs': ['error'],
'@stylistic/max-len': 'off',
'@stylistic/quote-props': ['error', 'as-needed'],
'@stylistic/no-extra-semi': ['error'],
'@stylistic/comma-dangle': ['error', 'always-multiline'],
/* stylistic rules */

/* typescript rules */
'@typescript-eslint/no-unused-vars': 'warn',
/* typescript rules */

/* playwright rules */
'playwright/expect-expect': 'off',
/* playwright rules */
},
},
);
13 changes: 13 additions & 0 deletions tests/acceptance/fixtures/AcceptanceTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test as ShopwareTestSuite, mergeTests } from '@shopware-ag/acceptance-test-suite';
import { test as shopCustomerTasks } from '@tasks/ShopCustomerTasks';
import { test as shopAdminTasks } from '@tasks/ShopAdminTasks';
import { test as adminPages } from '@page-objects/AdministrationPages';
import { test as storefrontPages } from '@page-objects/StorefrontPages';

export const test = mergeTests(
ShopwareTestSuite,
shopCustomerTasks,
shopAdminTasks,
adminPages,
storefrontPages,
);
16 changes: 16 additions & 0 deletions tests/acceptance/global.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { FixtureTypes as BaseTypes } from '@shopware-ag/acceptance-test-suite';
import type { AdminPageTypes } from '@page-objects/AdministrationPages';
import type { StorefrontPageTypes } from '@page-objects/StorefrontPages';
import type { DataFixtureTypes } from 'data-fixtures/DataFixtures';
import type { ShopAdminTasks } from '@tasks/ShopAdminTasks';
import type { ShopCustomerTasks } from '@tasks/ShopCustomerTasks';

interface TestFixtureTypes extends AdminPageTypes, StorefrontPageTypes, DataFixtureTypes, ShopAdminTasks, ShopCustomerTasks {
}

declare global {
type Task<Args extends Array<unknown>> = (...args: Args) => () => Promise<void>;

interface FixtureTypes extends Omit<BaseTypes, keyof TestFixtureTypes>, TestFixtureTypes {
}
}
Loading
Loading