Skip to content

Commit

Permalink
add should return user
Browse files Browse the repository at this point in the history
  • Loading branch information
Celesca committed Nov 20, 2024
1 parent a286e75 commit b5501e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const userController = new Elysia({ prefix: "/user" })
// Create a new user (sign-up)
.post(
"/create",
async ({ body, error }) => {
async ({ body, error, set }) => {
const { userName, email, password, workingStyle, profileImage, bio } = body;

const existingUser = await prisma.user.findUnique({
Expand Down Expand Up @@ -35,7 +35,11 @@ export const userController = new Elysia({ prefix: "/user" })
},
});

return newUser; // Return the newly created user
// return newUser and status 201
set.status = 201;
return newUser;


},
{
body: t.Object({
Expand Down
22 changes: 22 additions & 0 deletions test/userController.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'bun:test'
import { Elysia } from 'elysia'

describe('Create new user', () => {
it('should return a new user', async () => {
const app = new Elysia().post('/user/create', ({ body }) => {
return body
})

const response = await app
.handle(new Request('http://localhost:3000/user/create', {
method: 'POST',
body: JSON.stringify({
name: 'John Doe',
email: '[email protected]',
password: '1234',
})}))

//Expect response status to be 201 Created
expect(response.status).toBe(200)
})
})

0 comments on commit b5501e9

Please sign in to comment.