Skip to content

Commit

Permalink
Merge pull request #41 from nori-dongsan/feat/#39
Browse files Browse the repository at this point in the history
Feat/#39 ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
  • Loading branch information
dannaward authored Jul 22, 2022
2 parents 946e6cf + 9a34af5 commit bb20fab
Show file tree
Hide file tree
Showing 12 changed files with 436 additions and 115 deletions.
3 changes: 0 additions & 3 deletions src/entities/Toy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ export class Toy {
})
toySite: ToySite;

@ManyToOne(() => ToySite, (toySite) => toySite.toys, {
onDelete: 'CASCADE',
})
@IsNotEmpty()
@Column({ name: 'toy_site_cd' })
toySiteCd: number;
Expand Down
2 changes: 0 additions & 2 deletions src/entities/ToyCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import {
Column,
CreateDateColumn,
Entity,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { ThemeDto } from '../dtos/HomeDto';
import { Toy } from './Toy';

@Entity({ name: 'toy_collection' })
Expand Down
5 changes: 5 additions & 0 deletions src/repositories/ToySiteRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { EntityRepository, Repository } from 'typeorm';
import { ToySite } from '../entities/ToySite';

@EntityRepository(ToySite)
export class ToySiteRepository extends Repository<ToySite> {}
1 change: 0 additions & 1 deletion src/services/Procfile

This file was deleted.

45 changes: 45 additions & 0 deletions test/unit/services/AuthService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { UserRepository } from '../../../src/repositories/UserRepository';
import { UserService } from '../../../src/services/UserService';
import { AuthService } from '../../../src/services/AuthService';
import { createMemoryDatabase } from '../../utils/CreateMemoryDatabase';
import { UserSeed } from '../../utils/seeds/UserTestSeed';
import { Connection } from 'typeorm';
import { CreateUserDto } from '../../../src/dtos/UserDto';
import { ReturnErrorType } from '../../../src/constants/ReturnErrorType';
import { CreateTokenDto } from '../../../src/dtos/AuthDto';

describe('AuthService', () => {
let db: Connection;
let userRepository: UserRepository;
let authService: AuthService;
let userService: UserService;

beforeAll(async () => {
db = await createMemoryDatabase();
userRepository = db.getCustomRepository(UserRepository);
await userRepository.save(UserSeed);
userService = new UserService(userRepository);
authService = new AuthService(userRepository);
});

afterAll(() => db.close());

const request = {
accessToken: 'accessToken',
refreshToken: 'refreshToken',
};

it('์œ ํšจํ•˜์ง€ ์•Š์€ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์ด ์˜ค๋ฉด ํ† ํฐ์„ ๋ฐœ๊ธ‰ํ•˜์ง€ ์•Š๋Š”๋‹ค.', async () => {
const isUser = await authService.validateUserBySnsId(request.accessToken);

if (isUser) {
const accessToken = generateAccessToken(isUser);
} else {
expect(isUser).toBeNull();
}
});
});

function generateAccessToken(user: any) {
throw new Error('Function not implemented.');
}
29 changes: 21 additions & 8 deletions test/unit/services/CollectionService.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
import { Connection } from 'typeorm';
import { CollectionRepository } from '../../../src/repositories/CollectionRepository';
import { ThemeRepository } from '../../../src/repositories/ThemeRepository';
import { ToySiteRepository } from '../../../src/repositories/ToySiteRepository';
import { CollectionService } from '../../../src/services/CollectionService';
import { createMemoryDatabase } from '../../utils/CreateMemoryDatabase';
import { FriendSeed } from '../../utils/seeds/FriendTestSeed';
import { ThemeSeed } from '../../utils/seeds/ThemeSeed';
import { ToySiteSeed } from '../../utils/seeds/ToySiteSeed';
import { ToySeed } from '../../utils/seeds/ToyTestSeed';

describe('BoardService', () => {
let db: Connection;
let collectionRepository: CollectionRepository;
let themeRepository: ThemeRepository;
let toySiteRepository: ToySiteRepository;
let collectionService: CollectionService;

beforeAll(async () => {
db = await createMemoryDatabase();
collectionRepository = db.getCustomRepository(CollectionRepository);
await collectionRepository.save(FriendSeed);
collectionService = new CollectionService(collectionRepository);
themeRepository = db.getCustomRepository(ThemeRepository);
toySiteRepository = db.getCustomRepository(ToySiteRepository);
await collectionRepository.save(ToySeed);
await themeRepository.save(ThemeSeed);
await toySiteRepository.save(ToySiteSeed);
collectionService = new CollectionService(
collectionRepository,
themeRepository
);
});

afterAll(() => db.close);

it('์ปฌ๋ ‰์…˜ ์žฅ๋‚œ๊ฐ ๋ฆฌ์ŠคํŠธ๋ฅผ ์กฐํšŒํ•œ๋‹ค. (themeId: 0, sort: price-desc)', async () => {
const collection = await collectionService.fetchList(0, 'price-desc');
expect(collection.title).toBe('toddle');
expect(collection.toyList).toBeCalledWith(expect.anything()); // non-null
expect(collection.title).toBe('title');
// expect(collection.toyList).toBeCalledWith(expect.anything()); // non-null
if (collection.toyList != null) {
expect(collection.toyList[0].title).toBe(15000);
expect(collection.toyList[0].price).toBe(15000);
}
});

it('์ปฌ๋ ‰์…˜ ์žฅ๋‚œ๊ฐ ๋ฆฌ์ŠคํŠธ๋ฅผ ์กฐํšŒํ•œ๋‹ค. (themeId: 0)', async () => {
const collection = await collectionService.fetchList(0, null);
// expect(collection.title).toBe('toddle');
expect(collection.toyList).toBeCalledWith(expect.anything()); // non-null
// expect(collection.toyList).toBeCalledWith(expect.anything()); // non-null
if (collection.toyList != null) {
expect(collection.toyList[0].title).toBe(10000);
expect(collection.toyList[0].price).toBe(10000);
}
});

Expand Down
18 changes: 14 additions & 4 deletions test/unit/services/HomeService.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import { Connection } from 'typeorm';
import { HomeRepository } from '../../../src/repositories/HomeRepository';
import { ThemeRepository } from '../../../src/repositories/ThemeRepository';
import { ToySiteRepository } from '../../../src/repositories/ToySiteRepository';
import { HomeService } from '../../../src/services/HomeService';
import { createMemoryDatabase } from '../../utils/CreateMemoryDatabase';
import { FriendSeed } from '../../utils/seeds/FriendTestSeed';
import { ToySeed } from '../../utils/seeds/ToyTestSeed';
import { ThemeSeed } from '../../utils/seeds/ThemeSeed';
import { ToySiteSeed } from '../../utils/seeds/ToySiteSeed';

describe('BoardService', () => {
let db: Connection;
let homeRepository: HomeRepository;
let themeRepository: ThemeRepository;
let homeService: HomeService;
let toySiteRepository: ToySiteRepository;

beforeAll(async () => {
db = await createMemoryDatabase();
homeRepository = db.getCustomRepository(HomeRepository);
await homeRepository.save(FriendSeed);
homeService = new HomeService(homeRepository);
themeRepository = db.getCustomRepository(ThemeRepository);
toySiteRepository = db.getCustomRepository(ToySiteRepository);
await homeRepository.save(ToySeed);
await themeRepository.save(ThemeSeed);
await toySiteRepository.save(ToySiteSeed);
homeService = new HomeService(homeRepository, themeRepository);
});

afterAll(() => db.close);

it('ํ™ˆ ์žฅ๋‚œ๊ฐ ์ถ”์ฒœ ๋ฆฌ์ŠคํŠธ๋ฅผ ์กฐํšŒํ•œ๋‹ค.', async () => {
const toyList = await homeService.fetchList();
expect(toyList).toBeCalledWith(expect.anything()); // non-null
// expect(toyList).toBeCalledWith(expect.anything()); // non-null
if (
toyList.trending != null &&
toyList.noriPick != null &&
Expand Down
10 changes: 5 additions & 5 deletions test/utils/CreateMemoryDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Container } from "typedi";
import { createConnection, useContainer } from "typeorm";
import { Container } from 'typedi';
import { createConnection, useContainer } from 'typeorm';

/**
* ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉํ•  In-memory Database๋ฅผ ๋งŒ๋“ ๋‹ค
Expand All @@ -8,9 +8,9 @@ import { createConnection, useContainer } from "typeorm";
export async function createMemoryDatabase() {
useContainer(Container);
return createConnection({
type: "sqlite",
database: ":memory:",
entities: [__dirname + "/../../src/entities/*{.ts,.js}"],
type: 'sqlite',
database: ':memory:',
entities: [__dirname + '/../../src/entities/*{.ts,.js}'],
dropSchema: true,
synchronize: true,
logging: false,
Expand Down
92 changes: 0 additions & 92 deletions test/utils/seeds/FriendTestSeed.ts

This file was deleted.

26 changes: 26 additions & 0 deletions test/utils/seeds/ThemeSeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const ThemeSeed = [
{
id: 0,
title: 'title',
image: 'image',
subtitle: 'subtitle',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 1,
title: 'title',
image: 'image',
subtitle: 'subtitle',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 2,
title: 'title',
image: 'image',
subtitle: 'subtitle',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
];
56 changes: 56 additions & 0 deletions test/utils/seeds/ToySiteSeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export const ToySiteSeed = [
{
id: 1,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 2,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 3,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 4,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 5,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 6,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 7,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 8,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
{
id: 9,
toySite: 'toySite',
createdAt: `${new Date()}`,
updatedAt: `${new Date()}`,
},
];
Loading

0 comments on commit bb20fab

Please sign in to comment.