feat: add tests for /api/chat (#950)
This commit is contained in:
parent
4ca93aaf89
commit
a159b77fcf
9 changed files with 197 additions and 50 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
UIMessage,
|
||||
type UIMessage,
|
||||
appendResponseMessages,
|
||||
createDataStreamResponse,
|
||||
smoothStream,
|
||||
|
|
@ -42,7 +42,7 @@ export async function POST(request: Request) {
|
|||
|
||||
const session = await auth();
|
||||
|
||||
if (!session || !session.user || !session.user.id) {
|
||||
if (!session?.user?.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ export async function POST(request: Request) {
|
|||
await saveChat({ id, userId: session.user.id, title });
|
||||
} else {
|
||||
if (chat.userId !== session.user.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
return new Response('Forbidden', { status: 403 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ export async function POST(request: Request) {
|
|||
});
|
||||
} catch (error) {
|
||||
return new Response('An error occurred while processing your request!', {
|
||||
status: 404,
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ export async function DELETE(request: Request) {
|
|||
|
||||
const session = await auth();
|
||||
|
||||
if (!session || !session.user) {
|
||||
if (!session?.user?.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
|
|
@ -183,12 +183,12 @@ export async function DELETE(request: Request) {
|
|||
const chat = await getChatById({ id });
|
||||
|
||||
if (chat.userId !== session.user.id) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
return new Response('Forbidden', { status: 403 });
|
||||
}
|
||||
|
||||
await deleteChatById({ id });
|
||||
const deletedChat = await deleteChatById({ id });
|
||||
|
||||
return new Response('Chat deleted', { status: 200 });
|
||||
return Response.json(deletedChat, { status: 200 });
|
||||
} catch (error) {
|
||||
return new Response('An error occurred while processing your request!', {
|
||||
status: 500,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue