-
Notifications
You must be signed in to change notification settings - Fork 43
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 #75 from stakwork/feat/cypress-git-action
Feat/cypress git action
- Loading branch information
Showing
12 changed files
with
246 additions
and
7 deletions.
There are no files selected for viewing
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,75 @@ | ||
name: Cypress Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
cypress: | ||
name: Cypress | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Enable docker.host.internal for Ubuntu | ||
run: | | ||
pwd && sudo bash -c 'echo "172.17.0.1 host.docker.internal" >> /etc/hosts' | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Clone Stack | ||
run: | | ||
git clone https://github.com/stakwork/sphinx-stack.git stack | ||
- name: Give Permissions to Sphinx Tribes Frontend | ||
run: chmod 777 -R cypress | ||
|
||
- name: Give Permissions to Stack | ||
working-directory: ./stack | ||
run: | | ||
chmod 777 ./bitcoind; | ||
chmod 777 -R ./relay; | ||
chmod 777 -R ./lnd; | ||
chmod 777 -R ./proxy; | ||
chmod 777 -R ./cln; | ||
- name: Check for NODES | ||
uses: nick-fields/retry@v2 | ||
with: | ||
timeout_minutes: 10 | ||
max_attempts: 3 | ||
command: | | ||
GITACTION_ENV=gitactionenv docker-compose -f ./stack/alts/proxy.yml --project-dir ./stack up -d; | ||
sleep 240; | ||
docker ps | ||
docker logs meme.sphinx | ||
docker logs dave.sphinx | ||
docker wait stack_relaysetup_1 | ||
cat stack/relay/NODES.json; | ||
- name: Copy Node.json | ||
uses: canastro/copy-file-action@master | ||
with: | ||
source: 'stack/relay/NODES.json' | ||
target: 'cypress/fixtures/nodes.json' | ||
|
||
- name: Install Frontend Dependencies | ||
run: yarn install | ||
|
||
- name: Start Server | ||
run: yarn run start:cypress & | ||
|
||
- name: Run Cypress Test | ||
run: | | ||
sleep 20 | ||
yarn run cypress:run | ||
- name: Stop Stack | ||
working-directory: ./stack | ||
run: docker-compose down |
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
# testing | ||
/coverage | ||
cypress/fixtures/nodes.json | ||
cypress/screenshots | ||
|
||
# production | ||
/build | ||
|
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 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); |
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,59 @@ | ||
describe('User Login', () => { | ||
it('User gets to login into the app', () => { | ||
let user; | ||
const userAlias = 'carol'; | ||
let challenge; | ||
let token; | ||
let info; | ||
|
||
cy.fixture('nodes.json').then((json) => { | ||
for (let i = 0; i < json.length; i++) { | ||
if (json[i].alias === userAlias) { | ||
user = json[i]; | ||
} | ||
} | ||
|
||
cy.visit('http://localhost:3007'); | ||
cy.contains('Sign in').click(); | ||
|
||
cy.get('[data-challenge]') | ||
.invoke('attr', 'data-challenge') | ||
.then((value) => { | ||
const array = value?.split('&'); | ||
if (array && array.length === 4) { | ||
challenge = array[2].substring(10); | ||
} | ||
}); | ||
|
||
cy.request({ | ||
method: 'POST', | ||
url: `${user.external_ip}/verify_external`, | ||
headers: { | ||
'x-user-token': `${user.authToken}` | ||
} | ||
}).then((response) => { | ||
token = response.body.response.token; | ||
info = response.body.response.info; | ||
}); | ||
|
||
cy.request({ | ||
method: 'GET', | ||
url: `${user.external_ip}/signer/U98BoaW54IFZlcmlmaWNhdGlvbg==`, | ||
headers: { | ||
'x-user-token': `${user.authToken}` | ||
} | ||
}).then((response) => { | ||
info.url = `${user.external_ip}`; | ||
info['verification_signature'] = response.body.response.sig; | ||
|
||
cy.request({ | ||
method: 'POST', | ||
url: `http://localhost:13000/verify/${challenge}?token=${token}`, | ||
body: info | ||
}).then((response) => {}); | ||
}); | ||
|
||
cy.contains(userAlias).eq(0); | ||
}); | ||
}); | ||
}); |
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,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "[email protected]", | ||
"body": "Fixtures are a great way to mock data for responses to 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************** | ||
// This example commands.ts shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) | ||
// | ||
// declare global { | ||
// namespace Cypress { | ||
// interface Chainable { | ||
// login(email: string, password: string): Chainable<void> | ||
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element> | ||
// } | ||
// } | ||
// } |
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,43 @@ | ||
// *********************************************************** | ||
// This example support/e2e.ts is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands'; | ||
import nodes from '../fixtures/nodes.json'; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
|
||
async function postAllUsersToTribe() { | ||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
try { | ||
await fetch(`${node.external_ip}/profile`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
price_to_meet: 0, | ||
description: `Testing out how this works by ${node.alias}`, | ||
owner_alias: `${node.alias}`, | ||
img: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQR9dAUM-b34F_a6DMw8D6fQ_Y0LUIAVzvfCw&usqp=CAU' | ||
}), | ||
headers: { 'x-user-token': `${node.authToken}` } | ||
}); | ||
} catch (error) { | ||
console.log(`Error creating user on bounty platform: ${JSON.stringify(error)}`); | ||
} | ||
} | ||
} | ||
|
||
postAllUsersToTribe(); |
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
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
"baseUrl": "./src", | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
"src", | ||
], | ||
"exclude": ["cypress"] | ||
} |