From c49dfd45e6a9dc1cecca64708d383d070e318db7 Mon Sep 17 00:00:00 2001
From: rinsuki <428rinsuki+git@gmail.com>
Date: Fri, 25 Oct 2019 23:00:20 +0900
Subject: [PATCH] =?UTF-8?q?chart=E3=81=AEconnection=E3=82=92=E5=88=86?=
 =?UTF-8?q?=E9=9B=A2=E3=81=99=E3=82=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 test/chart.ts | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/test/chart.ts b/test/chart.ts
index 63108ba6e9..931a5b2f0b 100644
--- a/test/chart.ts
+++ b/test/chart.ts
@@ -17,11 +17,39 @@ process.env.NODE_ENV = 'test';
 import * as assert from 'assert';
 import * as lolex from 'lolex';
 import { async } from './utils';
-import { initDb } from '../src/db/postgre';
 import TestChart from '../src/services/chart/charts/classes/test';
 import TestGroupedChart from '../src/services/chart/charts/classes/test-grouped';
 import TestUniqueChart from '../src/services/chart/charts/classes/test-unique';
-import { Connection } from 'typeorm';
+import * as _TestChart from '../src/services/chart/charts/schemas/test';
+import * as _TestGroupedChart from '../src/services/chart/charts/schemas/test-grouped';
+import * as _TestUniqueChart from '../src/services/chart/charts/schemas/test-unique';
+import { Connection, getConnection, createConnection } from 'typeorm';
+import config from '../src/config';
+import Chart from '../src/services/chart/core';
+
+function initDb() {
+	try {
+		const conn = getConnection('__for_chart_testing');
+		return Promise.resolve(conn);
+	} catch (e) {}
+
+	return createConnection({
+		name: '__for_chart_testing',
+		type: 'postgres',
+		host: config.db.host,
+		port: config.db.port,
+		username: config.db.user,
+		password: config.db.pass,
+		database: config.db.db,
+		synchronize: true,
+		dropSchema: true,
+		entities: [
+			Chart.schemaToEntity(_TestChart.name, _TestChart.schema),
+			Chart.schemaToEntity(_TestGroupedChart.name, _TestGroupedChart.schema),
+			Chart.schemaToEntity(_TestUniqueChart.name, _TestUniqueChart.schema)
+		]
+	});
+}
 
 describe('Chart', () => {
 	let testChart: any;
@@ -31,7 +59,7 @@ describe('Chart', () => {
 	let connection: Connection;
 
 	before(done => {
-		initDb(true).then(c => {
+		initDb().then(c => {
 			connection = c;
 			done();
 		});