Skip to content
Open
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
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
"^.+\\.(t|j)s$": [
"ts-jest",
{
"tsconfig": {
"isolatedModules": false
},
"diagnostics": {
"ignoreCodes": [151002]
}
}
]
},
"collectCoverageFrom": [
"**/*.(t|j)s",
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/request-context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('request-context', () => {
const req = mockReq();
const info = mockInfo({
path: { key: 3, prev: undefined, typename: undefined },
} as unknown as GraphQLResolveInfo);
});
const meta = buildGraphqlRequestMeta(info, req);
expect(meta.path).toBe('3');
});
Expand Down
40 changes: 15 additions & 25 deletions src/features/auth/auth.seller.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ describe('AuthService (seller)', () => {
it('판매자 로그인 성공 시 accessToken과 accountStatus를 반환해야 한다', async () => {
// Arrange
jest.spyOn(argon2, 'verify').mockResolvedValue(true);
repo.findSellerCredentialByUsername.mockResolvedValue(
validCredential as never,
);
repo.findSellerCredentialByUsername.mockResolvedValue(validCredential);

// Act
const result = await service.sellerLogin({
Expand Down Expand Up @@ -182,7 +180,7 @@ describe('AuthService (seller)', () => {
},
};
repo.findSellerCredentialByUsername.mockResolvedValue(
nonSellerCredential as never,
nonSellerCredential,
);

// Act & Assert
Expand All @@ -207,9 +205,7 @@ describe('AuthService (seller)', () => {
it('비밀번호가 틀리면 UnauthorizedException을 던져야 한다', async () => {
// Arrange
jest.spyOn(argon2, 'verify').mockResolvedValue(false);
repo.findSellerCredentialByUsername.mockResolvedValue(
validCredential as never,
);
repo.findSellerCredentialByUsername.mockResolvedValue(validCredential);

// Act & Assert
await expect(
Expand Down Expand Up @@ -252,9 +248,7 @@ describe('AuthService (seller)', () => {

it('비밀번호를 성공적으로 변경해야 한다', async () => {
// Arrange
repo.findSellerCredentialByAccountId.mockResolvedValue(
sellerCredential as never,
);
repo.findSellerCredentialByAccountId.mockResolvedValue(sellerCredential);
// 첫 번째 호출: 현재 비밀번호 확인 (true)
// 두 번째 호출: 새 비밀번호 동일 여부 확인 (false = 다른 비밀번호)
jest
Expand Down Expand Up @@ -325,7 +319,7 @@ describe('AuthService (seller)', () => {
},
};
repo.findSellerCredentialByAccountId.mockResolvedValue(
nonSellerCredential as never,
nonSellerCredential,
);

// Act & Assert
Expand Down Expand Up @@ -354,9 +348,7 @@ describe('AuthService (seller)', () => {

it('현재 비밀번호가 틀리면 UnauthorizedException을 던져야 한다', async () => {
// Arrange
repo.findSellerCredentialByAccountId.mockResolvedValue(
sellerCredential as never,
);
repo.findSellerCredentialByAccountId.mockResolvedValue(sellerCredential);
jest.spyOn(argon2, 'verify').mockResolvedValue(false);

// Act & Assert
Expand All @@ -380,9 +372,7 @@ describe('AuthService (seller)', () => {

it('새 비밀번호가 기존 비밀번호와 동일하면 BadRequestException을 던져야 한다', async () => {
// Arrange
repo.findSellerCredentialByAccountId.mockResolvedValue(
sellerCredential as never,
);
repo.findSellerCredentialByAccountId.mockResolvedValue(sellerCredential);
// 현재 비밀번호 확인: true, 새 비밀번호 동일 여부: true (같은 비밀번호)
jest
.spyOn(argon2, 'verify')
Expand Down Expand Up @@ -434,7 +424,7 @@ describe('AuthService (seller)', () => {
created_at: new Date('2025-01-01'),
updated_at: new Date('2025-01-01'),
deleted_at: null,
} as never);
});

repo.rotateRefreshSession.mockResolvedValue({
id: BigInt(2),
Expand All @@ -458,7 +448,7 @@ describe('AuthService (seller)', () => {
status: 'ACTIVE' as const,
store: { id: BigInt(5) },
},
} as never);
});

// Act
const result = await service.refreshSeller(reqWithCookie, mockRes);
Expand Down Expand Up @@ -520,7 +510,7 @@ describe('AuthService (seller)', () => {
created_at: new Date('2025-01-01'),
updated_at: new Date('2025-01-01'),
deleted_at: null,
} as never);
});

repo.rotateRefreshSession.mockResolvedValue({
id: BigInt(2),
Expand Down Expand Up @@ -559,7 +549,7 @@ describe('AuthService (seller)', () => {
created_at: new Date('2025-01-01'),
updated_at: new Date('2025-01-01'),
deleted_at: null,
} as never);
});

repo.rotateRefreshSession.mockResolvedValue({
id: BigInt(2),
Expand Down Expand Up @@ -609,7 +599,7 @@ describe('AuthService (seller)', () => {
created_at: new Date('2025-01-01'),
updated_at: new Date('2025-01-01'),
deleted_at: null,
} as never);
});

repo.findSellerCredentialByAccountId.mockResolvedValue({
id: BigInt(1),
Expand All @@ -627,7 +617,7 @@ describe('AuthService (seller)', () => {
status: 'ACTIVE' as const,
store: { id: BigInt(5) },
},
} as never);
});

repo.revokeRefreshSession.mockResolvedValue({
id: BigInt(1),
Expand Down Expand Up @@ -692,7 +682,7 @@ describe('AuthService (seller)', () => {
created_at: new Date('2025-01-01'),
updated_at: new Date('2025-01-01'),
deleted_at: null,
} as never);
});

repo.findSellerCredentialByAccountId.mockResolvedValue(null);

Expand Down Expand Up @@ -723,7 +713,7 @@ describe('AuthService (seller)', () => {
created_at: new Date('2025-01-01'),
updated_at: new Date('2025-01-01'),
deleted_at: null,
} as never);
});

repo.findSellerCredentialByAccountId.mockResolvedValue({
id: BigInt(1),
Expand Down
2 changes: 1 addition & 1 deletion src/features/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('AuthService', () => {
}),
} as never);

mockOidc.toIdentityProvider.mockReturnValue('GOOGLE' as never);
mockOidc.toIdentityProvider.mockReturnValue('GOOGLE');

mockRepo.upsertUserByOidcIdentity.mockResolvedValue({
account: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'reflect-metadata';

import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';

import { SellerAddProductImageInput } from '@/features/seller/dto/inputs/seller-add-product-image.input';

function build(plain: object): SellerAddProductImageInput {
return plainToInstance(SellerAddProductImageInput, plain);
}

describe('SellerAddProductImageInput', () => {
it('필수만 통과', async () => {
const dto = build({ productId: '1', imageUrl: 'https://x/y.jpg' });
expect(await validate(dto)).toHaveLength(0);
});

it('sortOrder 포함 통과', async () => {
const dto = build({
productId: '1',
imageUrl: 'https://x/y.jpg',
sortOrder: 2,
});
expect(await validate(dto)).toHaveLength(0);
});

it('imageUrl 누락 거절', async () => {
const dto = build({ productId: '1' });
const errors = await validate(dto);
expect(errors[0].property).toBe('imageUrl');
});

it('sortOrder 가 정수가 아니면 거절', async () => {
const dto = build({
productId: '1',
imageUrl: 'x',
sortOrder: 1.5,
});
const errors = await validate(dto);
expect(errors[0].property).toBe('sortOrder');
});
});
13 changes: 13 additions & 0 deletions src/features/seller/dto/inputs/seller-add-product-image.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { IsInt, IsOptional, IsString } from 'class-validator';

export class SellerAddProductImageInput {
@IsString()
productId!: string;

@IsString()
imageUrl!: string;

@IsOptional()
@IsInt()
sortOrder?: number;
}
28 changes: 28 additions & 0 deletions src/features/seller/dto/inputs/seller-audit-log-list.input.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'reflect-metadata';

import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';

import { SellerAuditLogListInput } from '@/features/seller/dto/inputs/seller-audit-log-list.input';

function build(plain: object): SellerAuditLogListInput {
return plainToInstance(SellerAuditLogListInput, plain);
}

describe('SellerAuditLogListInput', () => {
it('빈 입력 허용', async () => {
const dto = build({});
expect(await validate(dto)).toHaveLength(0);
});

it('targetType 허용 값 통과', async () => {
const dto = build({ targetType: 'STORE' });
expect(await validate(dto)).toHaveLength(0);
});

it('알 수 없는 targetType 거절', async () => {
const dto = build({ targetType: 'INVALID' });
const errors = await validate(dto);
expect(errors[0].property).toBe('targetType');
});
});
18 changes: 18 additions & 0 deletions src/features/seller/dto/inputs/seller-audit-log-list.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IsIn, IsOptional } from 'class-validator';

import { SellerCursorInput } from '@/features/seller/dto/inputs/seller-cursor.input';

const AUDIT_TARGET_TYPES = [
'STORE',
'PRODUCT',
'ORDER',
'CONVERSATION',
'CHANGE_PASSWORD',
] as const;
type SellerAuditTargetType = (typeof AUDIT_TARGET_TYPES)[number];

export class SellerAuditLogListInput extends SellerCursorInput {
@IsOptional()
@IsIn(AUDIT_TARGET_TYPES)
targetType?: SellerAuditTargetType;
}
103 changes: 103 additions & 0 deletions src/features/seller/dto/inputs/seller-create-banner.input.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import 'reflect-metadata';

import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';

import { SellerCreateBannerInput } from '@/features/seller/dto/inputs/seller-create-banner.input';

function build(plain: object): SellerCreateBannerInput {
return plainToInstance(SellerCreateBannerInput, plain);
}

describe('SellerCreateBannerInput', () => {
it('필수만 통과', async () => {
const dto = build({ placement: 'HOME_MAIN', imageUrl: 'https://x/y.jpg' });
expect(await validate(dto)).toHaveLength(0);
});

it('전체 필드 통과', async () => {
const dto = build({
placement: 'CATEGORY',
title: '여름 배너',
imageUrl: 'https://x/y.jpg',
linkType: 'URL',
linkUrl: 'https://caquick.site/promo',
startsAt: new Date('2026-06-01'),
endsAt: new Date('2026-08-31'),
sortOrder: 1,
isActive: true,
});
expect(await validate(dto)).toHaveLength(0);
});

it('placement 누락 거절', async () => {
const dto = build({ imageUrl: 'https://x/y.jpg' });
const errors = await validate(dto);
expect(errors[0].property).toBe('placement');
});

it('imageUrl 누락 거절', async () => {
const dto = build({ placement: 'HOME_MAIN' });
const errors = await validate(dto);
expect(errors[0].property).toBe('imageUrl');
});

it('알 수 없는 placement 거절', async () => {
const dto = build({ placement: 'INVALID', imageUrl: 'https://x/y.jpg' });
const errors = await validate(dto);
expect(errors[0].property).toBe('placement');
});

it('알 수 없는 linkType 거절', async () => {
const dto = build({
placement: 'HOME_MAIN',
imageUrl: 'https://x/y.jpg',
linkType: 'UNKNOWN',
});
const errors = await validate(dto);
expect(errors[0].property).toBe('linkType');
});

it('startsAt 가 Date 가 아니면 거절', async () => {
const dto = build({
placement: 'HOME_MAIN',
imageUrl: 'https://x/y.jpg',
startsAt: '2026-06-01',
});
const errors = await validate(dto);
expect(errors[0].property).toBe('startsAt');
});

it.each([
['title', { title: 12345 }, 'title'],
['imageUrl 가 문자열 아님', { imageUrl: 12345 }, 'imageUrl'],
['linkUrl', { linkUrl: 12345 }, 'linkUrl'],
['linkProductId', { linkProductId: 12345 }, 'linkProductId'],
['linkStoreId', { linkStoreId: 12345 }, 'linkStoreId'],
['linkCategoryId', { linkCategoryId: 12345 }, 'linkCategoryId'],
['endsAt', { endsAt: '2026-06-01' }, 'endsAt'],
['sortOrder 가 정수 아님', { sortOrder: 1.5 }, 'sortOrder'],
['isActive 가 boolean 아님', { isActive: 'true' }, 'isActive'],
])(
'각 선택 필드 타입 오류 거절: %s',
async (_label, override, expectedProp) => {
const base = { placement: 'HOME_MAIN', imageUrl: 'https://x/y.jpg' };
const dto = build({ ...base, ...override });
const errors = await validate(dto);
expect(errors.some((e) => e.property === expectedProp)).toBe(true);
},
);

it('linkProductId · linkStoreId · linkCategoryId 가 null 이어도 통과 (IsOptional 흡수)', async () => {
// FE 가 명시적 null 을 보낼 수 있으므로 허용. linkType 별 조합 검증은 service.
const dto = build({
placement: 'STORE',
imageUrl: 'https://x/y.jpg',
linkType: 'STORE',
linkProductId: null,
linkStoreId: null,
linkCategoryId: null,
});
expect(await validate(dto)).toHaveLength(0);
});
});
Loading
Loading