v0.35.0
This commit is contained in:
@@ -9,8 +9,10 @@ import services from 'src/services/**/*.{js,ts}'
|
||||
|
||||
import { getCurrentUser } from 'src/lib/auth'
|
||||
import { db } from 'src/lib/db'
|
||||
import { logger } from 'src/lib/logger'
|
||||
|
||||
export const handler = createGraphQLHandler({
|
||||
loggerConfig: { logger, options: {} },
|
||||
getCurrentUser,
|
||||
schema: makeMergedSchema({
|
||||
schemas,
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { db } from 'src/lib/db'
|
||||
import { requireAuth } from 'src/lib/auth'
|
||||
|
||||
// Used when the environment variable REDWOOD_SECURE_SERVICES=1
|
||||
export const beforeResolver = (rules) => {
|
||||
rules.add(requireAuth)
|
||||
}
|
||||
|
||||
export const posts = () => {
|
||||
return db.post.findMany()
|
||||
}
|
||||
@@ -12,14 +17,12 @@ export const post = ({ id }) => {
|
||||
}
|
||||
|
||||
export const createPost = ({ input }) => {
|
||||
requireAuth()
|
||||
return db.post.create({
|
||||
data: input,
|
||||
})
|
||||
}
|
||||
|
||||
export const updatePost = ({ id, input }) => {
|
||||
requireAuth()
|
||||
return db.post.update({
|
||||
data: input,
|
||||
where: { id },
|
||||
@@ -27,7 +30,6 @@ export const updatePost = ({ id, input }) => {
|
||||
}
|
||||
|
||||
export const deletePost = ({ id }) => {
|
||||
requireAuth()
|
||||
return db.post.delete({
|
||||
where: { id },
|
||||
})
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
export const standard = defineScenario({
|
||||
post: {
|
||||
first: {
|
||||
title: 'First Post',
|
||||
body: 'Lorem ipsum dolar sit amet',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const withLongBody = defineScenario({
|
||||
post: {
|
||||
long: {
|
||||
title: 'First Post',
|
||||
body:
|
||||
"I'm baby succulents single-origin coffee coloring book taxidermy sartorial. Irony woke tilde, gentrify you probably haven't heard of them tumblr typewriter enamel pin brunch viral live-edge. Pok pok plaid fingerstache, copper mug pitchfork pickled 3 wolf moon farm-to-table sustainable. Jean shorts freegan salvia tofu dreamcatcher vaporware asymmetrical +1. Pabst gentrify keytar ennui mixtape. Franzen tbh cred austin, health goth intelligentsia flannel pug you probably haven't heard of them 8-bit try-hard tumeric 3 wolf moon cray. Tumeric edison bulb distillery slow-carb subway tile authentic literally kinfolk venmo.\n Food truck pop-up ugh, tacos gluten-free lyft readymade four dollar toast brunch palo santo quinoa. Mixtape twee meh chicharrones lyft. Helvetica succulents brooklyn, farm-to-table +1 quinoa mlkshk vegan you probably haven't heard of them hella bespoke af. Tilde distillery taxidermy artisan, chillwave tofu direct trade raclette polaroid deep v sustainable. Chambray iPhone letterpress, helvetica XOXO wayfarers migas. Hoodie roof party tilde cornhole, heirloom normcore copper mug schlitz meditation YOLO lumbersexual franzen drinking vinegar gluten-free swag.",
|
||||
},
|
||||
one: { title: 'String', body: 'String' },
|
||||
two: { title: 'String', body: 'String' },
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,16 +1,41 @@
|
||||
import { posts, post } from './posts'
|
||||
import { posts, post, createPost, updatePost, deletePost } from './posts'
|
||||
|
||||
describe('posts', () => {
|
||||
scenario('returns a list of posts', async (scenario) => {
|
||||
const list = await posts()
|
||||
scenario('returns all posts', async (scenario) => {
|
||||
const result = await posts()
|
||||
|
||||
expect(list.length).toEqual(Object.keys(scenario.post).length)
|
||||
expect(list[0].title).toEqual(scenario.post.first.title)
|
||||
expect(result.length).toEqual(Object.keys(scenario.post).length)
|
||||
})
|
||||
|
||||
scenario('returns a single post by ID', async (scenario) => {
|
||||
const record = await post({ id: scenario.post.first.id })
|
||||
scenario('returns a single post', async (scenario) => {
|
||||
const result = await post({ id: scenario.post.one.id })
|
||||
|
||||
expect(record.title).toEqual(scenario.post.first.title)
|
||||
expect(result).toEqual(scenario.post.one)
|
||||
})
|
||||
|
||||
scenario('creates a post', async () => {
|
||||
const result = await createPost({
|
||||
input: { title: 'String', body: 'String' },
|
||||
})
|
||||
|
||||
expect(result.title).toEqual('String')
|
||||
expect(result.body).toEqual('String')
|
||||
})
|
||||
|
||||
scenario('updates a post', async (scenario) => {
|
||||
const original = await post({ id: scenario.post.one.id })
|
||||
const result = await updatePost({
|
||||
id: original.id,
|
||||
input: { title: 'String2' },
|
||||
})
|
||||
|
||||
expect(result.title).toEqual('String2')
|
||||
})
|
||||
|
||||
scenario('deletes a post', async (scenario) => {
|
||||
const original = await deletePost({ id: scenario.post.one.id })
|
||||
const result = await post({ id: original.id })
|
||||
|
||||
expect(result).toEqual(null)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user