You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need help to address an issue which I am seeing while writing unit test cases for the data fetcher.
Here is my DataFetcher:
`@Slf4j
@DgsComponent @transactional(readOnly = true)
public class GetUserMetaDataDataFetcher {
@Autowired HttpServletRequest request;
@Autowired UserService userService;
@DgsData(parentType = "Query", field = "userMetaData")
public UserMetaDataResult getUserMetaData(@InputArgument("schoolId") UUID schoolId) {
String userId = request.getHeader("USER_UUID");
if (isBlank(userId)) {
log.error("User UUID is missing in the header");
throw new BadRequestError("User ID is missing in the header which is required for the API to pull the data.");
}
return userService.getUser(userId, schoolId.toString());
}
}`
Here is unit test I have written for the datafetcher.
` @SpringBootTest(
classes = {
DgsAutoConfiguration.class,
GraphQLRuntimeWiring.class,
GetUserMetaDataDataFetcher.class,
DgsExtendedScalarsAutoConfiguration.class
})
public class GetResidualDocumentUploadDataFetcherTest {
And if I try to mock when(request.getHeader(eq(X_CHEGG_USER_UUID.getKey()))).thenReturn(userId);, its always null.
I don't want to change all my DataFetcher to pass header as an argument like below. @RequestHeader("USER_UUID") String userId
What are the other ways I can address this issue ? Its kind of blocker to achieve the unit test coverage goal which we have for the project. Need help.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I need help to address an issue which I am seeing while writing unit test cases for the data fetcher.
Here is my DataFetcher:
`@Slf4j
@DgsComponent
@transactional(readOnly = true)
public class GetUserMetaDataDataFetcher {
}`
Here is unit test I have written for the datafetcher.
`
@SpringBootTest(
classes = {
DgsAutoConfiguration.class,
GraphQLRuntimeWiring.class,
GetUserMetaDataDataFetcher.class,
DgsExtendedScalarsAutoConfiguration.class
})
public class GetResidualDocumentUploadDataFetcherTest {
}`
The problem with this is:
when(request.getHeader(eq(X_CHEGG_USER_UUID.getKey()))).thenReturn(userId);, its always null.I don't want to change all my DataFetcher to pass header as an argument like below.
@RequestHeader("USER_UUID") String userIdWhat are the other ways I can address this issue ? Its kind of blocker to achieve the unit test coverage goal which we have for the project. Need help.
Thanks in advance.
Thanks,
Deba
Beta Was this translation helpful? Give feedback.
All reactions