Skip to content

Instantly share code, notes, and snippets.

@dac09
Last active September 9, 2021 13:07
Show Gist options
  • Save dac09/07589346f37b422f6e03acee851eb93e to your computer and use it in GitHub Desktop.
Save dac09/07589346f37b422f6e03acee851eb93e to your computer and use it in GitHub Desktop.
import { contacts } from './contacts'
import type { StandardScenario } from './contacts.scenarios'
import { setContext } from '@redwoodjs/graphql-server'
const MOCKED_USER = {
id: 156,
name: 'Danny',
}
// Note: no import!
mockCurrentUser(MOCKED_USER)
// you can also do this:
// setContext({
// currentUser: MOCKED_USER,
// })
describe('contacts', () => {
scenario('returns all contacts', async (scenario: StandardScenario) => {
const result = await contacts()
expect(result.length).toEqual(Object.keys(scenario.contact).length)
})
})
import { db } from 'src/lib/db'
export const contacts = () => {
if (context?.currentUser?.name !== 'Danny') {
throw new Error('Boom, no way man. Only Danny can access this')
}
return db.contact.findMany()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment