Follow-up from "Use GraphQL to get list of vulnerable projects for group"
The following discussion from !38878 (merged) should be addressed:
-
@oregand started a discussion: suggestion(non-blocking)
We now can test mock GraphQL responses via :
import { createMockClient } from 'mock-apollo-client';
And
import { InMemoryCache } from 'apollo-cache-inmemory';
As you can see here:
spec/frontend/design_management/pages/index_apollo_spec.js
, which would make for a better set of specs against this queryi.e.
import { vulnerabilityGradesQueryResponse, } from '../mock_data/apollo_mock'; import vulnerabilityGradesQuery from '../graphql/group_vulnerability_grades.query.graphql'; mockClient.setRequestHandler( vulnerabilityGradesQuery, jest.fn().mockResolvedValue(vulnerabilityGradesQueryResponse), );
But I would be happy to see this as a follow-up as it's a new thing we have only introduced recently
😄
Implementation plan
-
Use createMockClient
andInMemoryCache
for the tests inee/spec/frontend/security_dashboard/components/first_class_vulnerability_severities_spec.js
. They currently usewrapper.setData()
to set the data that Apollo would've set had it done the GraphQL request, so rather than skip the Apollo call altogether, we should mock out the call instead.
Edited by Daniel Tian