-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from boostcampwm-2022/Tab/Title
Tab/title
- Loading branch information
Showing
17 changed files
with
10,132 additions
and
4,337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
testRegex: ".Test.ts$", | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as dotenv from "dotenv"; | ||
import mongoose from "mongoose"; | ||
|
||
dotenv.config(); | ||
|
||
export default function connectMongoDB() { | ||
mongoose.connect( | ||
`mongodb+srv://${process.env.MONGODB_ID}:${process.env.MONGODB_PASSWORD}@cluster0.a7vmgdw.mongodb.net/database0?`, | ||
(err) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log("mongoDB is connected..."); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as dotenv from "dotenv"; | ||
import "reflect-metadata"; | ||
import { DataSource } from "typeorm"; | ||
|
||
dotenv.config(); | ||
const myDataSource = new DataSource({ | ||
type: "mysql", | ||
host: process.env.TYPEORM_HOST || "", | ||
port: Number(process.env.TYPEORM_PORT), | ||
username: process.env.TYPEORM_USERNAME || "", | ||
password: process.env.TYPEORM_PASSWORD || "", | ||
database: process.env.TYPEORM_DATABASE || "", | ||
entities: [`${__dirname}/../**/*.Model{.ts,.js}`], | ||
}); | ||
|
||
export default myDataSource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as redis from "redis"; | ||
|
||
const redisClient = redis.createClient({ | ||
url: `redis://@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}/0`, | ||
legacyMode: true, | ||
}); | ||
|
||
redisClient.on("connect", () => { | ||
console.info("Redis connected!"); | ||
}); | ||
redisClient.on("error", (err) => { | ||
console.error("Redis Client Error", err); | ||
}); | ||
|
||
redisClient.connect(); | ||
const redisCli = redisClient.v4; | ||
|
||
export default redisCli; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import request from "supertest"; | ||
import * as dotenv from "dotenv"; | ||
import { BeforeRecover } from "typeorm"; | ||
import app from "../app"; | ||
import connectMongoDB from "../Loader/Mongo.Loader"; | ||
|
||
dotenv.config(); | ||
beforeAll(async () => { | ||
await connectMongoDB(); | ||
}); | ||
describe("GET api/results/:formId", () => { | ||
const testFormId = "6396ab6baa73534ba0a86b12"; | ||
const testResult = { | ||
formTitle: "TEST", | ||
totalResponseCount: 9, | ||
acceptResponse: true, | ||
questionResultDict: { | ||
"1": { | ||
type: "checkbox", | ||
questionTitle: "q1", | ||
responseCount: 9, | ||
answerTotal: { | ||
a1: 2, | ||
a2: 1, | ||
a3: 1, | ||
a4: 2, | ||
a5: 3, | ||
}, | ||
}, | ||
"2": { | ||
type: "multiple", | ||
questionTitle: "q2", | ||
responseCount: 9, | ||
answerTotal: { | ||
a1: 6, | ||
a2: 9, | ||
a3: 9, | ||
a4: 9, | ||
a5: 9, | ||
}, | ||
}, | ||
"3": { | ||
type: "paragraph", | ||
questionTitle: "q3", | ||
responseCount: 9, | ||
answerTotal: { | ||
"2": 1, | ||
"3": 2, | ||
"4": 1, | ||
"5": 2, | ||
"6": 2, | ||
a1: 1, | ||
}, | ||
}, | ||
}, | ||
}; | ||
test("유효한 설문에 대한 결과 요청", (done) => { | ||
request(app) | ||
.get(`/api/results/${testFormId}`) | ||
.expect(200) | ||
.then((res) => { | ||
expect(res.body).toEqual(testResult); | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error("######Error >>", err); | ||
done(err); | ||
}); | ||
}); | ||
|
||
test("유효하지 않은 설문에 대한 결과 요청", (done) => { | ||
request(app) | ||
.get(`/api/results/invalidForm`) | ||
.expect(400) | ||
.then((res) => { | ||
expect(res.body).toEqual({ status: 400, message: "Invalid formId" }); | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error("######Error >>", err); | ||
done(err); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import request from "supertest"; | ||
import * as dotenv from "dotenv"; | ||
import "reflect-metadata"; | ||
import { DataSource } from "typeorm"; | ||
import User from "./User.Model"; | ||
import app from "../app"; | ||
|
||
dotenv.config(); | ||
|
||
const testUser = { | ||
name: "testUser", | ||
id: 58, | ||
infAccessToken: | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NTgsImlhdCI6MTY3MDgyODE2MH0.vQrK4E6RbQfPxpTt0cjBmhYVtlihWJelKSdssm2W45E", | ||
infRefreshToken: | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NTgsImlhdCI6MTY3MDgyODE2NH0.07bukMgpAcfDik8Umlg2UtTvVKmWFotf3AHy_legMWs", | ||
}; | ||
|
||
const testUserRefreshToken = beforeAll(async () => { | ||
const myDataSource = new DataSource({ | ||
type: "mysql", | ||
host: process.env.TYPEORM_HOST || "", | ||
port: Number(process.env.TYPEORM_PORT), | ||
username: process.env.TYPEORM_USERNAME || "", | ||
password: process.env.TYPEORM_PASSWORD || "", | ||
database: process.env.TYPEORM_DATABASE || "", | ||
entities: [User], | ||
}); | ||
await myDataSource.initialize().then(() => { | ||
console.log("Data Source has been initialized!"); | ||
}); | ||
}); | ||
|
||
// 본인 유저 정보 | ||
describe("GET api/users", () => { | ||
test("로그인한 유저의 경우 유저 정보 반환", (done) => { | ||
request(app) | ||
.get("/api/users") | ||
.set("Cookie", [`accessToken=${testUser.infAccessToken}`, `refreshToken=${testUser.infRefreshToken}`]) | ||
.expect(200) | ||
.then((res) => { | ||
expect(res.body).toEqual({ userID: testUser.id, userName: testUser.name }); | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error("######Error >>", err); | ||
done(err); | ||
}); | ||
}); | ||
|
||
test("로그인 안한 유저의 경우 401에러 반환", (done) => { | ||
request(app) | ||
.get("/api/users") | ||
.expect(401) | ||
.then((res) => { | ||
expect(res.body).toEqual({ status: 401, message: "Empty AccessToken" }); | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error("######Error >>", err); | ||
done(err); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import app from "./app"; | ||
import myDataSource from "./Loader/MySQL.Loader"; | ||
import connectMongoDB from "./Loader/Mongo.Loader"; | ||
|
||
myDataSource.initialize().then(() => { | ||
console.log("Data Source has been initialized!"); | ||
}); | ||
|
||
connectMongoDB(); | ||
|
||
app.listen(process.env.PORT); |