Skip to content

Commit

Permalink
Fix more merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed May 15, 2024
1 parent cb40a03 commit 74551ce
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
9 changes: 2 additions & 7 deletions app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { redirect } from 'next/navigation'
import { getUserFromSession } from '#lib/session'

export async function saveNote(
noteId: string | undefined,
noteId: number | undefined,
title: string,
body: string,
) {
Expand All @@ -16,11 +16,6 @@ export async function saveNote(
if (!user) {
redirect('/')
}

if (!noteId) {
noteId = Date.now().toString()
}

const payload = {
id: noteId,
title: title.slice(0, 255),
Expand All @@ -37,7 +32,7 @@ export async function saveNote(
redirect(`/note/${noteId}`)
}

export async function deleteNote(noteId: string) {
export async function deleteNote(noteId: number) {
await db.note.delete({
where: {
id: noteId,
Expand Down
17 changes: 9 additions & 8 deletions app/note/edit/[id]/page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { expect, fireEvent, userEvent, within } from '@storybook/test'
import { Meta, StoryObj } from '@storybook/react'
import { cookies } from '@storybook/nextjs/headers.mock'
import Page from './page'
import { saveNote, deleteNote } from '#app/actions.mock'
import { deleteNote, saveNote } from '#app/actions.mock'
import { db } from '#lib/db'
import { createUserCookie, userCookieKey } from '#lib/session'
import { PageDecorator } from '#.storybook/decorators'

const meta = {
component: Page,
parameters: { layout: 'fullscreen' },
decorators: [PageDecorator],
async beforeEach() {
cookies().set(userCookieKey, await createUserCookie('storybookjs'))
Expand Down Expand Up @@ -70,21 +69,23 @@ export const Save: Story = {
})

await step('Save', async () => {
const saveButton = canvas.getByRole('menuitem', { name: /done/i })
await userEvent.click(saveButton)
await userEvent.click(
await canvas.findByRole('menuitem', { name: /done/i }),
)
await expect(saveNote).toHaveBeenCalledOnce()
await expect(saveNote).toHaveBeenCalledWith(
'2',
2,
'Edited Title',
'Edited Body',
)
})

await step('Delete', async () => {
const deleteButton = canvas.getByRole('menuitem', { name: /delete/i })
await userEvent.click(deleteButton)
await userEvent.click(
await canvas.findByRole('menuitem', { name: /delete/i }),
)
await expect(deleteNote).toHaveBeenCalledOnce()
await expect(deleteNote).toHaveBeenCalledWith('2')
await expect(deleteNote).toHaveBeenCalledWith(2)
})
},
}
2 changes: 1 addition & 1 deletion app/note/edit/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function EditPage({ params }: Props) {

const note = await db.note.findUnique({
where: {
id: params.id,
id: Number(params.id),
},
})

Expand Down
2 changes: 1 addition & 1 deletion components/note-editor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const meta = {
args: {
initialTitle: 'This is a title',
initialBody: 'This is a body',
noteId: '1',
noteId: 1,
}
} satisfies Meta<typeof NoteEditor>

Expand Down
2 changes: 1 addition & 1 deletion components/note-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { deleteNote, saveNote } from '#app/actions'
import Image from 'next/image'

type Props = {
noteId: string | undefined
noteId: number | undefined
initialTitle: string
initialBody: string
}
Expand Down

0 comments on commit 74551ce

Please sign in to comment.