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
Feat/jimmy test cookies #9
Conversation
This makes it consistent with the other methods in the context and possibly makes it easier to mock in tests.
UserService should only handle operations done on the User entity. Logout doesn't do any such operations and should thus belong in the resolver (i.e. controller).
Context should be handled in the resolver/controller layer.
The ServerContext interface should be agnostic about implementation details of how JWTs are set and cleared.
Doing this modularizes the express server to be used by supertest.
Since we are working with supertest, which is a bit lower-level than the previous testClient hook from Apollo-Server-Testing, the query method now takes in the GraphQL DocumentNode directly, converted to string using graphql's `print` method. The raw response now includes http headers, and the actual data is now in a JSON string, so we must parse it to achieve what testClient was previously doing for us.
We no longer need to mock/hardcode setting of cookies etc since our tests now actually use an express server, which handles these things.
We need to parse the `set-cookie` header in the raw response in our cookies tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good and works. One question - are we still mocking the db on queries (not actually making calls)? I can see testClient
is an instance of supertest
but it looks like its test app
argument is built with the same express server context as normal development server. I might not be understanding correctly
No, we are actually not mocking anything at the moment. Our index.ts takes |
Current tests use the apollo-server-testing library which provides a
query
andmutation
hook against theApolloServer
directly without going through HTTP. However, this library sucks (see apollographql/apollo-server#2277), and doesn't handle cookies at all. For thorough testing of routes that set cookies, we need to test whether cookies are set properly.The goal for this branch is to instead instantiate the express server loaded with app (i.e.
app
) and use the supertest library to run.post
against the express server. Similarly, this framework doesn't require an http service to be started.supertest
instead ofapollo-server-testing