Skip to content

Commit

Permalink
Fixed breaking dto
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b authored and hsb1007 committed Jul 1, 2024
1 parent 55bd31a commit 40e21a0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
10 changes: 6 additions & 4 deletions src/auth/auth.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ describe('Auth Controller Tests', () => {
it('should be able to sign up using email', async () => {
const response = await app.inject({
method: 'POST',
url: '/auth/send-verification-email',
url: '/auth/email',
payload: {
email: '[email protected]',
},
});

expect(response.statusCode).toEqual(201);
expect(response.json().email).toEqual('[email protected]');
expect(response.json()).toEqual({
status: 'success',
});
});

it('should send verification code to email on sign up', async () => {
await app.inject({
method: 'POST',
url: '/auth/send-verification-email',
url: '/auth/email',
payload: {
email: '[email protected]',
},
Expand Down Expand Up @@ -101,7 +103,7 @@ describe('Auth Controller Tests', () => {
// Sign up
await app.inject({
method: 'POST',
url: '/auth/send-verification-email',
url: '/auth/email',
payload: {
email: '[email protected]',
},
Expand Down
27 changes: 11 additions & 16 deletions src/auth/service/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,17 @@ export class AuthService {
throw new NotFoundException('User not found');
}

const updatedUser = await this.prisma.user.update({
where: {
email,
},
data: {
isEmailVerified: true,
},
select: {
id: true,
email: true,
name: true,
profilePictureUrl: true,
authType: true,
isEmailVerified: true,
},
});
const updatedUser = plainToClass(
UserResponseDto,
await this.prisma.user.update({
where: {
email,
},
data: {
isEmailVerified: true,
},
}),
);

await this.prisma.verificationCode.delete({
where: {
Expand Down
20 changes: 19 additions & 1 deletion src/user/dto/user-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import { AuthType } from '@prisma/client';
import { Exclude } from 'class-transformer';
import { Exclude, Expose } from 'class-transformer';

@Exclude()
export default class UserResponseDto {
@Expose()
id: string;

@Expose()
email: string;

@Expose()
name: string;

@Expose()
location: string;

@Expose()
onboarded: boolean;

@Expose()
profilePictureUrl: string;

@Expose()
authType: AuthType;

@Expose()
isEmailVerified: boolean;

@Expose()
headline: string;
}
2 changes: 1 addition & 1 deletion src/user/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class UserService {
) {}

async getSelf(user: User) {
return user;
return plainToClass(UserResponseDto, user);
}

async updateSelf(user: User, dto: UpdateUserDto) {
Expand Down
11 changes: 9 additions & 2 deletions src/user/user.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('User Controller Tests', () => {
expect(prisma).toBeDefined();
});

it('should not be able to update itself if onboarding is not finished', async () => {
it('should be able to update itself if onboarding is not finished', async () => {
await prisma.user.update({
where: {
email: '[email protected]',
Expand All @@ -75,7 +75,14 @@ describe('User Controller Tests', () => {
},
});

expect(response.statusCode).toBe(401);
const updatedUser = await prisma.user.findUnique({
where: {
email: '[email protected]',
},
});
expect(updatedUser.name).toBe('Jane Doe');

expect(response.statusCode).toBe(200);
});

it('should be able to get the current user', async () => {
Expand Down

0 comments on commit 40e21a0

Please sign in to comment.