Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Seung-o committed Jan 21, 2024
1 parent d12ee55 commit 7f8260f
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 27 deletions.
44 changes: 17 additions & 27 deletions src/trade-posts/tests/trade-post.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { Model } from 'mongoose';
import { IBookmarkService } from '../../bookmarks/interfaces/bookmark.interface';
import { TradeAction } from '../enums/trade-action.enum';
import { CreateTradePostInput } from '../inputs/trade-post.input';
import { TradePostComment } from '../schemas/trade-post-comment.schema';
import { TradePost, TradePostDocument } from '../schemas/trade-post.schema';
import { TradePostCommentService } from '../services/trade-post-comment.service';
Expand All @@ -25,10 +23,7 @@ describe('TradePostService', () => {
{
provide: IBookmarkService,
useValue: {
bookmarkTradePost: jest.fn(),
unbookmarkTradePost: jest.fn(),
getBookmarkedTradePosts: jest.fn(),
isTradePostBookmarked: jest.fn(),
getBookmark: jest.fn(),
},
},
{
Expand All @@ -40,9 +35,7 @@ describe('TradePostService', () => {
{
provide: getModelToken(TradePost.name),
useValue: {
countDocuments: jest.fn(),
create: jest.fn(),
findByIdAndUpdate: jest.fn(),
findById: jest.fn(),
},
},
{
Expand All @@ -59,29 +52,26 @@ describe('TradePostService', () => {
tradePostModel = module.get<Model<TradePostDocument>>(getModelToken(TradePost.name));
});

describe('createTradePost', () => {
it('should create a trade post', async () => {
// Mock the necessary dependencies and input data
const userId = '65a178d35a5f64cf91e95123';
const input: CreateTradePostInput = {
action: TradeAction.BUY,
price: 1000,
describe('getTradePost', () => {
it('should return trade post', async () => {
const userId = 'userId';
const tradePostId = 'tradePostId';
const tradePost = {
id: tradePostId,
authorId: 'authorId',
title: 'title',
description: 'description',
image: 'image',
createdAt: new Date(),
updatedAt: new Date(),
};

jest.spyOn(tradePostModel, 'countDocuments').mockResolvedValueOnce(0);
jest.spyOn(tradePostModel, 'create').mockResolvedValueOnce({ id: '65a178d35a5f64cf91e950d8' } as any);
jest.spyOn(TradePostStorageService.prototype, 'uploadImage').mockResolvedValueOnce('image-url');
jest.spyOn(tradePostModel, 'findByIdAndUpdate').mockResolvedValueOnce({
id: '65a178d35a5f64cf91e950d8',
authorId: '65a24bff8cfbf7b75ff72717',
comments: [],
} as any);
const result = await tradePostService.createTradePost(userId, input);
jest.spyOn(tradePostModel, 'findById').mockResolvedValueOnce(tradePost as any);
jest.spyOn(bookmarkService, 'getBookmark').mockResolvedValueOnce({ tradePostIds: ['tradePostId'] } as any);

const result = await tradePostService.getTradePost(userId, tradePostId);

// Assert the result
expect(result).toBeDefined();
expect(result.isBookmarked).toBe(true);
});
});
});
123 changes: 123 additions & 0 deletions src/users/json/words.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"adjectives": [
"강렬한",
"신비로운",
"매혹적인",
"아름다운",
"신나는",
"활기찬",
"따뜻한",
"차가운",
"고요한",
"빛나는",
"무한한",
"유쾌한",
"쾌활한",
"행복한",
"낭만적인",
"도전적인",
"자유로운",
"새로운",
"화려한",
"편안한",
"독특한",
"현대적인",
"과거의",
"미래의",
"유연한",
"선명한",
"소박한",
"신선한",
"쾌적한",
"도시의",
"자연의",
"청명한",
"유순한",
"황홀한",
"달콤한",
"섬세한",
"단호한",
"발랄한",
"신사적인",
"세련된",
"고상한",
"전통적인",
"존경받는",
"영리한",
"참신한",
"수줍은",
"경이로운",
"황홀한",
"환상적인",
"절제된",
"맑은",
"어두운",
"무거운",
"가벼운",
"쫄깃한",
"단단한",
"부드러운",
"건강한",
"유리한",
"불가사의한",
"기발한",
"마법같은",
"단순한",
"원활한",
"빠른",
"느린",
"고요한",
"분주한",
"감각적인",
"감동적인",
"우아한",
"감사한",
"따뜻한",
"꾸준한",
"고요한",
"환한",
"진중한",
"자세한",
"깔끔한",
"남다른",
"끈질긴",
"긴장감 있는",
"완벽한",
"친절한",
"화목한",
"다정한",
"존경받는",
"소중한",
"정갈한",
"담백한",
"생기있는",
"책임감 있는",
"끊임없는",
"맑은"
],
"nouns": [
{ "name": "달팽이", "imageUrl": "" },
{ "name": "스포아", "imageUrl": "" },
{ "name": "슬라임", "imageUrl": "" },
{ "name": "주황버섯", "imageUrl": "" },
{ "name": "리본돼지", "imageUrl": "" },
{ "name": "초록버섯", "imageUrl": "" },
{ "name": "스티지", "imageUrl": "" },
{ "name": "뿔버섯", "imageUrl": "" },
{ "name": "미요캐츠", "imageUrl": "" },
{ "name": "페어리", "imageUrl": "" },
{ "name": "라츠", "imageUrl": "" },
{ "name": "티키", "imageUrl": "" },
{ "name": "루팡", "imageUrl": "" },
{ "name": "로랑", "imageUrl": "" },
{ "name": "월묘", "imageUrl": "" },
{ "name": "엄티", "imageUrl": "" },
{ "name": "헥터", "imageUrl": "" },
{ "name": "화이트팽", "imageUrl": "" },
{ "name": "페페", "imageUrl": "" },
{ "name": "예티", "imageUrl": "" },
{ "name": "레쉬", "imageUrl": "" },
{ "name": "하프", "imageUrl": "" },
{ "name": "샤크", "imageUrl": "" }
]
}

0 comments on commit 7f8260f

Please sign in to comment.