Skip to content
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

test: adds setup for mock-service-worker #127

Merged
merged 5 commits into from
Dec 4, 2020

Conversation

schottra
Copy link
Contributor

@schottra schottra commented Dec 4, 2020

This is the first step in using mock-service-worker to mock our data instead of the messy mocking at the apiContext or axios level.

The basic idea is that we have a set of mock objects defined in src/mocks and a set of handler functions for each of the endpoints we use (there are only a handful). There will be a default set of objects that are loaded into the mock server for simple uses cases. Specific cases can add additional single-test handlers via mockServer.use. I decorated the mock server object with insert* functions for adding handlers for a specific entity type, to reduce the clutter in tests.

This PR just gets mock-service-worker integrated with a few simple objects and fixes whatever broke in doing so (mostly around some tests of the AdminEntity code).

A note:
Going forward, we will not test things like whether the correct query params were passed to an API call. We will test what happens in the failure cases. If we really need to test a specific behavior on query params, MSW can be set up to handle the query params and return different data. And then we can allow the component to render the data in the special case and assert that it looks the way we expect

Change list

  • Added mock-service-worker
  • Updated the way our env variables are read to remove the unnecessary isServer() check. We can prefer process.env if it exists and otherwise try window.env.
  • Added handlers for WorkflowExecution, NodeExecution, Workflow and Project.
    • Note: Handlers all use a shared response function which will encode the response to protobuf and set the correct headers, since the client code in AdminEntity will expect that and attempt to decode it. This is about as realistic a response as we can get.
  • Added one mock object for a WF Execution and a small list of sample projects.
  • Added code to import and create handlers for the default data objects
  • Updated and/or removed some tests which were attempting to mock AdmintEntity. We will let them call all the way through to axios and operate data returned from our mock server.
  • Updated some import statements of AdminEntity to be more specific, since the index-type includes cause circular reference issues.
  • Moved around some constants for api path generation to make sure that the mock server and client code calling it will use the same prefix.
  • Added some temporary empty tests to make Jest happy until I refactor the suites in question in my next PR.
  • Upgraded typescript to fix error with types from msw, jest, ts-jest, and babel-jest to versions which support TS 4+. Fixed minors issues resulting from the upgrade.

@schottra schottra requested review from BobNisco and podehnal December 4, 2020 01:40
@@ -29,6 +29,8 @@ describe.skip('ExecutionNodeViews', () => {
props = { execution: workflowExecution };
});

it('is disabled', () => {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these intentionally kept in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. This keeps the test runner from throwing errors. I will remove them in the next PR when I fix and re-enable the commented-out tests.

@schottra schottra merged commit 95fb925 into execution-data-refactor Dec 4, 2020
@schottra schottra deleted the mock-service-worker branch December 4, 2020 20:24
schottra added a commit that referenced this pull request Jan 4, 2021
* test: add msw and basic handlers for a few types

* test: add mock data for a basic workflow execution

* test: fixing/removing tests after adding msw

* test: throw on unexpected requests to msw

* fix: upgrade TS to fix error and cleanup resulting errors
schottra added a commit that referenced this pull request Jan 5, 2021
* test: add msw and basic handlers for a few types

* test: add mock data for a basic workflow execution

* test: fixing/removing tests after adding msw

* test: throw on unexpected requests to msw

* fix: upgrade TS to fix error and cleanup resulting errors
schottra added a commit that referenced this pull request Jan 6, 2021
* refactor: integrate react-query for execution data fetching (#123)

* refactor: using react-query to load top level Execution

* refactor: upgrading react-query and fixing execution termination

* refactor: handle 401s on queries and do auth flow

* refactor: adding conditional refresh for execution status

* refactor: cleanup broken files after context refactor

* chore: docs

* refactor: Remove ExecutionDataCache in favor of react-query (#126)

* refactor: first step of using queries for NE table

* refactor: removing data cache from first layer of NE table

* refactor: removing remaining execution data cache usage

* refactor: rename QueryKey type and remove bug workaround

* refactor: fixing remaining consumers of NEs

* test: adds setup for mock-service-worker (#127)

* test: add msw and basic handlers for a few types

* test: add mock data for a basic workflow execution

* test: fixing/removing tests after adding msw

* test: throw on unexpected requests to msw

* fix: upgrade TS to fix error and cleanup resulting errors

* Migrate from TSLint to ESLint (#128)

* ci: move from tslint->eslint

* fix: addressing eslint errors

* fix: remove passing of unused variable

* ci: remove unnecessary prettier config

* refactor: clean up mock fixtures and re-enable tests for executions (#130)

* test: adding test data for node executions

* test: mocks and refactoring to re-enable NodeExecutionDetails tests

* chore: lint error

* test: getting first test for NE table working again

* test: mocks and a couple of tests for NE table

* refactor: msw handlers to use a backing map and return 404s

* test: more tests for NE table

* test: adding fixture for dynamic external workflow

* test: using mock fixture for sub workflow tests

* test: move remaining mocks to fixtures and fix tests

* test: re-enabling more execution tests

* fix: removing global query handlers for caching entitiesq

* test: re-enable ExecutionNodeViews tests

* fix: typo in import path

* fix: show DataError by default for failed queries

* chore: documentation

* chore: pr feedback

* test: fixing storybook rendering for NE table

* refactor: queries and loading states for (Task)ExecutionDetails

* chore: cleanup unused code

* fix: adds mock support for launch plans

* test: update LoadingSpinner tests

* fix: handle error case for NE children

* chore: remove todo

* fix: typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants