Skip to content

Commit

Permalink
Simplified the code for extension
Browse files Browse the repository at this point in the history
Added E2E Tests
  • Loading branch information
Kwok-he-Chu authored Feb 14, 2024
2 parents 24c67c5 + ca53297 commit c5a21f9
Show file tree
Hide file tree
Showing 20 changed files with 1,993 additions and 331 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- .gitignore
- .gitpod.yml
- LICENSE
- playwright.config.js
tags:
- 'v*'

Expand All @@ -27,7 +28,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build & Test Mock Terminal-API Application

on:
workflow_dispatch:
push:
branches: [ main ]
paths-ignore:
- README.md
- '.github/dependabot.yml'
- .dockerignore
- .gitignore
- .gitpod.yml
- LICENSE
pull_request:
branches: [ main ]
paths-ignore:
- README.md
- '.github/dependabot.yml'
- .dockerignore
- .gitignore
- .gitpod.yml
- LICENSE

jobs:
test:
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm ci

- name: Run Mock Terminal-API Application in background (&)
run: npm start &

- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Run Playwright tests
run: npx playwright test

# - name: Upload playwright report
# uses: actions/upload-artifact@v3
# if: always()
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 1
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,8 @@ dist
.yarn/install-state.gz
.pnp.*

# package-lock
package-lock.json
# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ git clone https://github.com/adyen-examples/adyen-mock-terminal-api.git
```


## 2. Run the application
## 2. Run the Application

```
npm install
Expand All @@ -52,6 +52,16 @@ Once you've cloned the example, you can point the application to use `http://loc
2. Alternatively, you can use this stand-alone application and send terminal API requests from within the application.


### Run Docker Image

You can also run the `adyen-mock-terminal-api` in a Docker container which exposes the application on port 3000 (default).


```
# Run on Mac (i.e. --platform linux/arm64/v8)
docker run --rm -d --name adyen-mock-terminal-api -p 3000:3000 -e PORT=3000 ghcr.io/adyen-examples/adyen-mock-terminal-api:main
```


## Contributing

Expand All @@ -64,14 +74,12 @@ We commit all our new features directly into our GitHub repository. Feel free to
2. The example below adds `paymentRequest.json` and `paymentResponse.json` (prefixed by `payment`). The `src/routes/services/payloadService` will automatically add this payload if the JSON is valid.
- Add your `Request` to `/public/payloads/**{payment}**/paymentRequest
- Add your `Response` to `/public/payloads/**{payment}**/paymentResponse
- Note: Every `-Request` should have a `-Response`. Except for those that require some kind of logic (f.e. "paymentBusyResponse").
3. In `/src/routes/apiRoutes.js`, find the `/sync`-endpoint and the following code snippet. Notice these two lines: `req.body.SaleToPOIRequest.PaymentRequest` and `payloadService.getResponseByPrefix("payment")`.
- Note: Every `-Request` should have a `-Response`. Except for those that require some kind of (state) logic (f.e. "paymentBusyResponse" triggers when a payment request is in-progress).
3. In `/src/routes/defaultRoutes.js`, find the `/sync`-endpoint and the following code snippet:

```js
if (req.body.SaleToPOIRequest.PaymentRequest) {
response = payloadService.getResponseByPrefix("payment");
storageService.setLastResponse(response);
res.status(200).send(response);
sendResponse(res, "payment");
return;
}
```
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const express = require('express');
const handlebars = require('express-handlebars');
const path = require('path');
const apiRoutes = require('./src/routes/apiRoutes');
const defaultRoutes = require('./src/routes/defaultRoutes');
const userInteractionRoutes = require('./src/routes/userInteractionRoutes');

const port = process.env.PORT || 3000;

Expand All @@ -27,6 +28,7 @@ app.engine("hbs", handlebars({
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "src", "views"));

app.use("/", apiRoutes);
app.use("/", defaultRoutes);
app.use("/user-interaction", userInteractionRoutes);

app.listen(port, () => console.log(`Server started -> http://localhost:${port}`));
Loading

0 comments on commit c5a21f9

Please sign in to comment.