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
e2e: Proposal Create mock structure. #2676
Changes from 12 commits
5b97a79
f895c71
f8f57f4
099b142
e0a0f84
fba7bb4
1d71b8e
706e6b9
abbb3c3
7fc66ce
bb479dd
f888462
df69ed7
46df268
c5919b3
e56ed4e
3a5dab9
384b63a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,69 @@ | ||
import { buildProposal } from "../../support/generate"; | ||
|
||
beforeEach(function mockApiCalls() { | ||
// currently mocking pi and ticketvote summaries calls with any status, since | ||
// they aren't used for assertions. | ||
cy.useTicketvoteApi(); | ||
cy.useRecordsApi(); | ||
cy.usePiApi(); | ||
cy.useWwwApi(); | ||
cy.useCommentsApi(); | ||
}); | ||
|
||
describe("Proposal Create", () => { | ||
// XXX This test needs changes in the Datepicker and (probably) the Select | ||
// components, in order to fill the new form fields such as: start & end dates | ||
// and amount - issue to track <insert issue link> | ||
// | ||
/*it("Paid user can create proposals manually", () => { | ||
it("should be able to create proposals", () => { | ||
// paid user with proposal credits | ||
const user = { | ||
email: "adminuser@example.com", | ||
username: "adminuser", | ||
password: "password" | ||
}; | ||
cy.userEnvironment("user", { verifyIdentity: true }); | ||
const proposal = buildProposal(); | ||
cy.login(user); | ||
cy.visit("/"); | ||
cy.identity(); | ||
cy.recordsMiddleware("new", {}); | ||
cy.visit("/record/new"); | ||
cy.typeCreateProposal(proposal); | ||
});*/ | ||
cy.findByRole("button", { name: /submit/i }).click(); | ||
// needs more time in general to complete this request so we increase the | ||
// responseTimeout | ||
cy.wait("@newProposal").should((xhr) => { | ||
expect(xhr.status).to.equal(200); | ||
cy.piMiddleware("summaries", { amountByStatus: { unvetted: 1 } }); | ||
const token = xhr.response.body.record.censorshiprecord.token; | ||
cy.assertProposalPage({ | ||
...proposal, | ||
token: token | ||
}); | ||
cy.wait("@pi.summaries", { timeout: 500 }); | ||
cy.findByTestId("record-title").should("have.text", proposal.name); | ||
}); | ||
}); | ||
|
||
it("Non-paid user can not create proposals", () => { | ||
const user = { | ||
email: "user3@example.com", | ||
username: "user3", | ||
password: "password" | ||
}; | ||
cy.login(user); | ||
it("should not be able to create proposals without fill the input", () => { | ||
// paid user with proposal credits | ||
cy.userEnvironment("user", { verifyIdentity: true }); | ||
cy.recordsMiddleware("new", {}); | ||
cy.visit("/record/new"); | ||
cy.findByRole("button", { name: /submit/i }).click(); | ||
cy.findByTestId("proposal-name").parent().find("p").contains("Required"); | ||
cy.findByTestId("proposal-amount").parent().find("p").contains("Required"); | ||
cy.get("[data-testid=datepicker]:eq(0)") | ||
.find("p") | ||
.contains("Please pick a start date"); | ||
cy.get("[data-testid=datepicker]:eq(1)") | ||
.find("p") | ||
.contains("Please pick an end date"); | ||
}); | ||
|
||
it("should not be able create proposals with non-paid user", () => { | ||
cy.userEnvironment("unpaid", { verifyIdentity: true }); | ||
cy.visit("/"); | ||
cy.findByText(/new proposal/i).should("be.disabled"); | ||
const proposal = buildProposal(); | ||
cy.visit("/record/new"); | ||
cy.typeCreateProposal(proposal); | ||
cy.findByText( | ||
/you won't be able to submit comments or proposals before paying the paywall/i | ||
).should("be.visible"); | ||
const proposal = buildProposal(); | ||
cy.findByTestId("proposal-name").should("be.visible").type(proposal.name); | ||
cy.findByTestId("text-area").type(proposal.description); | ||
cy.findByRole("button", { name: /submit/i }).should("be.disabled"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,22 @@ | |
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) | ||
// | ||
import { sha3_256 } from "js-sha3"; | ||
import { requestWithCsrfToken, setProposalStatus } from "../utils"; | ||
import { | ||
PROPOSAL_SUMMARY_STATUS_UNVETTED, | ||
vibros68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requestWithCsrfToken, | ||
setProposalStatus | ||
} from "../utils"; | ||
import * as pki from "../pki"; | ||
import get from "lodash/fp/get"; | ||
// TODO: consider moving general functions like makeProposal and signRegister | ||
// to a more general lib file other than api. | ||
import { makeProposal, signRegister } from "../utils"; | ||
import { shortRecordToken } from "../utils"; | ||
import { | ||
makeProposal, | ||
signRegister, | ||
shortRecordToken, | ||
RECORD_DOMAINS, | ||
typeDatePicker | ||
vibros68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} from "../utils"; | ||
import { middlewares as recordMiddlewares } from "./mock/records"; | ||
import { middlewares as ticketVoteMiddlewares } from "./mock/ticketvote"; | ||
import { middlewares as commentsMiddlewares } from "./mock/comments"; | ||
|
@@ -149,22 +158,19 @@ Cypress.Commands.add("approveProposal", ({ token }) => | |
Cypress.Commands.add("typeCreateProposal", (proposal) => { | ||
cy.server(); | ||
cy.findByTestId("proposal-name").type(proposal.name); | ||
cy.findByTestId("text-area").type(proposal.description); | ||
cy.findByTestId("proposal-amount").type(String(proposal.amount / 100)); // get dollars from cents. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier: 80 max char per line. |
||
const startDate = new Date(proposal.startDate * 1000); | ||
cy.findAllByTestId("datepicker").first().children().first().click(); | ||
cy.findAllByTestId("days-list") | ||
.first() | ||
.findByText(startDate.getDate()) | ||
.click(); | ||
cy.findAllByTestId("datepicker").first().next().children().first().click(); | ||
cy.get("[data-testid=days-list]:eq(1)").find(">li").last().click(); | ||
const domainTxt = RECORD_DOMAINS[proposal.domain]; | ||
cy.get("#domain-selector").click().contains(domainTxt).click({ force: true }); | ||
cy.route("POST", "/api/records/v1/new").as("newProposal"); | ||
cy.findByRole("button", { name: /submit/i }).click(); | ||
// needs more time in general to complete this request so we increase the | ||
// responseTimeout | ||
cy.wait("@newProposal", { timeout: 10000 }).should((xhr) => { | ||
expect(xhr.status).to.equal(200); | ||
expect(xhr.response.body.record) | ||
.to.have.property("censorshiprecord") | ||
.and.be.a("object") | ||
.and.have.all.keys("token", "signature", "merkle"); | ||
cy.assertProposalPage({ | ||
...proposal, | ||
token: xhr.response.body.record.censorshiprecord.token | ||
}); | ||
}); | ||
cy.findByTestId("text-area").type(proposal.description); | ||
}); | ||
|
||
Cypress.Commands.add("assertListLengthByTestId", (testid, expectedLength) => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,8 @@ export function Record({ | |
status: recordStatus, | ||
state: recordState, | ||
version: recordVersion, | ||
publickey, | ||
signature: recordSignature, | ||
files = [] | ||
} = {}) { | ||
const token = recordToken || Token(); | ||
|
@@ -106,15 +108,19 @@ export function Record({ | |
signature, | ||
merkle: faker.datatype.hexaDecimal(64, false, /[0-9a-z]/) | ||
}; | ||
this.files = [new File(fileIndex), ...files.map((f) => new File(f))]; | ||
if (files.length == 2) { | ||
this.files = files; | ||
} else { | ||
this.files = [new File(fileIndex), ...files.map((f) => new File(f))]; | ||
} | ||
this.metadata = [ | ||
UserMetadata(user), | ||
RecordMetadata({ | ||
token, | ||
version, | ||
status, | ||
publickey: user.publickey, | ||
signature, | ||
publickey: publickey || user.publickey, | ||
recordSignature, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed some issues here. RecordMetadata has no |
||
timestamp | ||
}) | ||
]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.