Closed VirginiaDooley closed 1 year ago
I'm trying to figure out how to run the correct data set for the corresponding environment. I tried creating a dedicated command to test mock
environment similar to the test
command here, but that did not change the test results. Advice very welcome.
I may be misunderstanding your question, but I think I see what you are getting at. I'll attempt to say something of use. You've got 6 commands for starting a dev server:
npm run dc:start:prod
: start the app using the DC theme, calling https://developers.democracyclub.org.uk/api/v1npm run dc:start:sandbox
: start the app using the DC theme, calling the sandbox endpoints https://developers.democracyclub.org.uk/api/v1/#sandbox-outputs-2npm run dc:start:mock
: start the app using the DC theme and using the mock data in https://github.com/DemocracyClub/WhereDoIVote-Widget/tree/master/public/example-responsesand
npm run ec:start:prod
: start the app using the EC theme, calling https://developers.democracyclub.org.uk/api/v1npm run ec:start:sandbox
: start the app using the EC theme, calling the sandbox endpoints https://developers.democracyclub.org.uk/api/v1/#sandbox-outputs-2npm run ec:start:mock
: start the app using the DC theme and using the mock data in https://github.com/DemocracyClub/WhereDoIVote-Widget/tree/master/public/example-responsesYou've got only one test command: npm test
. The tests start with REACT_APP_API=sandbox
, which does make it look like the integration tests would call the sandbox API if you don't explicitly call mockResponse()
but it is a red herring. It is just passing a value in here because the application will crap out here if you don't pass a valid value in for REACT_APP_API
this is mostly a good thing when it comes to making sure we build a valid app, but what actually happens under test is that regardless of what value you pass for REACT_APP_API
axios is completely mocked out to just return { data: {} }
as a baseline using a jest manual mock. Then you can call mockResponse()
to register a different mock response for .get
for each test that needs one. See:
REACT_APP_API=sandbox
in https://github.com/DemocracyClub/WhereDoIVote-Widget/blob/b07a892d399f22b22b2328db1611ebb260231d23/package.json#L56 would do something, but it actually does nothing. Tbh, if this was in a file format that allowed comments it would probably have one explaining all this, but you can't put comments in JSON so :shrug:.Does that help?
I may be misunderstanding your question, but I think I see what you are getting at. I'll attempt to say something of use. You've got 6 commands for starting a dev server:
npm run dc:start:prod
: start the app using the DC theme, calling https://developers.democracyclub.org.uk/api/v1npm run dc:start:sandbox
: start the app using the DC theme, calling the sandbox endpoints https://developers.democracyclub.org.uk/api/v1/#sandbox-outputs-2npm run dc:start:mock
: start the app using the DC theme and using the mock data in https://github.com/DemocracyClub/WhereDoIVote-Widget/tree/master/public/example-responsesand
npm run ec:start:prod
: start the app using the EC theme, calling https://developers.democracyclub.org.uk/api/v1npm run ec:start:sandbox
: start the app using the EC theme, calling the sandbox endpoints https://developers.democracyclub.org.uk/api/v1/#sandbox-outputs-2npm run ec:start:mock
: start the app using the DC theme and using the mock data in https://github.com/DemocracyClub/WhereDoIVote-Widget/tree/master/public/example-responsesYou've got only one test command:
npm test
. The tests start withREACT_APP_API=sandbox
, which does make it look like the integration tests would call the sandbox API if you don't explicitly callmockResponse()
but it is a red herring. It is just passing a value in here because the application will crap out here if you don't pass a valid value in forREACT_APP_API
this is mostly a good thing when it comes to making sure we build a valid app, but what actually happens under test is that regardless of what value you pass forREACT_APP_API
axios is completely mocked out to just return{ data: {} }
as a baseline using a jest manual mock. Then you can callmockResponse()
to register a different mock response for.get
for each test that needs one. See:
- https://github.com/DemocracyClub/WhereDoIVote-Widget/blob/master/src/__mocks__/axios.js
- https://jestjs.io/docs/manual-mocks
Again, this is also mostly a good thing. You don't really want your tests calling live APIs if you forget to mock something. This does have a couple of tradeoffs though:
- It leads to a situation where it looks like changing
REACT_APP_API=sandbox
in https://github.com/DemocracyClub/WhereDoIVote-Widget/blob/b07a892d399f22b22b2328db1611ebb260231d23/package.json#L56 would do something, but it actually does nothing. Tbh, if this was in a file format that allowed comments it would probably have one explaining all this, but you can't put comments in JSON so 🤷.- You can't rely on the integration tests if you're updating axios because the whole package is mocked under test - you really need to actually run the app locally and make some queries against the live or sandbox API to verify an upgrade to axios is non-breaking.
Does that help?
Yes, that does help, thank you. Re: 2 - I've run the app and verified I'm getting the right data and corresponding text for postcode. I would still feel better if I could test it.
- You can't rely on the integration tests if you're updating axios because the whole package is mocked under test
Re: 2 - I've run the app and verified I'm getting the right data and corresponding text for postcode. I would still feel better if I could test it.
So just to note: the axios version isn't being touched in this PR, but I assume you mean when you were working on https://github.com/DemocracyClub/WhereDoIVote-Widget/pull/649
If you want to solve that problem for axios upgrades, you could switch your mocking approach to something like nock which moves the mocking a layer out to mocking the node HTTP API instead of the HTTP client library. That way you could rely on the tests when upgrading axios because your client library code still runs when you make a request - its just taking to a mock node HTTP API.
I'll leave you to think about whether the mileage you'd get out of that change is worth the churn of migrating.
Reading the text in the fewer candidates than seats scenario, you've included text from WCIVF which is not relevant to WDIV: "No votes will be cast, and the candidate below has been automatically declared the winner." Can this sentence be removed?
Reading the text in the fewer candidates than seats scenario, you've included text from WCIVF which is not relevant to WDIV: "No votes will be cast, and the candidate below has been automatically declared the winner." Can this sentence be removed?
Thank you for catching that. I've removed that sentence from English and Welsh translations as requested with 4887fc6.
Closes https://github.com/DemocracyClub/WhereDoIVote-Widget/issues/645
As noted in the comments below, uncontested responses could not be tested in detail. Since the current staging configuration only works with sandbox data, I've included screenshots for uncontested mock data:
**SS30AA - Number of candidates === available seats
**SS30AB - Number of candidates < available seats
**SS30AC - Zero candidates