From eaee784b9e4725ae013bfa0dcf8000b906c6b7d8 Mon Sep 17 00:00:00 2001 From: koomchang Date: Tue, 12 Nov 2024 01:47:26 +0900 Subject: [PATCH] =?UTF-8?q?test:=20global=20=ED=99=98=EA=B2=BD=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=83=9D=EC=84=B1=20=EB=90=9C=20container=EB=A5=BC?= =?UTF-8?q?=20=EC=9E=AC=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=84=A4=EC=A0=95=20#72?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/config/globalSetup.ts | 3 --- backend/test/place/place.repository.test.ts | 29 +++++---------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/backend/test/config/globalSetup.ts b/backend/test/config/globalSetup.ts index 392140fe..68104e07 100644 --- a/backend/test/config/globalSetup.ts +++ b/backend/test/config/globalSetup.ts @@ -5,9 +5,6 @@ export default async () => { const ddlScriptPath = path.resolve(__dirname, '../../resources/sql/DDL.sql'); global.reusedContainer = await new MySqlContainer() - .withUsername('testUser') - .withUserPassword('testPassword') - .withDatabase('testDB') .withReuse() .withBindMounts([ { source: ddlScriptPath, target: '/docker-entrypoint-initdb.d/DDL.sql' }, diff --git a/backend/test/place/place.repository.test.ts b/backend/test/place/place.repository.test.ts index d2d9481d..bd14807b 100644 --- a/backend/test/place/place.repository.test.ts +++ b/backend/test/place/place.repository.test.ts @@ -1,29 +1,15 @@ -import { MySqlContainer, StartedMySqlContainer } from '@testcontainers/mysql'; -import { DataSource } from 'typeorm'; import { PlaceRepository } from '../../src/place/place.repository'; -import { createTestDataSource } from '../datasource.config'; -import { PlaceFixture } from './place.fixture'; +import { initDataSource } from '../config/datasource.config'; +import { PlaceFixture } from './fixture/place.fixture'; +import { MySqlContainer, StartedMySqlContainer } from '@testcontainers/mysql'; describe('PlaceRepository', () => { - let placeRepository: PlaceRepository; - let testDataSource: DataSource; let container: StartedMySqlContainer; + let placeRepository: PlaceRepository; beforeAll(async () => { - container = await new MySqlContainer() - .withUsername('testUser') - .withUserPassword('testPassword') - .withDatabase('testDB') - .start(); - - testDataSource = await createTestDataSource(container); - await testDataSource.initialize(); - placeRepository = new PlaceRepository(testDataSource); - }); - - afterAll(async () => { - await testDataSource.destroy(); - await container.stop(); + container = await new MySqlContainer().withReuse().start(); + placeRepository = new PlaceRepository(await initDataSource(container)); }); beforeEach(async () => { @@ -31,7 +17,6 @@ describe('PlaceRepository', () => { }); it('장소 이름이나 주소에 포함된 키워드를 찾아 해당하는 장소를 반환한다.', async () => { - // given const placesWithParkName = [ { googlePlaceId: 'googlePlaceId_1', @@ -68,7 +53,6 @@ describe('PlaceRepository', () => { ); await placeRepository.save(places); - // when const page = 1; const pageSize = 10; const query = 'park'; @@ -78,7 +62,6 @@ describe('PlaceRepository', () => { pageSize, ); - // then expect(results.length).toBe(3); expect(results).toEqual(