shapeshift / web

ShapeShift Web
https://app.shapeshift.com
MIT License
157 stars 180 forks source link

Mock all Cypress requests #1103

Closed 0xApotheosis closed 2 years ago

0xApotheosis commented 2 years ago

Note: Please see the discussion below about using cypress-autorecord - this is now the preferred approach.

Overview

For our Cypress tests, we currently mock only the data that is required by the UI elements and flows that we actually test.

We don't, however, mock the remaining calls, which slows down our test runs.

Reference

See the current mocks for external requests (those services not managed by ShapeShift), and internal requests (those that ShapeShift are responsible for) as an example of what we are looking to extend.

To find out what requests Cypress is currently making, we can run Cypress locally using yarn test:cypress, which will launch a local Cypress runner. Run the tests with Electron, and monitor the network tab for requests.

Examples of requests to mock:

Note, running Cypress locally requires web to be running locally - please see the README for instructions on doing this.

Some of the responses from these requests are large - the bounty hunter should use their discretion by only including data that is actually used by ShapeShift Web. We want to avoid having unnecessarily large mock data files in the codebase, and also avoid the illusion of precision that these mock files might give. The responses to these requests are out of our control, and could change at any time - only mocking the data we use is one way to mitigate the risk of mock data becoming stale.

No-opping requests that we don't need in the test environment is ok.

To keep this work decoupled from the test-related mock data, we probably want to have a new set a new set of Cypress commands, mockExternalEnvironmentRequests, and mockInternalEnvironmentRequests (or similar - use own discretion). There will likely sit in their own helper file in the cypress/support directory.

Acceptance Criteria

Screenshots/Mockups

In the example below, only the request with the alias getChainLinkData is mocked - in the resulting PR, we want to mock the rest.

Screen Shot 2022-03-03 at 11 54 21 am

Ownership

gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 2750.0 FOX (893.94 USD @ $0.33/FOX) attached to it as part of the ShapeShift fund.

0xean commented 2 years ago

@bernardstanislas - Looking forward to your contributions here! Would you be able to give an expected timeline for your PR? TY.

Bernardstanislas commented 2 years ago

I think I'll be able to send you a first draft by the end of the week if that suits you?

0xean commented 2 years ago

Sounds great, thanks for the update.

0xApotheosis commented 2 years ago

Thanks @Bernardstanislas - please add me as a reviewer to your PR once you're ready.

Bernardstanislas commented 2 years ago

I just started to look at the number of external calls, I am wondering about the cost of maintaining the mocks in the future.

I know vcr from the ruby world, which records external calls and then can replay them as mocks. I searched if there was an equivalent for Cypress and I came across this https://github.com/Nanciee/cypress-autorecord

What are your thoughts about doing it this way? I think it will be easier to maintain in the future and more accurate in terms of sticking to the reality if you put in place a policy of mock updates, let's say every week.

0xApotheosis commented 2 years ago

This could work @Bernardstanislas. I'll take a moment to review Cypress Autorecord, it could indeed be a better long-term approach.

Thanks for the initiative!

0xApotheosis commented 2 years ago

@Bernardstanislas this approach sounds reasonable. Some thoughts on the implementation:

With all of this in mind, this sounds good to me.

Bernardstanislas commented 2 years ago

Ok @0xApotheosis this is clear to me. Unfortunately I think I won't have time to work on this in the coming weeks, I'm sorry I hadn't planned that I would be kept busy with my current job on my free time. Feel free to remove me from the Gitcoin plateform. Sorry again

0xApotheosis commented 2 years ago

Thanks for the update @Bernardstanislas, we've removed you from the bounty.

gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Workers have applied to start work.

These users each claimed they can complete the work by 264 years, 7 months from now. Please review their action plans below:

1) ezhimakov has applied to start work _(Funders only: approve worker | reject worker)_.

i'll try to mock all requests on my local server and send a PR 2) visitskyworld has applied to start work _(Funders only: approve worker | reject worker)_.

I can work on this bounty and will mock all cypress request using cypress.intercept()

Learn more on the Gitcoin Issue Details page.

0xApotheosis commented 2 years ago

@codinglittlecat I didn't have time to update the bounty description after the conversation above re: using cypress-autorecord to auto-capture responses.

Could you please use this in your solution?

0xApotheosis commented 2 years ago

Hey @codinglittlecat, could you please confirm if you've seen this?

codinglittlecat commented 2 years ago

@0xApotheosis , I will use cypress-autorecord to auto-capture.

0xApotheosis commented 2 years ago

@0xApotheosis , I will use cypress-autorecord to auto-capture.

Thank you, ser.

codinglittlecat commented 2 years ago

@0xApotheosis Should I remove existing mocks and interceptions?

0xApotheosis commented 2 years ago

@codinglittlecat some mocks are designed to exert specific behaviour in the UX, which is tested by Cypress. These mocks need to stay, and override the auto-generated mocks.

Basically, if you remove a hard coded mock and a Cypress test breaks, you'll need to keep it. The rest can go.

codinglittlecat commented 2 years ago

Thanks. If we use cypress-autorecord, we don't need to mock all data and intercepts. I am not sure some of accpetnace of creteria is needed. e.g.

Each stub should be given an alias, e.g. cy.intercept('GET', 'some-url', { responseKey: 'responseValue' }).as('someAlias')

0xApotheosis commented 2 years ago

Indeed - acknowledging that the AC is a little bit off now, we'll be pragmatic about this so long as the solution meets cypress-autorecord best practices and is aligned with the intent of the bounty 👌

Feel free to reach out to me on Discord to chat through any clarifications or questions as you go.

gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 2750.0 FOX (758.93 USD @ $0.28/FOX) has been submitted by:

  1. @codinglittlecat

@0xean please take a look at the submitted work:


gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


The funding of 2750.0 FOX (903.49 USD @ $0.33/FOX) attached to this issue has been cancelled by the bounty submitter

0xean commented 2 years ago

@purelycrickets - to bounty