diff --git a/.env.example b/.env.example index c6f395a..5af894a 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,2 @@ PRIVATE_KEY= -HOSTNAME= \ No newline at end of file +HOSTCHAIN= \ No newline at end of file diff --git a/README.md b/README.md index 2c5d269..486fdac 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### First we need to create a file called "SYNPRESS_PRIVATEKEY" and place the test wallet's private key. This is because the synpress lib doesn't recognize the .env ### Now we need to start the BeproService, to use some ganache services -### For this we will add the private_key and hostname to the .env and start the server with the command: +### For this we will add the private_key and hostchain to the .env and start the server with the command: ``` npm run beproService ``` diff --git a/bepro-service/index.js b/bepro-service/index.js index e8b5739..722d5b6 100644 --- a/bepro-service/index.js +++ b/bepro-service/index.js @@ -2,12 +2,16 @@ const express = require("express"); const { Web3Connection } = require("@taikai/dappkit"); require("dotenv").config(); -const web3connection = new Web3Connection({ - web3Host: process.env.HOSTNAME, - privateKey: process.env.PRIVATE_KEY, - skipWindowAssignment: true, -}); -web3connection.start(); +async function defaultWeb3Connection(start = false) { + const web3Connection = new Web3Connection({ + web3Host: process.env.HOSTCHAIN, + privateKey: process.env.PRIVATE_KEY, + skipWindowAssignment: true, + }); + if (start) await web3Connection.start(); + + return web3Connection; +} const app = express(); app.use(express.json()); @@ -27,18 +31,21 @@ async function increaseTime(time, web3) { return new Promise((resolve, reject) => { provider.send(timeAdvance, (err) => { - if (err) reject(err); - else + if (err) { + reject(err); + } else { provider.send(mine, (err, resp) => { if (err) reject(err); resolve(resp); }); + } }); }); } app.post("/increaseTime", async (req, res) => { const { time } = req.body; + const web3connection = await defaultWeb3Connection(true); await increaseTime(time, web3connection.Web3) .then(() => res.send("OK")) .catch(() => { diff --git a/package.json b/package.json index e874ac9..321a36d 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,9 @@ "@synthetixio/synpress": "^1.1.1", "@taikai/dappkit": "^2.0.0-alpha.4" }, + "browser": { + "dappkit": "./node_modules/@taikai/dappkit/dist/index.js" + }, "dependencies": { "dotenv": "^16.0.0", "electron": "^17.2.0", diff --git a/prepare.js b/prepare.js index 1d0037d..2bbf4b4 100644 --- a/prepare.js +++ b/prepare.js @@ -1,8 +1,10 @@ const fs = require("fs"); const keys = require("./keys.json"); const path = require("node:path"); +require("dotenv").config(); const address = Object.values(keys.private_keys)[0]; +const HOSTNAME = process.env.HOSTNAME const main = () => { if (fs.readFileSync(path.resolve(__dirname, "SYNPRESS_PRIVATEKEY"))) @@ -17,7 +19,8 @@ const main = () => { fs.unlinkSync(path.resolve(__dirname, ".env")); fs.writeFileSync( path.resolve(__dirname, ".env"), - `PRIVATE_KEY=${address}`, + `PRIVATE_KEY=${address} + HOSTNAME=${HOSTNAME}`, "utf-8" ); }; diff --git a/tests/e2e/config.json b/tests/e2e/config.json index 4360cec..cf98afd 100644 --- a/tests/e2e/config.json +++ b/tests/e2e/config.json @@ -14,7 +14,9 @@ }, "env": { "coverage": false, - "delegationAddress": "0x7dF9dCE4feA1737D66F10414175608B15a78D719" + "delegationAddress": "0x7dF9dCE4feA1737D66F10414175608B15a78D719", + "acessToken": "needValidToken", + "councilMemberValue": 26000000 }, "defaultCommandTimeout": 30000, "pageLoadTimeout": 30000, diff --git a/tests/e2e/pages/account/my-account.js b/tests/e2e/pages/account/my-account.js index c90926b..0aa3e35 100644 --- a/tests/e2e/pages/account/my-account.js +++ b/tests/e2e/pages/account/my-account.js @@ -38,7 +38,7 @@ export default class MyAccount extends Page { } getModalButtonConfirm() { - return cy.get(".modal-footer > .btn-primary"); + return cy.get("button").contains("Confirm"); } getButtonUnlock() { diff --git a/tests/e2e/pages/bounty/bounty.js b/tests/e2e/pages/bounty/bounty.js index fdf4d6c..226b381 100644 --- a/tests/e2e/pages/bounty/bounty.js +++ b/tests/e2e/pages/bounty/bounty.js @@ -1,10 +1,10 @@ import Page from "../page"; -import { FirstPrData } from "../payload/bounty"; +import { FirstPrData, SecondPrData, ResponsePrData } from "../payload/bounty"; import { interceptGroup } from "../helpers/handleEqualIntercepts"; export class Bounty extends Page { getRedeemButton() { - return cy.get("button").contains("Redeem"); + return cy.get("button").contains("Cancel"); } getStartWorkingButton() { return cy.contains("Start Working", { @@ -20,9 +20,32 @@ export class Bounty extends Page { return cy.contains("Recognize as finished"); } + getPullRequestDraft() { + return cy.contains("Draft"); + } + getCreateProposalButton() { return cy.get("button").contains("Create Proposal"); } + + getMakeReadyForReviewButton() { + return cy.contains("Make ready for review"); + } + getBackPullRequest() { + return cy.get("svg.rounded-circle").click({ force: true }); + } + getUpdateAmountButton() { + return cy.get("button").contains("Update Amount"); + } + getInputModalAmount() { + return cy.get("div > label").contains("Amount").next(); + } + getConfirmModalButton() { + return cy.get("button > span").contains("Confirm"); + } + getCancelModalButton() { + return cy.get("button").contains("Cancel"); + } } export function StartWorking() { @@ -36,7 +59,7 @@ export function StartWorking() { bounty.getStartWorkingButton().should("exist").click({ force: true }); - cy.wait(["@getIssueData"]); + cy.wait(["@getIssueData", "@gqlCommentsQuery", "@gqlRepositoriesQuery"]); bounty.waitForTransactionSuccess(); @@ -47,11 +70,6 @@ export function StartWorking() { export function CreatePullRequest() { const bounty = new Bounty(); - interceptGroup.postPullRequest(); - interceptGroup.getIssueCommentsGithub(); - interceptGroup.getGithubCurrentRepos(); - interceptGroup.getPrCount(); - interceptGroup.getPrGithub(); cy.intercept( { @@ -70,23 +88,27 @@ export function CreatePullRequest() { ).as("getIssuePrData"); bounty.getCreatePullRequestButton().click({ force: true }); + cy.wait(["@gqlBranchesQuery", "@gqlRepositoriesQuery"]); cy.get("h3").contains("Create Pull Request").should("exist"); + cy.wait(1500); cy.get(".react-select__input").click({ force: true }).type("{enter}"); cy.get("span").contains("Create Pull Request").click({ force: true }); - cy.wait("@postPullRequest"); - cy.wait([ - "@getIssueCommentsGithub", - "@getGithubCurrentRepos", - "@getIssuePrData", - "@getPrCount", - "@getPrGithub", - ]); + cy.wait(500); + cy.intercept("POST", "/api/pull-request", { + body: ResponsePrData, + }); + cy.confirmMetamaskTransaction({}); + cy.intercept("POST", "/api/past-events/pull-request/created", { + body: ["1540"], + }); + cy.wait("@gqlDetailsQuery"); bounty.waitForTransactionSuccess(); } export function recognizeAsFinished(address) { const bounty = new Bounty(); + cy.intercept( { method: "GET", @@ -103,46 +125,91 @@ export function recognizeAsFinished(address) { } ).as("getIssuePrData"); - interceptGroup.getIssueCommentsGithub(); - interceptGroup.getGithubCurrentRepos(); - interceptGroup.getPrGithub(); - interceptGroup.getPrCount(); - interceptGroup.getParticipants(); - interceptGroup.getCommits(); + cy.intercept( + { + method: "GET", + url: "/api/issue/*/*/bepro", + times: 5000, + }, + ({ reply, headers }) => { + delete headers["if-none-match"]; // prevent caching + reply(({ body }) => { + body.state = "ready"; + body.pullRequests = [SecondPrData(body.issueId, body.createdAt)]; + return body; + }); + } + ).as("getIssuePrData2"); + interceptGroup.searchUsers(address); - bounty.getRecognizeAsFinishedButton().click({ force: true }); - cy.wait(500); + cy.contains("1 pull request").should("exist"); + bounty.getPullRequestDraft().click({ force: true }); + cy.contains("Pull Request").should("exist"); + bounty.getMakeReadyForReviewButton().should("exist"); + bounty.getMakeReadyForReviewButton().click({ force: true }); cy.confirmMetamaskTransaction({}); - cy.wait([ - "@getIssueCommentsGithub", - "@getGithubCurrentRepos", - "@getIssuePrData", - "@getPrGithub", - "@getPrCount", - "@getCommits", - "@getParticipants", - "@searchUsers", - ]); + cy.intercept("POST", "/api/past-events/pull-request/ready", { + body: ["1181"], + }); + cy.wait(["@gqlCommentsQuery", "@gqlDetailsQuery", "@getIssuePrData2"]); + bounty.getBackPullRequest(); + cy.wait("@searchUsers"); } export function RedeemBounty() { const bounty = new Bounty(); - cy.contains("Redeem", { + cy.contains("Cancel", { timeout: 60000, }); - bounty.getRedeemButton().click(); cy.wait(1000); cy.isMetamaskWindowActive(); cy.wait(1000); cy.confirmMetamaskTransaction({}); - cy.contains("Redeem", { + cy.contains("Cancel", { timeout: 60000, }).should("not.exist"); cy.contains("canceled", { timeout: 60000, }).should("exist"); } + +export function updateAmount(amount) { + const bounty = new Bounty(); + + cy.intercept( + { + method: "GET", + url: "/api/issue/*/*/bepro", + times: 5000, + }, + ({ reply, headers }) => { + delete headers["if-none-match"]; // prevent caching + reply(({ body }) => { + body.amount = amount; + return body; + }); + } + ).as("getIssue"); + + cy.intercept("/api/past-events/bounty/updated", ["1/1"]).as("bountyUpdated"); + + cy.contains("Update Amount").should("exist"); + bounty.getUpdateAmountButton().click(); + cy.wait(500); + cy.contains("Update Bounty Amount").should("exist"); + bounty.getInputModalAmount().type(amount); + cy.wait(500); + cy.get("button > span").contains("Approve").click({ force: true }); + cy.wait(500); + cy.confirmMetamaskPermissionToSpend(); + cy.contains("Confirm") + bounty.getConfirmModalButton().click({ force: true }); + cy.wait(500); + cy.confirmMetamaskTransaction({}); + cy.wait(["@bountyUpdated", "@getIssue"]); + cy.get("div .price-conversor > span").contains(amount); +} diff --git a/tests/e2e/pages/bounty/create-bounty.js b/tests/e2e/pages/bounty/create-bounty.js index b451f13..5654bc5 100644 --- a/tests/e2e/pages/bounty/create-bounty.js +++ b/tests/e2e/pages/bounty/create-bounty.js @@ -1,5 +1,4 @@ import Page from "../page"; -import { BranchsData } from "../payload/bounty"; export class FormBounty extends Page { getTitle() { @@ -15,11 +14,15 @@ export class FormBounty extends Page { } getBranch() { + return cy.get("div > label").contains("Select a branch").next() + } + + getToken() { return cy.get(".react-select__input").last(); } getAmount() { - return cy.get("input.text-muted"); + return cy.get(`input[inputmode="numeric"]`); } getButtonCreate() { @@ -51,22 +54,19 @@ export function CreateBounty({ }) { const form = new FormBounty(); - cy.intercept("GET", "/api/repos/branchs/*/bepro", BranchsData).as( - "getBranchs" - ); - - cy.intercept("PATCH", "/api/issue").as("postDraftIssue"); + cy.intercept("POST", "/api/past-events/bounty/created").as("created"); cy.get("span").contains("Create bounty").click(); - cy.url() + cy.url(); form.getTitle().type(title, { force: true }); form.getDescription().type(description); form.getRepository().click({ force: true }).type("{enter}"); - cy.wait("@getBranchs"); + cy.wait("@gqlBranchesQuery"); form.getBranch().click({ force: true }).type("{enter}"); + form.getToken().click({ force: true }).type("{enter}"); + form.getAmount().type(amount); cy.wait(500); form.handleApprove(); - form.getAmount().type(amount); form.getButtonCreate().should("not.be.disabled").click(); cy.intercept("POST", "/api/issue"); cy.wait(500); @@ -77,7 +77,7 @@ export function CreateBounty({ }); } }); - cy.wait("@postDraftIssue", { + cy.wait("@created", { timeout: 100000, }); } diff --git a/tests/e2e/pages/bounty/proposal.js b/tests/e2e/pages/bounty/proposal.js index 1b9d455..57e163b 100644 --- a/tests/e2e/pages/bounty/proposal.js +++ b/tests/e2e/pages/bounty/proposal.js @@ -1,11 +1,12 @@ import Page from "../page"; import { interceptGroup } from "../helpers/handleEqualIntercepts"; import { Bounty } from "./bounty"; -import { FirstProposalData, FirstPrData } from "../payload/bounty"; +import { FirstProposalData, SecondPrData } from "../payload/bounty"; +import { faker } from "@faker-js/faker"; export class Proposal extends Page { getReadyToMergePr() { - return cy.get("span").contains("ready to merge"); + return cy.get("span").contains("Ready to merge"); } getDistributionInput() { return cy.get(`input.border-radius-8[inputmode="numeric"]`); @@ -28,9 +29,9 @@ export function CreateSimpleProposal(address) { delete headers["if-none-match"]; // prevent caching reply(({ body }) => { body.state = "ready"; - body.mergeProposals = [FirstProposalData(body.issueId, body.createdAt)]; + body.mergeProposals = [FirstProposalData(body.issueId, faker.date.past(1))]; body.pullRequests = [ - FirstPrData(body.issueId, body.createdAt), + SecondPrData(body.issueId, body.createdAt), { branch: "bounty_47", createdAt: body.createdAt, @@ -47,10 +48,6 @@ export function CreateSimpleProposal(address) { } ).as("getIssuePrData"); - interceptGroup.getPrGithub(); - interceptGroup.getParticipants(); - interceptGroup.getIssueCommentsGithub(); - interceptGroup.getGithubCurrentRepos(); interceptGroup.searchUsers(address); cy.intercept("POST", "/api/past-events/merge-proposal", { @@ -63,12 +60,7 @@ export function CreateSimpleProposal(address) { proposal.getCreateButton().click(); cy.confirmMetamaskTransaction({}); cy.wait([ - "@getGithubCurrentRepos", - "@getParticipants", - "@getIssueCommentsGithub", - "@getPrGithub", "@getIssuePrData", - "@mergeProposal", "@searchUsers", ]); @@ -79,9 +71,8 @@ export function CreateSimpleProposal(address) { cy.get("label.text-primary").contains("validation & disputes"); } -export function MergeProposalBounty(address) { +export function MergeProposalBounty() { const bounty = new Bounty(); - interceptGroup.getAddress(address); cy.intercept("POST", "/api/pull-request/merge", { statusCode: 200, @@ -91,9 +82,11 @@ export function MergeProposalBounty(address) { statusCode: 200, }).as("closeIssue"); - cy.wait("@getAddress"); - cy.get("button").contains("Merge").click(); + cy.contains("Open for Dispute").should("exist"); + cy.get("div.justify-content-between > button").first().click(); cy.wait(500); + /* todo: fix this merge confirmation logic */ + /*cy.get(".modal-footer > button").click(); cy.confirmMetamaskTransaction({}); cy.wait(["@mergePr", "@closeIssue"]); bounty.waitForTransactionSuccess(); @@ -107,5 +100,5 @@ export function MergeProposalBounty(address) { { timeout: 60000, } - ); + );*/ } diff --git a/tests/e2e/pages/helpers/handleEqualIntercepts.js b/tests/e2e/pages/helpers/handleEqualIntercepts.js index a12788e..7bcb3b7 100644 --- a/tests/e2e/pages/helpers/handleEqualIntercepts.js +++ b/tests/e2e/pages/helpers/handleEqualIntercepts.js @@ -1,132 +1,14 @@ import { UserBranchsData, Forksdata, - ReposUserData, - StatusPrGithubData, - PrCommitsGithubData, } from "../payload/bounty"; import { userData } from "../payload/user"; -const hostGithub = "api.github.com"; +import { hasQueryName } from "../../utils/graphql-test-utils"; -export const interceptGroup = { - getGithubForks: () => - cy - .intercept( - { - method: "GET", - url: "/repos/*/*/forks?per_page=100", - hostname: hostGithub, - }, - { - statusCode: 200, - body: Forksdata, - } - ) - .as("getGithubForks"), - - getGithubCurrentBranchs: () => - cy - .intercept( - { - method: "GET", - url: "/repos/*/*/branches", - hostname: hostGithub, - }, - UserBranchsData - ) - .as("getGithubCurrentBranchs"), - getGithubCurrentRepos: () => - cy - .intercept( - { - method: "GET", - url: "/repos/*/*", - hostname: hostGithub, - }, - ReposUserData - ) - .as("getGithubCurrentRepos"), - - getIssueCommentsGithub: () => - cy - .intercept( - { - method: "GET", - url: "/repos/*/*/issues/*/comments", - hostname: hostGithub, - }, - { - statusCode: 200, - body: [], - } - ) - .as("getIssueCommentsGithub"), - - postPullRequest: () => - cy - .intercept( - { - method: "POST", - url: "/api/pull-request", - times: 2000, - }, - { - body: "ok", - } - ) - .as("postPullRequest"), - - getPrCount: () => - cy - .intercept("GET", "/api/pull-request?*", { - count: 1, - }) - .as("getPrCount"), - - getPrGithub: () => - cy - .intercept( - { - method: "GET", - url: "/repos/*/*/pulls/*", - hostname: "api.github.com", - }, - { - body: StatusPrGithubData, - } - ) - .as("getPrGithub"), - - getParticipants: () => - cy - .intercept( - { - method: "GET", - url: "/repos/*/*/pulls/*/commits", - hostname: "api.github.com", - }, - { - body: [PrCommitsGithubData], - } - ) - .as("getParticipants"), - - getCommits: () => - cy - .intercept( - { - method: "GET", - url: "/repos/*/*/commits", - hostname: "api.github.com", - }, - { - body: [PrCommitsGithubData], - } - ) - .as("getCommits"), +export const interceptGroup = { searchUsers: (address) => cy @@ -143,4 +25,141 @@ export const interceptGroup = { body: [userData(address)], }) .as("getAddress"), + + gqlForksQuery: (req) => { + if (hasQueryName(req, "query Forks")) { + req.alias = "gqlForksQuery"; + req.reply(({ body }) => { + body.data ? (body.data = null) : null; + body.data = Forksdata; + return body; + }); + } + }, + + gqlBranchesQuery: (req) => { + if (hasQueryName(req, "query Branches")) { + req.alias = "gqlBranchesQuery"; + req.reply(({ body }) => { + body.data ? (body.data = null) : null; + body.data = UserBranchsData; + return body; + }); + } + }, + + gqlRepositoriesQuery: (req) => { + if (hasQueryName(req, "query Repositories")) { + req.alias = "gqlRepositoriesQuery"; + req.reply(({ body }) => { + body.data ? (body.data = null) : null; + body.data = { + user: { + repositories: { + pageInfo: { + endCursor: "Y3Vyc29yOnYyOpHOG9_rrw==", + hasNextPage: false, + }, + nodes: [ + { + name: "bepro-js-edge", + nameWithOwner: "user-test/bepro-js-edge", + isFork: true, + owner: { + login: "user-test", + }, + }, + ], + }, + organizations: { + nodes: [], + }, + }, + }; + return body; + }); + } + }, + + gqlCommentsQuery: (req) => { + if (hasQueryName(req, "query Comments")) { + req.alias = "gqlCommentsQuery"; + req.reply(({ body }) => { + body.data ? (body.data = null) : null; + body.data = { + repository: { + issueOrPullRequest: { + comments: { + pageInfo: { + endCursor: null, + hasNextPage: false, + }, + nodes: [], + }, + }, + }, + }; + return body; + }); + } + }, + + gqlDetailsQuery: (req) => { + if (hasQueryName(req, "query Details")) { + req.alias = "gqlDetailsQuery"; + req.reply({ + data: { + repository: { + pullRequest: { + id: "PR_kwDOGEZRks45NP5H", + mergeable: "MERGEABLE", + merged: false, + state: "OPEN", + }, + }, + }, + }); + } + }, + + gqlParticipantsQuery: (req) => { + if (hasQueryName(req, "query Participants")) { + req.alias = "gqlParticipantsQuery"; + req.reply({ + data: { + repository: { + pullRequest: { + participants: { + pageInfo: { + endCursor: "Mg", + hasNextPage: false, + }, + nodes: [ + { + login: "user-test", + }, + ], + }, + }, + }, + }, + }); + } + }, + + gqlLinesOfCodeQuery: (req) => { + if (hasQueryName(req, "query LinesOfCode")) { + req.alias = "gqlLinesOfCodeQuery"; + req.reply({ + data: { + repository: { + pullRequest: { + additions: 2, + deletions: 1, + }, + }, + }, + }); + } + }, }; diff --git a/tests/e2e/pages/payload/bounty.js b/tests/e2e/pages/payload/bounty.js index 8ba7758..2e8a9f2 100644 --- a/tests/e2e/pages/payload/bounty.js +++ b/tests/e2e/pages/payload/bounty.js @@ -1,38 +1,39 @@ -const Forksdata = [ - { - id: 451920531, - name: "bepro-js-edge", - full_name: "luisclark/bepro-js-edge", - owner: { - login: "luisclark", - id: 92887398, - avatar_url: "https://avatars.githubusercontent.com/u/92887398?v=4", - url: "https://api.github.com/users/luisclark", - type: "User", +const Forksdata = { + repository: { + forks: { + pageInfo: { + endCursor: "Y3Vyc29yOnYyOpHOHRNkNw==", + hasNextPage: false, + }, + nodes: [ + { + owner: { + login: "user-1", + }, + }, + { + owner: { + login: "user-2", + }, + }, + { + owner: { + login: "user-test", + }, + }, + ], }, - url: "https://api.github.com/repos/luisclark/bepro-js-edge", - }, -]; - -const UserBranchsData = [ - { - name: "main", }, - { - name: "master", - }, -]; +}; -const BranchsData = [ - { - branch: "main", - protected: false, - }, - { - branch: "master", - protected: false, +const UserBranchsData = { + repository: { + refs: { + nodes: [{ name: "main" }, { name: "master" }], + pageInfo: { endCursor: "Nw", hasNextPage: false }, + }, }, -]; +}; const ReposNetworkData = [ { @@ -42,11 +43,14 @@ const ReposNetworkData = [ }, ]; -const ReposUserData = { - owner: { - login: "user-test", - }, - fork: true, +const ResponsePrData = { + bountyId: 30, + originRepo: "bepronetwork/bepro-js-edge", + originBranch: "bounty_1-414", + originCID: "1/1539", + userRepo: "user-test/bepro-js-edge", + userBranch: "user-test:feature/test6", + cid: "1540", }; const FirstPrData = (issueId, createdAt) => ({ @@ -58,20 +62,28 @@ const FirstPrData = (issueId, createdAt) => ({ issueId, reviewers: [], updatedAt: "2022-03-30T14:02:57.131Z", + contractId: 0, + branch: "user-test:feature/test7", + status: "draft", + userBranch: "user-test:feature/test7", + userRepo: "user-test/bepro-js-edge", }); -const StatusPrGithubData = { - state: "open", - mergeable: true, - mergeable_state: "dirty", - merged: false, -}; - -const PrCommitsGithubData = { - author: { - login: "user-test", - }, -}; +const SecondPrData = (issueId, createdAt) => ({ + branch: "bounty_46", + createdAt, + githubId: "1181", + githubLogin: "user-test", + id: 3, + issueId, + reviewers: [], + updatedAt: "2022-03-30T14:02:57.131Z", + contractId: 0, + branch: "user-test:feature/test7", + status: "ready", + userBranch: "user-test:feature/test7", + userRepo: "user-test/bepro-js-edge", +}); const FirstProposalData = (issueId, createdAt) => ({ createdAt, @@ -81,27 +93,27 @@ const FirstProposalData = (issueId, createdAt) => ({ pullRequestId: 3, scMergeId: "0", updatedAt: "2022-03-31T16:07:41.687Z", + contractId: 0, }); const SecondProposalData = (issueId, createdAt) => ({ - createdAt, - githubLogin: "user-test2", - id: 2, - issueId, - pullRequestId: 50, - scMergeId: "0", - updatedAt: "2022-03-31T16:07:41.687Z", - }); + createdAt, + githubLogin: "user-test2", + id: 2, + issueId, + pullRequestId: 50, + scMergeId: "0", + updatedAt: "2022-03-31T16:07:41.687Z", + contractId: 0, +}); export { Forksdata, - BranchsData, UserBranchsData, ReposNetworkData, - ReposUserData, FirstPrData, - StatusPrGithubData, - PrCommitsGithubData, + SecondPrData, FirstProposalData, - SecondProposalData + SecondProposalData, + ResponsePrData, }; diff --git a/tests/e2e/pages/payload/user.ts b/tests/e2e/pages/payload/user.ts index 23a77c4..e0a2230 100644 --- a/tests/e2e/pages/payload/user.ts +++ b/tests/e2e/pages/payload/user.ts @@ -20,15 +20,17 @@ function userData( }; } -const userSessionData = { - expires: faker.date.future(1), - user: { - name: githubHandle, - email: null, - image: "https://avatars.githubusercontent.com/u/34746557?v=4", - login: githubLogin, - accessToken, - }, +const userSessionData = (accessToken) => { + return { + expires: faker.date.future(1), + user: { + name: githubHandle, + email: faker.internet.email(), + image: "https://avatars.githubusercontent.com/u/34746557?v=4", + login: githubLogin, + accessToken: accessToken, + }, + }; }; export { userData, userSessionData }; diff --git a/tests/e2e/specs/1-login-spec.js b/tests/e2e/specs/1-login-spec.js index b85a7ca..71c043a 100644 --- a/tests/e2e/specs/1-login-spec.js +++ b/tests/e2e/specs/1-login-spec.js @@ -18,15 +18,27 @@ describe("Wallet tests", () => { userData(metamaskWalletAddress), ]).as("userData"); - cy.intercept("GET", "/api/auth/session", userSessionData).as("userSession"); + cy.intercept( + "GET", + "/api/auth/session", + userSessionData(Cypress.env("acessToken")) + ).as("userSession"); cy.visit("/"); - mainNav.handleConnectBrowserWallet(); + cy.acceptMetamaskAccess(); cy.wait(["@userData", "@userSession"]); }); + after(() => { + cy.isMetamaskWindowActive().then((active) => { + if (active === true) { + cy.closeMetamaskWindow(); + } + }); + }); + context("Connect metamask wallet and account tests", () => { it(`should login with success`, () => { // TODO add conditional that enables use of metamask when all tests are run @@ -51,9 +63,13 @@ describe("Wallet tests", () => { cy.url().should("contain", "bepro/account"); account.getOracles().click({ force: true }); cy.url().should("contain", "bepro/account/my-oracles"); + cy.wait(500); + account.getInputLock().type(Cypress.env("councilMemberValue"), { force: true }); + cy.wait(500); account.handleApprove(); - account.getInputLock().type(26000000); - account.getButtonLockTransaction().click(); + cy.wait(500) + account.getButtonLockTransaction().click({ force: true }); + cy.wait(500) account.getModalButtonConfirm().click(); cy.wait(500); account.confirmMetamaskTransaction(); @@ -62,8 +78,9 @@ describe("Wallet tests", () => { it(`should unlock $bepro account`, () => { account.getButtonUnlock().click({ force: true }); - account.getInputUnlock().clear().type(100); - account.getButtonUnlockTransaction().click(); + account.getInputUnlock().clear({ force: true }).type(100); + account.getButtonUnlockTransaction().click({ force: true }); + cy.wait(500); account.getModalButtonConfirm().click(); cy.wait(500); account.confirmMetamaskTransaction(); @@ -71,12 +88,13 @@ describe("Wallet tests", () => { }); it(`should delegate oracles`, () => { - account.getInputDelegateAmount().type(10); - account.getInputDelegateAddress().type(Cypress.env("delegationAddress")); + account.getInputDelegateAmount().type(10, { force: true }); + account.getInputDelegateAddress().type(Cypress.env("delegationAddress"), { force: true }); account.getButtonDelegate().click({ force: true }); cy.wait(500); account.confirmMetamaskTransaction(); mainNav.waitForTransactionSuccess(); + cy.wait(1000) }); }); }); diff --git a/tests/e2e/specs/2-bounty-spec.js b/tests/e2e/specs/2-bounty-spec.js index 1cd688d..9708d1a 100644 --- a/tests/e2e/specs/2-bounty-spec.js +++ b/tests/e2e/specs/2-bounty-spec.js @@ -9,6 +9,7 @@ import { CreatePullRequest, recognizeAsFinished, RedeemBounty, + updateAmount, } from "../pages/bounty/bounty"; import { MergeProposalBounty, @@ -41,7 +42,11 @@ describe("Bounty tests", () => { userData(metamaskWalletAddress), ]).as("userData"); - cy.intercept("GET", "/api/auth/session", userSessionData).as("userSession"); + cy.intercept( + "GET", + "/api/auth/session", + userSessionData(Cypress.env("acessToken")) + ).as("userSession"); cy.intercept({ method: "GET", @@ -51,18 +56,23 @@ describe("Bounty tests", () => { cy.visit("/"); - cy.wait(["@getRepos", "@getApi"]); + cy.wait(["@getRepos", "@getApi", "@userSession"]); - navActions.handleConnectBrowserWallet(); - - cy.wait(["@userData", "@userSession"]); + cy.isMetamaskWindowActive().then((active) => { + if (active === true) { + cy.acceptMetamaskAccess(); + cy.wait(["@userData"]); + } + }); }); it("Should start working bounty", () => { - interceptGroup.getGithubForks(); - interceptGroup.getGithubCurrentBranchs(); - interceptGroup.getGithubCurrentRepos(); - interceptGroup.getIssueCommentsGithub(); + cy.intercept("POST", "https://api.github.com/graphql", (req) => { + interceptGroup.gqlBranchesQuery(req); + interceptGroup.gqlForksQuery(req); + interceptGroup.gqlCommentsQuery(req); + interceptGroup.gqlRepositoriesQuery(req); + }); CreateBounty({ title: faker.random.words(2), @@ -72,53 +82,96 @@ describe("Bounty tests", () => { }); cy.wait([ - "@getGithubForks", - "@getGithubCurrentBranchs", - "@getGithubCurrentRepos", - "@getIssueCommentsGithub", + "@gqlBranchesQuery", + "@gqlForksQuery", + "@gqlCommentsQuery", + "@gqlRepositoriesQuery", ]); + cy.reload(); + StartWorking(); }); it("Should create pull request bounty", () => { + cy.intercept("POST", "https://api.github.com/graphql", (req) => { + interceptGroup.gqlBranchesQuery(req); + interceptGroup.gqlRepositoriesQuery(req); + interceptGroup.gqlDetailsQuery(req); + }); CreatePullRequest(); }); it("Should recognize as finished bounty", () => { + cy.intercept("POST", "https://api.github.com/graphql", (req) => { + interceptGroup.gqlCommentsQuery(req); + interceptGroup.gqlRepositoriesQuery(req); + interceptGroup.gqlDetailsQuery(req); + interceptGroup.gqlLinesOfCodeQuery(req); + interceptGroup.gqlParticipantsQuery(req); + }); recognizeAsFinished(metamaskWalletAddress); - cy.wait(2000); + cy.wait([ + "@gqlParticipantsQuery", + "@gqlLinesOfCodeQuery", + "@gqlRepositoriesQuery", + ]); }); it("Should create proposal bounty", () => { - bounty.getCreateProposalButton().click({ force: true }); + cy.intercept("POST", "https://api.github.com/graphql", (req) => { + interceptGroup.gqlParticipantsQuery(req); + interceptGroup.gqlCommentsQuery(req); + interceptGroup.gqlRepositoriesQuery(req); + interceptGroup.gqlDetailsQuery(req); + interceptGroup.gqlLinesOfCodeQuery(req); + }); cy.wait(500); + cy.contains("Create Proposal").should("exist"); + bounty.getCreateProposalButton().click({ force: true }); CreateSimpleProposal(metamaskWalletAddress); }); it("Should merge proposal bounty", () => { + /*cy.intercept("POST", "https://api.github.com/graphql", (req) => { + interceptGroup.gqlBranchesQuery(req); + interceptGroup.gqlForksQuery(req); + interceptGroup.gqlCommentsQuery(req); + interceptGroup.gqlRepositoriesQuery(req); + interceptGroup.gqlDetailsQuery(req); + interceptGroup.gqlLinesOfCodeQuery(req); + interceptGroup.gqlParticipantsQuery(req); + });*/ + interceptGroup.getAddress(metamaskWalletAddress); cy.get("span").contains("1 proposal").click({ force: true }); cy.get(".content-wrapper > .cursor-pointer:nth-child(1)").click({ force: true, }); - MergeProposalBounty(metamaskWalletAddress); + cy.wait("@getAddress"); + MergeProposalBounty(); }); - it("Should Redeem bounty", () => { + it("Should Update amount bounty", () => { + cy.intercept("POST", "https://api.github.com/graphql", (req) => { + interceptGroup.gqlBranchesQuery(req); + interceptGroup.gqlForksQuery(req); + interceptGroup.gqlCommentsQuery(req); + interceptGroup.gqlRepositoriesQuery(req); + }); + cy.intercept("POST", "/api/search/users/address", [ userData(metamaskWalletAddress), ]).as("userData"); - cy.intercept("GET", "/api/auth/session", userSessionData).as("userSession"); + cy.intercept( + "GET", + "/api/auth/session", + userSessionData(Cypress.env("acessToken")) + ).as("userSession"); cy.visit("bepro/create-bounty"); cy.wait(["@userData", "@userSession"]); - interceptGroup.getGithubForks(); - interceptGroup.getGithubCurrentBranchs(); - interceptGroup.getGithubCurrentRepos(); - interceptGroup.getIssueCommentsGithub(); - CreateBounty({ title: faker.random.words(6), description: faker.random.words(6), @@ -126,12 +179,16 @@ describe("Bounty tests", () => { }); cy.wait([ - "@getGithubForks", - "@getGithubCurrentBranchs", - "@getGithubCurrentRepos", - "@getIssueCommentsGithub", + "@gqlBranchesQuery", + "@gqlForksQuery", + "@gqlCommentsQuery", + "@gqlRepositoriesQuery", ]); + updateAmount(20); + }); + + it("Should Redeem bounty", () => { RedeemBounty(); }); }); diff --git a/tests/e2e/tsconfig.json b/tests/e2e/tsconfig.json index 28d2c53..5a59704 100644 --- a/tests/e2e/tsconfig.json +++ b/tests/e2e/tsconfig.json @@ -7,7 +7,8 @@ "@types/puppeteer-core", "@synthetixio/synpress/support", "cypress-wait-until", - "@testing-library/cypress" + "@testing-library/cypress", + "electron-fetch" ], "outDir": "./output" }, diff --git a/tests/e2e/utils/graphql-test-utils.js b/tests/e2e/utils/graphql-test-utils.js new file mode 100644 index 0000000..96cad34 --- /dev/null +++ b/tests/e2e/utils/graphql-test-utils.js @@ -0,0 +1,7 @@ +// Utility to match GraphQL based on the first words +export const hasQueryName = (req, queryName) => { + const { body } = req + return ( + body.query && body.query.search(queryName) > -1 + ) + } \ No newline at end of file