Last active
September 9, 2021 13:07
-
-
Save dac09/07589346f37b422f6e03acee851eb93e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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