Replies: 3 comments 4 replies
-
We've had some brief internal discussions about this and have decided that mocking the APIs is the best path foward. Are we already doing this at all in the politeiagui repo? When we convert this work into issues, we should not mock the user API routes fow now. The user routes are being replaced on the backend as part of the user layer rewrite and we don't want to do work that will be invalidated in a few months. We can, however, start mocking all of the new API routes: records, comments, and ticketvote. |
Beta Was this translation helpful? Give feedback.
-
Hey guys, wrote a small tutorial to guide contributors to follow our e2e testing patters. I'm thinking about opening an issue with this description and then open other small issues for the specific e2e tests for each container. This can be used as a coordination issue so we can have a better view of the test coverage. Feel free to add more cases too 😁 After the discussion on #2576, we figured out that the best way to add E2E tests into the build pipeline was to mock API requests so we could run the cypress testing environment detached from Politeia backend. How to mock API requestsLuckily, Cypress has a good tool for tests: the Let's create a mocked API response for the // ============
// your-test.js
// ============
describe("Ticketvote inventory", () => {
it("can fetch the ticketvote inventory", () => {
cy.intercept("/api/ticketvote/v1/inventory", (req) => {
req.reply({
statusCode: 200, // set custom response status
body: {
vetted: {
unauthorized: ["abcdefg"], // return some fake token
},
},
});
});
// ...
// assertions regarding the ticketvote inventory
// ...
});
}); This will intercept the However, intercept commands can be used on many different tests, hence, they should be more generic. This is why we came up with middlewares, which are nothing but an interceptor + alias. Let's see how can we use the
export const middlewares = {
// ...
inventory: () =>
cy.intercept("/api/ticketvote/v1/inventory", (req) => {
req.reply({
statusCode: 200, // set custom response status
body: {
vetted: {
unauthorized: ["abcdefg"], // return some fake token
},
},
});
}),
// ...
};
import { middlewares as ticketVoteMiddlewares } from "./mock/ticketvote";
// ...
Cypress.Commands.add("middleware", (path, ...args) => {
const mw = get(path)({
ticketvote: ticketVoteMiddlewares,
// ... other middlewares
});
return mw(...args).as(path); // alias automatically generated
});
// ...
// ============
// your-test.js
// ============
describe("Ticketvote Inventory", () => {
it("can fetch the ticketvote inventory", () => {
cy.middleware("ticketvote.inventory"); // accessing the middleware path using the string pattern.
// ...
cy.wait("@ticketvote.inventory").its("status").should("eq", 200); // Success
// ...
});
// ...
});
Pi test casesIn order to write better e2e tests, we should give a priority to the user actions among the platform. Let's see the expected behavior for the following containers:
Proposal
Comments
Admin
|
Beta Was this translation helpful? Give feedback.
-
Update: we are now able to execute e2e tests on github ci using the mock structure. Here's a draft that illustrates the e2e execution on the build pipeline for the politeia app: https://github.com/victorgcramos/politeiagui/actions/runs/2792384449 However, e2e tests are only available for the new plugin-architecture, due to the lack of user layer implementation. The legacy app (which is currently on production) does not support this service on its build pipeline. |
Beta Was this translation helpful? Give feedback.
-
We would like to add the e2e tests to our build pipeline to make sure PRs aren't breaking them.
Note: Currently the e2e tests need running BE instance in order to run.
Beta Was this translation helpful? Give feedback.
All reactions