Skip to content

Commit

Permalink
update:Add->FixErrorLogicAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
DevAnonitos committed May 17, 2024
1 parent bfbd9a3 commit e7d7ef3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 14 additions & 0 deletions __tests__/api/prompt/route.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @jest-environment node
*/
import { GET } from "@/app/api/prompt/route";
describe('API Prompt', () => {
it('should [GET]: response data as JSON from API Route', async () => {
const res = await GET();
const data = await res.json();
console.log(data);
expect(res.statusCode).toEqual(200);
expect(data).toBeDefined();
expect(data.length).toBe(1)
});
});
5 changes: 3 additions & 2 deletions app/api/prompt/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export const GET = async (request) => {
status: 200,
});
} catch (error) {
return new Response(JSON("Fail to fetch All prompts", {
console.log(error);
return new Response(JSON.stringify("Fail to fetch All prompts"), {
status: 500,
}))
});
}
};
6 changes: 3 additions & 3 deletions app/api/users/[id]/posts/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export const GET = async (request, { params }) => {
}

const prompts = await Prompt.find({ creator: params.id }).populate("creator");

return new Response(JSON.stringify(prompts), {
status: 200,
});
} catch (error) {
console.log(error);
return new Response("Failed to fetch prompts created by user", {
status: 500
return new Response(JSON.stringify("Failed to fetch prompts created by user"), {
status: 500,
});
}
};

0 comments on commit e7d7ef3

Please sign in to comment.