Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Create integration test env that handles auth protected routes correctly #81

Closed
Bouncey opened this issue Apr 26, 2018 · 3 comments
Closed
Assignees
Labels
status: discussing status: PR has an associated pull request

Comments

@Bouncey
Copy link
Member

Bouncey commented Apr 26, 2018

No description provided.

@ojongerius
Copy link
Contributor

I started looking at this out of interest. It looks like we can easily created a mocked context, and pass it in to the query like so:

   // Create mock context
  const mockedContext = {
    headers: {
    'Content-Type': 'application/json',
    authorization: 'Bearer ' + token
    }
  };

  const rootValue = {};
  // Pass context into they query
  const result = await graphql(graphqlSchema, query, rootValue, mockedContext);

This will make tests return correct responses for non existent and malformed tokens, still have to test against a correct token.

To do that, we create a random secret to use, have the server use that for the verification, and create the tokens using the same secret.

When that works we can make it reusable across tests, using the Jest global environment setup for Mongo.

@ojongerius
Copy link
Contributor

Ha! Just had lunch and creating a valid token really is as simple as:

const token = jwt.sign({ id: 123, name: 'Charlie' }, JWT_CERT);

I'll factor this so that it's available in the test environment and raise a PR.

@ojongerius ojongerius self-assigned this Apr 27, 2018
@ojongerius ojongerius added the status: PR has an associated pull request label Apr 27, 2018
@ojongerius
Copy link
Contributor

Changes from #83 were merged in via #58

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: discussing status: PR has an associated pull request
Projects
None yet
Development

No branches or pull requests

2 participants