Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions docker-compose.e2e.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
version: '3'
services:
app:
container_name: nestjs_boilerplate
container_name: nestjs_test
build: .
ports:
- '${PORT}:${PORT}'
- 3000:3000
depends_on:
- postgres
test_postgres:
condition: service_healthy
volumes:
- .:/app
- node_modules:/app/node_modules
command: npm run test:e2e
command: >
sh -c "
npm run test:e2e
"
env_file:
- .test.env

postgres:
test_postgres:
image: postgres
container_name: postgres
container_name: test_postgres
env_file:
- .test.env
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'postgres']
restart: unless-stopped
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
TZ: 'UTC'
PGTZ: 'UTC'
ports:
- '5432:5432'
- '5433:5432'
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql

volumes:
node_modules:
1 change: 1 addition & 0 deletions init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
12 changes: 12 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// jest.config.ts
export default {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
testEnvironment: 'node',
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"start:dev": "export NODE_ENV=development && nest start --watch",
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
"lint:fix": "eslint -c ./eslint.config.mjs \"{src,test}/**/*.ts\" --fix",
"test": "jest",
"test": "jest --config jest.config.ts",
"test:unit": "jest --testPathPattern='^(?!.*\\.integration\\.spec\\.ts$).*\\.spec\\.ts$'",
"test:integration": "jest --testPathPattern='\\.integration\\.spec\\.ts$'",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "rm -rf dist && jest --config ./test/jest-e2e.json",
"test:e2e:docker": "rm -rf dist && docker-compose -f docker-compose.e2e.yml --env-file ./.test.env up --exit-code-from app",
"test:e2e": "npm run build && jest --config ./test/jest-e2e.json",
"test:e2e:docker": "docker-compose -f docker-compose.e2e.yml --env-file ./.test.env up --build --exit-code-from app",
"g": "plop --plopfile ./generator/plopfile.mjs",
"prepare": "husky",
"typeorm": "export NODE_ENV=production&& ts-node ./node_modules/typeorm/cli.js -d ./src/common/config/ormconfig.ts",
Expand Down
2 changes: 0 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { envValidation } from './common/helper/env.validation';
import { LoggingModule } from './common/logging/logging.module';
import { HealthModule } from './health/health.module';
import { ResumeModule } from './resume/resume.module';
import { UploadModule } from './upload/upload.module';
import { UserModule } from './user/user.module';

@Module({
Expand All @@ -34,7 +33,6 @@ import { UserModule } from './user/user.module';
}),
UserModule,
AuthModule,
UploadModule,
HealthModule,
CustomCacheModule.forRoot(),
LoggingModule,
Expand Down
4 changes: 1 addition & 3 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { UserModule } from '../user/user.module';
import { EmailVerificationRepository } from './repositories/email-verification.repository';
import { AuthVerificationResolver } from './resolvers/auth-verification.resolver';
import { AuthResolver } from './resolvers/auth.resolver';
import { AuthMailService } from './services/auth-mail.serivice';
import { AuthMailService } from './services/auth-mail.service';
import { AuthVerificationService } from './services/auth-verification.service';
import { AuthService } from './services/auth.service';
// import { JwtRefreshStrategy } from './strategies/jwt-refresh.strategy';
import { JwtStrategy } from './strategies/jwt.strategy';
import { LocalStrategy } from './strategies/local.strategy';

Expand Down Expand Up @@ -44,7 +43,6 @@ import { LocalStrategy } from './strategies/local.strategy';
AuthService,
AuthResolver, // 이메일/비밀번호 로그인
JwtStrategy,
// JwtRefreshStrategy,
LocalStrategy,
AuthMailService,
AuthVerificationService,
Expand Down
10 changes: 5 additions & 5 deletions src/auth/entities/auth._entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, ObjectType } from '@nestjs/graphql';

@ObjectType()
export class UserResponse {
@ObjectType('AuthUserResponse')
export class AuthUserResponse {
@Field(() => String)
id: string;

Expand All @@ -12,11 +12,11 @@ export class UserResponse {
username: string;
}

@ObjectType()
@ObjectType('JwtWithUser')
export class JwtWithUser {
@Field(() => String)
jwt: string;

@Field(() => UserResponse)
user: UserResponse;
@Field(() => AuthUserResponse)
user: AuthUserResponse;
}
2 changes: 1 addition & 1 deletion src/auth/entities/email-verification.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Field, ID, ObjectType } from '@nestjs/graphql';
import { Column, CreateDateColumn, Entity, PrimaryColumn } from 'typeorm';
import { ulid } from 'ulid';

@ObjectType()
@ObjectType('EmailVerification')
@Entity('email_verifications')
export class EmailVerification {
@Field(() => ID)
Expand Down
16 changes: 8 additions & 8 deletions src/auth/inputs/apple-login.input.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Field, InputType } from '@nestjs/graphql';
// import { Field, InputType } from '@nestjs/graphql';

@InputType()
export class AppleLoginInput {
@Field()
idToken: string;
// @InputType()
// export class AppleLoginInput {
// @Field()
// idToken: string;

@Field({ nullable: true })
user?: string; // Apple에서 name 정보는 처음 로그인 시에만 전달됨
}
// @Field({ nullable: true })
// user?: string; // Apple에서 name 정보는 처음 로그인 시에만 전달됨
// }
4 changes: 2 additions & 2 deletions src/auth/inputs/auth.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Field, InputType } from '@nestjs/graphql';

import { IsEmail, IsNotEmpty, Matches, MinLength } from 'class-validator';

@InputType()
@InputType('SignInInputType', { isAbstract: true })
export class SignInInput {
@Field(() => String)
@IsNotEmpty()
Expand All @@ -13,7 +13,7 @@ export class SignInInput {
password?: string;
}

@InputType()
@InputType('SignUpInputType', { isAbstract: true })
export class SignUpInput {
@Field(() => String)
@IsNotEmpty()
Expand Down
12 changes: 6 additions & 6 deletions src/auth/inputs/kakao-login.input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, InputType } from '@nestjs/graphql';
// import { Field, InputType } from '@nestjs/graphql';

@InputType()
export class KakaoLoginInput {
@Field()
accessToken: string;
}
// @InputType()
// export class KakaoLoginInput {
// @Field()
// accessToken: string;
// }
12 changes: 6 additions & 6 deletions src/auth/inputs/naver-login.input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, InputType } from '@nestjs/graphql';
// import { Field, InputType } from '@nestjs/graphql';

@InputType()
export class NaverLoginInput {
@Field()
accessToken: string;
}
// @InputType()
// export class NaverLoginInput {
// @Field()
// accessToken: string;
// }
38 changes: 19 additions & 19 deletions src/auth/inputs/social-login.input.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Field, InputType } from '@nestjs/graphql';
// import { Field, InputType } from '@nestjs/graphql';

import { IsEmail, IsEnum, IsString } from 'class-validator';
// import { IsEmail, IsEnum, IsString } from 'class-validator';

import { SocialProvider } from '../../user/enum/social-provider.enum';
// import { SocialProvider } from '../../user/enum/social-provider.enum';

@InputType()
export class SocialLoginInput {
@Field(() => SocialProvider)
@IsEnum(SocialProvider)
provider: SocialProvider;
// @InputType()
// export class SocialLoginInput {
// @Field(() => SocialProvider)
// @IsEnum(SocialProvider)
// provider: SocialProvider;

@Field(() => String)
@IsString()
providerId: string;
// @Field(() => String)
// @IsString()
// providerId: string;

@Field(() => String, { nullable: true })
@IsString()
@IsEmail()
email?: string;
// @Field(() => String, { nullable: true })
// @IsString()
// @IsEmail()
// email?: string;

@Field(() => String, { nullable: true })
@IsString()
nickname?: string;
}
// @Field(() => String, { nullable: true })
// @IsString()
// nickname?: string;
// }
2 changes: 1 addition & 1 deletion src/auth/repositories/email-verification.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dayjs from 'dayjs';
import * as dayjs from 'dayjs';
import { EntityManager } from 'typeorm';

import { CustomRepository } from '../../common/decorators/typeorm.decorator';
Expand Down
48 changes: 48 additions & 0 deletions src/auth/services/auth-mail.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Test, TestingModule } from '@nestjs/testing';

import { MailerService } from '@nestjs-modules/mailer';

import { AuthMailService } from './auth-mail.service';

describe('AuthMailService', () => {
let service: AuthMailService;
let mailerService: MailerService;

const mockMailerService = {
sendMail: jest.fn(),
};

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
AuthMailService,
{
provide: MailerService,
useValue: mockMailerService,
},
],
}).compile();

service = module.get<AuthMailService>(AuthMailService);
mailerService = module.get<MailerService>(MailerService);
});

afterEach(() => {
jest.clearAllMocks();
});

it('should send verification code to email', async () => {
const email = 'test@example.com';
const code = '123456';

await service.sendVerificationCode(email, code);

expect(mailerService.sendMail).toHaveBeenCalledTimes(1);
expect(mailerService.sendMail).toHaveBeenCalledWith({
to: email,
subject: '[ResumeLog] 이메일 인증 코드',
template: 'verify-email',
context: { code },
});
});
});
Loading