my-legacy-code / Growth

0 stars 0 forks source link

Add Unit Tests to GraphQL layer #19

Open CreatCodeBuild opened 6 years ago

CreatCodeBuild commented 6 years ago

Add mock style unit tests to GraphQL layer.

As a thumb of rule:

  1. We use Fake Adapter style to test use cases because use cases contain most of the logic.
  2. For IO layers, we prefer to Mock Adapter style because we care more about the correctness of API integrations here, assuming use case logic is always right.

The test flow is:

  1. Start GraphQL Http Server
  2. Build GraphQL query
  3. Send the query to the server
  4. Assert response. Do not assert on any server internal behaviors.

Potentially helpful packages:

  1. https://golang.org/pkg/net/http/httptest for test http server
  2. https://github.com/CreatCodeBuild/h for http client
  3. https://github.com/CreatCodeBuild/graphb for query building