Skip to content

Commit

Permalink
test: add e2e tests (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
amagyar-iohk authored Aug 10, 2023
1 parent 61d9dbd commit a9d12e7
Show file tree
Hide file tree
Showing 23 changed files with 5,519 additions and 20 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ jobs:
- name: Build
run: npm run build

- name: Tests with Code Coverage
run: npm run coverage
- name: Publish coverage
uses: ArtiomTr/jest-coverage-report-action@v2
with:
threshold: 30
97 changes: 97 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: End-to-end tests

concurrency:
group: ${{ github.head_ref }}${{ github.ref }}-e2e
cancel-in-progress: true

on:
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
inputs:
mediatorOobUrl:
required: true
description: Mediator out-of-band url
default: https://mediator.rootsid.cloud/oob_url
prismAgentUrl:
required: true
description: Prism-agent server url
default: https://k8s-dev.atalaprism.io/prism-agent
publishedDid:
required: false
description: Published DID
schemaId:
required: false
description: Schema ID
apiKey:
required: false
description: Authorization key
pull_request:
branches:
- master

env:
GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
MEDIATOR_OOB_URL: ${{ inputs.mediatorOobUrl || secrets.MEDIATOR_OOB_URL }}
PRISM_AGENT_URL: ${{ inputs.prismAgentUrl || secrets.PRISM_AGENT_URL }}
PUBLISHED_DID: ${{ inputs.publishedDid || secrets.PUBLISHED_DID }}
SCHEMA_ID: ${{ inputs.schemaId || secrets.SCHEMA_ID }}
APIKEY: ${{ inputs.apiKey || secrets.APIKEY }}
NODE_AUTH_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}

jobs:
run-e2e-tests:
name: "Run"
runs-on: ubuntu-latest

steps:
- name: Mask apikey
run: echo "::add-mask::${{env.APIKEY}}"

- name: Checkout Code
uses: actions/checkout@v3
with:
token: ${{ secrets.ATALA_GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
registry-url: https://npm.pkg.github.com/
scope: "@input-output-hk"

- name: Pack atala-prism-wallet-sdk
if: github.event_name == 'pull_request'
run: |
npm install
npm run build
npm pack
echo "PACKAGE_NAME=$(find . -maxdepth 1 -name input-output* | tr -d '\n')" >> "$GITHUB_ENV"
- name: Install local dependency
if: github.event_name == 'pull_request'
working-directory: integration-tests/e2e-tests
run: |
yarn
yarn add "../../${{ env.PACKAGE_NAME }}"
- name: Run tests
working-directory: integration-tests/e2e-tests
run: |
yarn
yarn test:sdk
yarn test:sdk:report
- name: Add notes to summary
working-directory: integration-tests/e2e-tests
run: cat notes >> $GITHUB_STEP_SUMMARY

- name: Publish Serenity report
uses: actions/upload-artifact@v3
with:
name: atala-prism-sdk-ts.zip
path: integration-tests/e2e-tests/target/site/wallet-sdk-ts
if-no-files-found: error
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,3 @@ jobs:
run: |
npm install
npx semantic-release
- name: Publish artifact
run: npm publish
57 changes: 42 additions & 15 deletions .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,49 @@ branches:
plugins:
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- [ '@semantic-release/changelog', { changelogFile: 'CHANGELOG.md' } ]
- [ '@semantic-release/exec', {
prepareCmd: 'npm version ${nextRelease.version} --git-tag-version false' } ]
- [ '@semantic-release/git', {
assets: [ 'package.json' , 'package-lock.json' , 'CHANGELOG.md' ],
message: 'chore(release): release ${nextRelease.version}
${nextRelease.notes}' } ]
- [ "semantic-release-slack-bot", {
notifyOnSuccess: true,
notifyOnFail: true,
markdownReleaseNotes: true,
onSuccessTemplate: {
text: "A new version of `$package_name` successfully released!\n
- [ '@semantic-release/changelog',
{
changelogFile: 'CHANGELOG.md'
}
]
- [ '@semantic-release/exec',
{
prepareCmd: 'npm version ${nextRelease.version} --git-tag-version false'
}
]
- [ '@semantic-release/exec',
{
prepareCmd: 'npm publish'
}
]
- [ '@semantic-release/exec',
{
prepareCmd: 'yarn --cwd integration-tests/e2e-tests add @input-output-hk/atala-prism-wallet-sdk@^${nextRelease.version}'
}
]
- [ '@semantic-release/git',
{
assets: [
'package.json',
'package-lock.json',
'CHANGELOG.md',
'integration-tests/e2e-tests/**/*'
],
message: 'chore(release): release ${nextRelease.version}\n\n${nextRelease.notes}'
}
]
- [ "semantic-release-slack-bot",
{
notifyOnSuccess: true,
notifyOnFail: true,
markdownReleaseNotes: true,
onSuccessTemplate: {
text: "A new version of `$package_name` successfully released!\n
Version: `$npm_package_version`\n
Tag: $repo_url/releases/tag/v$npm_package_version\n
\n
Release notes:\n
$release_notes" } } ]
$release_notes"
}
}
]
7 changes: 7 additions & 0 deletions integration-tests/e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
target
pluto.db
.DS_Store
.idea
.env*
notes
1 change: 1 addition & 0 deletions integration-tests/e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Wallet SDK - Typescript E2E
13 changes: 13 additions & 0 deletions integration-tests/e2e-tests/config/cucumber.sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
default: [
`--publish-quiet`,
`--format '@serenity-js/cucumber'`,
`--require=tests/sdk/steps/**/*.ts`,
`--require=config/serenity.config.ts`,
`--require-module=ts-node/register`,
'--backtrace'
].join(' '),
glue: [
"tests/sdk/src/**/*.ts"
]
}
35 changes: 35 additions & 0 deletions integration-tests/e2e-tests/config/serenity.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BeforeAll, defineParameterType, setDefaultTimeout } from "@cucumber/cucumber"
import { actorCalled, actorInTheSpotlight, configure } from "@serenity-js/core"

setDefaultTimeout(3 * 60 * 1000)

BeforeAll(async function () {
// Configure Serenity/JS
configure({
crew: [
"@serenity-js/console-reporter",
"@serenity-js/serenity-bdd",
[
"@serenity-js/core:ArtifactArchiver",
{ outputDirectory: "target/site/serenity" },
],
]
})
})

defineParameterType({
// regexp: /[A-Z][a-z]+/,
regexp: /.*/,
transformer(name: string) {
return actorCalled(name);
},
name: 'actor',
});

defineParameterType({
regexp: /he|she|they|his|her|their/,
transformer() {
return actorInTheSpotlight();
},
name: 'pronoun',
});
2 changes: 2 additions & 0 deletions integration-tests/e2e-tests/notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### End-to-end notes:

43 changes: 43 additions & 0 deletions integration-tests/e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "atala-prism-wallet-sdk-ts-e2e",
"version": "1.0.0",
"main": "index.ts",
"scripts": {
"postinstall": "serenity-bdd update",
"clean": "rimraf target",
"test:sdk": "yarn clean && yarn test:sdk:run",
"test:sdk:run": "cucumber-js --config config/cucumber.sdk.js tests/sdk/features -b --exit",
"test:sdk:report": "serenity-bdd run --features tests/sdk/features --destination target/site/wallet-sdk-ts",
"check:deps": "npm-check --skip-unused"
},
"repository": {
"type": "git",
"url": "git+https://github.com/input-output-hk/atala-prism-wallet-sdk-ts-e2e.git"
},
"author": "Allain Magyar",
"license": "ISC",
"bugs": {
"url": "https://github.com/amagyar-iohk/atala-prism-wallet-sdk-ts-e2e/issues"
},
"homepage": "https://github.com/amagyar-iohk/atala-prism-wallet-sdk-ts-e2e#readme",
"dependencies": {
"@cucumber/cucumber": "^9.3.0",
"@input-output-hk/atala-prism-wallet-sdk": "^2.0.3",
"@input-output-hk/prism-typescript-client": "^1.9.2",
"@serenity-js/assertions": "^3.8.0",
"@serenity-js/console-reporter": "^3.8.0",
"@serenity-js/core": "3.8.0",
"@serenity-js/cucumber": "3.8.0",
"@serenity-js/rest": "3.8.0",
"@serenity-js/serenity-bdd": "3.8.0",
"@types/node": "^20.4.7",
"axios": "^1.3.5",
"dotenv": "^16.3.1",
"npm-check": "^6.0.1",
"rimraf": "^5.0.0",
"sql.js": "^1.8.0",
"sqlite3": "^5.1.6",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
19 changes: 19 additions & 0 deletions integration-tests/e2e-tests/tests/Expectations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Expectation } from "@serenity-js/core"

export class Expectations {
static propertyValueToBe = (propertyValue: (actual: any) => string, expected: string) => {
return Expectation.define(
`propertyValueEqualTo`, 'contain a specified attribute value equal to',
(actual: any, expected: string) => {
return propertyValue(actual) == expected
}
)(expected)
}

static equalsTo = Expectation.define(
'isEqualTo', 'is equal to',
(actual: number, expected: number) =>
actual === expected,
)

}
18 changes: 18 additions & 0 deletions integration-tests/e2e-tests/tests/Questions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Question, QuestionAdapter } from "@serenity-js/core"
import { GetRequest, LastResponse, Send } from "@serenity-js/rest"

export class Questions {
static httpGet<T = any>(url: string): QuestionAdapter<T> {
return Question.about('get response body', async actor => {
const request = Send.a(GetRequest.to(url))
await request.performAs(actor)
return await actor.answer(LastResponse.body())
})
}

static getArraySize(description: string, array: any[]): QuestionAdapter<number> {
return Question.about(description, async actor => {
return await actor.answer(array.length)
})
}
}
10 changes: 10 additions & 0 deletions integration-tests/e2e-tests/tests/Utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { appendFile } from "fs";

export class Utils {
static appendToNotes(message: string) {
console.info("Adding to notes:", message)
appendFile("notes", message + "\n", (err) => {
if(err) console.error(err)
})
}
}
11 changes: 11 additions & 0 deletions integration-tests/e2e-tests/tests/sdk/environment.variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {configDotenv} from "dotenv";

configDotenv()

export class EnvironmentVariables {
public static oobUrl: string = process.env.MEDIATOR_OOB_URL!
public static agentUrl: string = process.env.PRISM_AGENT_URL!
public static publishedDid: string = process.env.PUBLISHED_DID!
public static schemaId: string = process.env.SCHEMA_ID!
public static apiKey: string | undefined = process.env.APIKEY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Create connection
The Edge Agent should be able to create a connection to prism-agent

Scenario: Create connection
Given Cloud Agent has a connection invitation
And Cloud Agent shares invitation to Edge Agent
When Edge Agent connects through the invite
Then Cloud Agent should have its status updated
14 changes: 14 additions & 0 deletions integration-tests/e2e-tests/tests/sdk/features/Credential.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Credential
The Edge Agent should be able to receive a credential from Cloud Agent and respond to a proof-of-request

Scenario: Accept credential and respond to present-proof
Given Cloud Agent is connected to Edge Agent
When Cloud Agent offers a credential
Then Edge Agent should receive the credential
When Edge Agent accepts the credential
And Cloud Agent should see the credential was accepted
Then Edge Agent wait to receive an issued credential
And Edge Agent process the issued credential
When Cloud Agent asks for present-proof
And Edge Agent sends the present-proof
Then Cloud Agent should see the present-proof is verified
Loading

0 comments on commit a9d12e7

Please sign in to comment.