Update best-practice for testing GraphQL mutations to be unit + small request
About
Our GraphQL styleguide currently mentions only request-style testing of GraphQL mutations, but not unit test-style.
In this thread it was discussed whether we should make it best-practice to test GraphQL mutations as unit-tests, with minimal request spec testing, due to unit tests executing faster.
Testing the speed difference locally: The set_due_date_spec.rb
unit test benchmarks as around 4x faster to run than the corresponding set_due_date_spec.rb
request test, which contains the same tests.
Current practice
Looking at the way our GraphQL mutations are currently tested:
- Some mutations only tested as request specs, e.g.: all
/notes
mutations - Some mutations tested as both unit-style and request-style: e.g.:
issues/set_due_date
unit and request and arguably there is large (redundant) duplication of test coverage between the two types
Proposal
Change our GraphQL Styleguide:
Unit test mutations:
Test mutations unit-test style. As authorizations are handled within the resolve, this test will also include all authorization tests
Minimal request test
Each mutation should have a request spec that tests that all expected fields are returned. This test will prove that the mutation is mounted in the schema and works with our instrumentation (i.e., the complexity analyzer does not fail the query). Request specs will not duplicate tests that the unit-test covers (i.e., authorization, errors).