diff --git a/src/views/loginReplacePage.js b/src/views/loginReplacePage.js
index 209e0bb0..972cfb62 100644
--- a/src/views/loginReplacePage.js
+++ b/src/views/loginReplacePage.js
@@ -24,7 +24,7 @@ module.exports = `
}
const submitHandler = () => {
const value = document.getElementById("input-id").value;
- if(value) post('/auth/login/replace', {
+ if(value) post('/api/auth/login/replace', {
id: value,
});
}
diff --git a/src/views/reportEmailPage.js b/src/views/reportEmailPage.js
new file mode 100644
index 00000000..1ee674f8
--- /dev/null
+++ b/src/views/reportEmailPage.js
@@ -0,0 +1,86 @@
+const emailPage = require("./emailPage");
+
+const reportEmailPage = {};
+
+/* 미정산 알림 메일을 위한 템플릿 */
+reportEmailPage["no-settlement"] = (
+ origin,
+ name,
+ nickname,
+ roomName,
+ payer,
+ roomId
+) =>
+ emailPage(
+ "미정산 내역 관련 안내",
+ `
${name} (${nickname}) 님께
+ 안녕하세요, ${name} (${nickname}) 님.
+ KAIST 학부 총학생회 산하 특별기구 SPARCS의 Taxi 팀입니다.
+ 최근 참여하신 방에서 정산이 이루어지지 않았다는 사용자의 문의가 접수되어 메일을 보내드립니다.
+
+
+ 방 제목
+ ${roomName}
+
+
+ 결제자
+ ${payer}
+
+
+
+ 위 방에서 채팅을 확인하실 수 있으며,
결제하신 분께 해당 금액을 정산해주시기를 부탁드립니다.
+
미정산이 반복되는 경우 Taxi 서비스 이용이 제한될 수 있음을 알려드립니다.
+ 문의가 필요하신 경우,
택시 서비스 내부의 "채널톡 문의하기"를 통해 채팅을 남겨주시거나, 또는 이 메일에 회신해 주셔도 됩니다.
+ 감사합니다.
+ SPARCS Taxi팀 드림.
+ `
+ );
+
+/* 미탑승 알림 메일을 위한 템플릿 */
+reportEmailPage["no-show"] = (
+ origin,
+ name,
+ nickname,
+ roomName,
+ payer,
+ roomId
+) =>
+ emailPage(
+ "미탑승 내역 관련 안내",
+ `
${name} (${nickname}) 님께
+ 안녕하세요, ${name} (${nickname}) 님.
+ KAIST 학부 총학생회 산하 특별기구 SPARCS의 Taxi 팀입니다.
+ 최근 참여하신 방에서 별도의 연락 없이 탑승하지 않았다는 사용자의 문의가 접수되어 메일을 보내드립니다.
+
+
+ 방 제목
+ ${roomName}
+
+
+ 결제자
+ ${payer}
+
+
+
+
미탑승이 반복되는 경우 Taxi 서비스 이용이 제한될 수 있음을 알려드립니다.
+ 문의가 필요하신 경우,
택시 서비스 내부의 "채널톡 문의하기"를 통해 채팅을 남겨주시거나, 또는 이 메일에 회신해 주셔도 됩니다.
+ 감사합니다.
+ SPARCS Taxi팀 드림.
+ `
+ );
+
+module.exports = reportEmailPage;
diff --git a/test/modules/auths/jwt.js b/test/modules/auths/jwt.js
new file mode 100644
index 00000000..bac7edfa
--- /dev/null
+++ b/test/modules/auths/jwt.js
@@ -0,0 +1,29 @@
+const { expect } = require("chai");
+const { sign, verify } = require("../../../src/modules/auths/jwt");
+
+// jwt.js 관련 2개의 함수를 테스트
+// 1. jwt 서명과 검증이 성공적으로 되는지 테스트
+describe("[jwt] 1.sign & verify", () => {
+ it("should sign and verify jwt correctly", async () => {
+ // JWT 서명에 사용되는 사용자
+ const user = {
+ _id: "507f191e810c19729de860ea",
+ };
+
+ // 토큰 생성이 성공적으로 되는지 테스트
+ const { token: accessToken } = await sign({
+ id: user._id,
+ type: "access",
+ });
+ const { token: refreshToken } = await sign({
+ id: user._id,
+ type: "refresh",
+ });
+
+ // 토큰 검증이 성공적으로 되는지 테스트
+ const accessTokenStatus = await verify(accessToken);
+ expect(accessTokenStatus).to.has.property("id", user._id);
+ const refreshTokenStatus = await verify(refreshToken);
+ expect(refreshTokenStatus).to.has.property("id", user._id);
+ });
+});
diff --git a/test/auth.replace.js b/test/services/auth.replace.js
similarity index 82%
rename from test/auth.replace.js
rename to test/services/auth.replace.js
index 322d13ef..643eddf7 100644
--- a/test/auth.replace.js
+++ b/test/services/auth.replace.js
@@ -1,7 +1,7 @@
const request = require("supertest");
-const authHandlers = require("../src/services/auth.replace");
-const { userModel } = require("../src/modules/stores/mongo");
+const authHandlers = require("../../src/services/auth.replace");
+const { userModel } = require("../../src/modules/stores/mongo");
// auth.replace.js 관련 1개의 handler을 테스트
// 1. dev 환경에서 로그인이 성공적으로 이루어지는지 확인
diff --git a/test/locations.js b/test/services/locations.js
similarity index 87%
rename from test/locations.js
rename to test/services/locations.js
index 19308e51..7df01482 100644
--- a/test/locations.js
+++ b/test/services/locations.js
@@ -1,15 +1,15 @@
-const expect = require("chai").expect;
-const locationHandlers = require("../src/services/locations");
-const httpMocks = require("node-mocks-http");
-
-// locations.js 관련 1개의 handler을 테스트
-// 1. 모든 location 정보를 잘 가져오는지 확인
-describe("[locations] 1.getAllLocationsHandler", () => {
- it("should return information of locations correctly", async () => {
- let req = httpMocks.createRequest({});
- let res = httpMocks.createResponse();
- await locationHandlers.getAllLocationsHandler(req, res);
-
- expect(res._getJSONData().locations).not.to.have.lengthOf(0);
- });
-});
+const expect = require("chai").expect;
+const locationHandlers = require("../../src/services/locations");
+const httpMocks = require("node-mocks-http");
+
+// locations.js 관련 1개의 handler을 테스트
+// 1. 모든 location 정보를 잘 가져오는지 확인
+describe("[locations] 1.getAllLocationsHandler", () => {
+ it("should return information of locations correctly", async () => {
+ let req = httpMocks.createRequest({});
+ let res = httpMocks.createResponse();
+ await locationHandlers.getAllLocationsHandler(req, res);
+
+ expect(res._getJSONData().locations).not.to.have.lengthOf(0);
+ });
+});
diff --git a/test/logininfo.js b/test/services/logininfo.js
similarity index 94%
rename from test/logininfo.js
rename to test/services/logininfo.js
index 64e492f7..30204643 100644
--- a/test/logininfo.js
+++ b/test/services/logininfo.js
@@ -1,6 +1,6 @@
const expect = require("chai").expect;
-const logininfoHandlers = require("../src/services/logininfo");
-const { userModel } = require("../src/modules/stores/mongo");
+const logininfoHandlers = require("../../src/services/logininfo");
+const { userModel } = require("../../src/modules/stores/mongo");
// 1-1. 로그인 한 유저가 없을 시 undefined를 return 하는지 확인
// 1-2. login 정보를 잘 return 하는지 확인
diff --git a/test/reports.js b/test/services/reports.js
similarity index 92%
rename from test/reports.js
rename to test/services/reports.js
index 67bf4001..86347d4a 100644
--- a/test/reports.js
+++ b/test/services/reports.js
@@ -1,7 +1,7 @@
const expect = require("chai").expect;
-const reportHandlers = require("../src/services/reports");
-const { userModel } = require("../src/modules/stores/mongo");
-const { userGenerator, roomGenerator, testRemover } = require("./utils");
+const reportHandlers = require("../../src/services/reports");
+const { userModel } = require("../../src/modules/stores/mongo");
+const { userGenerator, roomGenerator, testRemover } = require("../utils");
const httpMocks = require("node-mocks-http");
let testData = { rooms: [], users: [], chat: [], location: [], report: [] };
@@ -24,7 +24,7 @@ describe("[reports] 1.createHandler", () => {
type: "etc-reason",
etcDetail: "etc-detail",
time: Date.now(),
- roomId: testRoom._id
+ roomId: testRoom._id,
},
});
let res = httpMocks.createResponse();
diff --git a/test/rooms.js b/test/services/rooms.js
similarity index 95%
rename from test/rooms.js
rename to test/services/rooms.js
index 6ba0c232..e17ae6af 100644
--- a/test/rooms.js
+++ b/test/services/rooms.js
@@ -1,203 +1,203 @@
-const expect = require("chai").expect;
-const express = require("express");
-const roomsHandlers = require("../src/services/rooms");
-const {
- userModel,
- roomModel,
- locationModel,
-} = require("../src/modules/stores/mongo");
-const { userGenerator, testRemover } = require("./utils");
-const app = express();
-const httpMocks = require("node-mocks-http");
-
-let testData = { rooms: [], users: [], chat: [], location: [], report: [] };
-const removeTestData = async () => {
- // drop all testData
- await testRemover(testData);
-};
-
-// rooms.js 관련 9개의 handler을 테스트
-// 1. test1이 1분 뒤에 출발하는 test-room 방을 생성, 제대로 생성 되었는지 확인
-describe("[rooms] 1.createHandler", () => {
- it("should create room which departs after 1 minute", async () => {
- const testUser1 = await userGenerator("test1", testData);
- const testFrom = await locationModel.findOne({ koName: "대전역" });
- const testTo = await locationModel.findOne({ koName: "택시승강장" });
- let req = httpMocks.createRequest({
- body: {
- name: "test-room",
- from: testFrom._id,
- to: testTo._id,
- time: Date.now() + 60 * 1000,
- maxPartLength: 4,
- },
- userId: testUser1.id,
- app,
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.createHandler(req, res);
-
- const testRoom = await roomModel.findOne({ name: "test-room" });
- testData["rooms"].push(testRoom);
- const resData = res._getData();
- expect(resData).to.has.property("name", "test-room");
- });
-});
-
-// 2. test1을 통하여 방의 정보를 제대로 가져오는지 확인
-describe("[rooms] 2.infoHandler", () => {
- it("should return information of room", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- const testRoom = await roomModel.findOne({ name: "test-room" });
- let req = httpMocks.createRequest({
- query: { id: testRoom._id },
- userId: testUser1.id,
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.infoHandler(req, res);
-
- const resData = res._getData();
- expect(resData).to.has.property("name", "test-room");
- expect(resData).to.has.property("isOver");
- });
-});
-
-// 3. 로그인되지 않은 유저가 방의 정보를 제대로 가져오는지 확인
-describe("[rooms] 3.publicInfoHandler", () => {
- it("should return information of room", async () => {
- const testRoom = await roomModel.findOne({ name: "test-room" });
- let req = httpMocks.createRequest({
- query: { id: testRoom._id },
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.publicInfoHandler(req, res);
-
- const resData = res._getData();
- expect(resData).to.has.property("name", "test-room");
- expect(resData).to.has.property("isOver", undefined);
- });
-});
-
-// 4. test2가 test-room에 join, 방에 잘 join 했는지 확인
-describe("[rooms] 4.joinHandler", () => {
- it("should return information of room and join", async () => {
- const testUser2 = await userGenerator("test2", testData);
- const testRoom = await roomModel.findOne({ name: "test-room" });
- let req = httpMocks.createRequest({
- body: {
- roomId: testRoom._id,
- },
- userId: testUser2.id,
- app,
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.joinHandler(req, res);
-
- const resData = res._getData();
- expect(resData).to.has.property("name", "test-room");
- expect(resData.part).to.have.lengthOf(2);
- });
-});
-
-// 5. 방의 정보를 통해 검색, 검색 정보가 예상과 일치하는지 확인
-describe("[rooms] 5.searchHandler", () => {
- it("should return information of searching room", async () => {
- const testFrom = await locationModel.findOne({ koName: "대전역" });
- const testTo = await locationModel.findOne({ koName: "택시승강장" });
- let req = httpMocks.createRequest({
- query: {
- name: "test-room",
- from: testFrom._id,
- to: testTo._id,
- time: Date.now(),
- withTime: true,
- maxPartLength: 4,
- },
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.searchHandler(req, res);
-
- const resJson = res._getJSONData();
- expect(resJson[0]).to.has.property("name", "test-room");
- expect(resJson[0].settlementTotal).to.be.undefined;
- });
-});
-
-// 6. 방에 속한 유저를 통해 검색
-// ongoing은 test-room이 검색되고, done은 아무것도 검색되지 않아야함
-describe("[rooms] 6.searchByUserHandler", () => {
- it("should return information of searching room", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- let req = httpMocks.createRequest({
- userId: testUser1.id,
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.searchByUserHandler(req, res);
-
- const resJson = res._getJSONData();
- expect(resJson["ongoing"][0]).to.has.property("name", "test-room");
- expect(resJson["done"][0]).to.be.undefined;
- });
-});
-
-// 7. 1분이 지난 후, 정산 정보를 불러옴. 예상과 같은 정보를 불러오는지 확인
-describe("[rooms] 7.commitPaymentHandler", () => {
- it("should return information of room and commit payment", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- const testRoom = await roomModel.findOne({ name: "test-room" });
- let req = httpMocks.createRequest({
- body: { roomId: testRoom._id },
- userId: testUser1.id,
- timestamp: Date.now() + 60 * 1000,
- app,
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.commitPaymentHandler(req, res);
-
- const resData = res._getData();
- expect(resData).to.has.property("name", "test-room");
- expect(resData).to.has.property("isOver", true);
- expect(resData).to.has.property("settlementTotal", 1);
- });
-});
-
-// 8. 도착 정보를 불러옴. 예상과 같은 정보를 불러오는지 확인
-describe("[rooms] 8.settlementHandler", () => {
- it("should return information of room and set settlement", async () => {
- const testUser2 = await userModel.findOne({ id: "test2" });
- const testRoom = await roomModel.findOne({ name: "test-room" });
- let req = httpMocks.createRequest({
- body: { roomId: testRoom._id },
- userId: testUser2.id,
- app,
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.settlementHandler(req, res);
-
- const resData = res._getData();
- expect(resData).to.has.property("name", "test-room");
- expect(resData).to.has.property("isOver", true);
- expect(resData).to.has.property("settlementTotal", 2);
- });
-});
-
-// 9. test2 방에서 퇴장, 제대로 방에서 나갔는지 확인하고 생성해준 data 모두 삭제
-describe("[rooms] 9.abortHandler", () => {
- it("should return information of room and abort user", async () => {
- const testUser2 = await userModel.findOne({ id: "test2" });
- const testRoom = await roomModel.findOne({ name: "test-room" });
- let req = httpMocks.createRequest({
- body: { roomId: testRoom._id },
- userId: testUser2.id,
- session: {},
- app,
- });
- let res = httpMocks.createResponse();
- await roomsHandlers.abortHandler(req, res);
- afterEach(removeTestData);
-
- const resData = res._getData();
- expect(resData).to.has.property("name", "test-room");
- expect(resData.part).to.have.lengthOf(1);
- });
-});
+const expect = require("chai").expect;
+const express = require("express");
+const roomsHandlers = require("../../src/services/rooms");
+const {
+ userModel,
+ roomModel,
+ locationModel,
+} = require("../../src/modules/stores/mongo");
+const { userGenerator, testRemover } = require("../utils");
+const app = express();
+const httpMocks = require("node-mocks-http");
+
+let testData = { rooms: [], users: [], chat: [], location: [], report: [] };
+const removeTestData = async () => {
+ // drop all testData
+ await testRemover(testData);
+};
+
+// rooms.js 관련 9개의 handler을 테스트
+// 1. test1이 1분 뒤에 출발하는 test-room 방을 생성, 제대로 생성 되었는지 확인
+describe("[rooms] 1.createHandler", () => {
+ it("should create room which departs after 1 minute", async () => {
+ const testUser1 = await userGenerator("test1", testData);
+ const testFrom = await locationModel.findOne({ koName: "대전역" });
+ const testTo = await locationModel.findOne({ koName: "택시승강장" });
+ let req = httpMocks.createRequest({
+ body: {
+ name: "test-room",
+ from: testFrom._id,
+ to: testTo._id,
+ time: Date.now() + 60 * 1000,
+ maxPartLength: 4,
+ },
+ userId: testUser1.id,
+ app,
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.createHandler(req, res);
+
+ const testRoom = await roomModel.findOne({ name: "test-room" });
+ testData["rooms"].push(testRoom);
+ const resData = res._getData();
+ expect(resData).to.has.property("name", "test-room");
+ });
+});
+
+// 2. test1을 통하여 방의 정보를 제대로 가져오는지 확인
+describe("[rooms] 2.infoHandler", () => {
+ it("should return information of room", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ const testRoom = await roomModel.findOne({ name: "test-room" });
+ let req = httpMocks.createRequest({
+ query: { id: testRoom._id },
+ userId: testUser1.id,
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.infoHandler(req, res);
+
+ const resData = res._getData();
+ expect(resData).to.has.property("name", "test-room");
+ expect(resData).to.has.property("isOver");
+ });
+});
+
+// 3. 로그인되지 않은 유저가 방의 정보를 제대로 가져오는지 확인
+describe("[rooms] 3.publicInfoHandler", () => {
+ it("should return information of room", async () => {
+ const testRoom = await roomModel.findOne({ name: "test-room" });
+ let req = httpMocks.createRequest({
+ query: { id: testRoom._id },
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.publicInfoHandler(req, res);
+
+ const resData = res._getData();
+ expect(resData).to.has.property("name", "test-room");
+ expect(resData).to.has.property("isOver", undefined);
+ });
+});
+
+// 4. test2가 test-room에 join, 방에 잘 join 했는지 확인
+describe("[rooms] 4.joinHandler", () => {
+ it("should return information of room and join", async () => {
+ const testUser2 = await userGenerator("test2", testData);
+ const testRoom = await roomModel.findOne({ name: "test-room" });
+ let req = httpMocks.createRequest({
+ body: {
+ roomId: testRoom._id,
+ },
+ userId: testUser2.id,
+ app,
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.joinHandler(req, res);
+
+ const resData = res._getData();
+ expect(resData).to.has.property("name", "test-room");
+ expect(resData.part).to.have.lengthOf(2);
+ });
+});
+
+// 5. 방의 정보를 통해 검색, 검색 정보가 예상과 일치하는지 확인
+describe("[rooms] 5.searchHandler", () => {
+ it("should return information of searching room", async () => {
+ const testFrom = await locationModel.findOne({ koName: "대전역" });
+ const testTo = await locationModel.findOne({ koName: "택시승강장" });
+ let req = httpMocks.createRequest({
+ query: {
+ name: "test-room",
+ from: testFrom._id,
+ to: testTo._id,
+ time: Date.now(),
+ withTime: true,
+ maxPartLength: 4,
+ },
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.searchHandler(req, res);
+
+ const resJson = res._getJSONData();
+ expect(resJson[0]).to.has.property("name", "test-room");
+ expect(resJson[0].settlementTotal).to.be.undefined;
+ });
+});
+
+// 6. 방에 속한 유저를 통해 검색
+// ongoing은 test-room이 검색되고, done은 아무것도 검색되지 않아야함
+describe("[rooms] 6.searchByUserHandler", () => {
+ it("should return information of searching room", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ let req = httpMocks.createRequest({
+ userId: testUser1.id,
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.searchByUserHandler(req, res);
+
+ const resJson = res._getJSONData();
+ expect(resJson["ongoing"][0]).to.has.property("name", "test-room");
+ expect(resJson["done"][0]).to.be.undefined;
+ });
+});
+
+// 7. 1분이 지난 후, 정산 정보를 불러옴. 예상과 같은 정보를 불러오는지 확인
+describe("[rooms] 7.commitPaymentHandler", () => {
+ it("should return information of room and commit payment", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ const testRoom = await roomModel.findOne({ name: "test-room" });
+ let req = httpMocks.createRequest({
+ body: { roomId: testRoom._id },
+ userId: testUser1.id,
+ timestamp: Date.now() + 60 * 1000,
+ app,
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.commitPaymentHandler(req, res);
+
+ const resData = res._getData();
+ expect(resData).to.has.property("name", "test-room");
+ expect(resData).to.has.property("isOver", true);
+ expect(resData).to.has.property("settlementTotal", 1);
+ });
+});
+
+// 8. 도착 정보를 불러옴. 예상과 같은 정보를 불러오는지 확인
+describe("[rooms] 8.settlementHandler", () => {
+ it("should return information of room and set settlement", async () => {
+ const testUser2 = await userModel.findOne({ id: "test2" });
+ const testRoom = await roomModel.findOne({ name: "test-room" });
+ let req = httpMocks.createRequest({
+ body: { roomId: testRoom._id },
+ userId: testUser2.id,
+ app,
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.settlementHandler(req, res);
+
+ const resData = res._getData();
+ expect(resData).to.has.property("name", "test-room");
+ expect(resData).to.has.property("isOver", true);
+ expect(resData).to.has.property("settlementTotal", 2);
+ });
+});
+
+// 9. test2 방에서 퇴장, 제대로 방에서 나갔는지 확인하고 생성해준 data 모두 삭제
+describe("[rooms] 9.abortHandler", () => {
+ it("should return information of room and abort user", async () => {
+ const testUser2 = await userModel.findOne({ id: "test2" });
+ const testRoom = await roomModel.findOne({ name: "test-room" });
+ let req = httpMocks.createRequest({
+ body: { roomId: testRoom._id },
+ userId: testUser2.id,
+ session: {},
+ app,
+ });
+ let res = httpMocks.createResponse();
+ await roomsHandlers.abortHandler(req, res);
+ afterEach(removeTestData);
+
+ const resData = res._getData();
+ expect(resData).to.has.property("name", "test-room");
+ expect(resData.part).to.have.lengthOf(1);
+ });
+});
diff --git a/test/users.js b/test/services/users.js
similarity index 90%
rename from test/users.js
rename to test/services/users.js
index 1efa0d86..4f2195da 100644
--- a/test/users.js
+++ b/test/services/users.js
@@ -1,140 +1,140 @@
-const expect = require("chai").expect;
-const usersHandlers = require("../src/services/users");
-const { userModel } = require("../src/modules/stores/mongo");
-const { userGenerator, testRemover } = require("./utils");
-const httpMocks = require("node-mocks-http");
-
-let testData = { rooms: [], users: [], chat: [], location: [], report: [] };
-const removeTestData = async () => {
- await testRemover(testData);
-};
-
-// users.js 관련 5개의 handler을 테스트
-// 1. test1 유저를 생성 후, agreeOnTermsOfServiceHandler가 제대로 msg를 send 하는지 확인
-describe("[users] 1.agreeOnTermsOfServiceHandler", () => {
- it("should return correct response from handler", async () => {
- const testUser1 = await userGenerator("test1", testData);
- const msg =
- "User/agreeOnTermsOfService : agree on Terms of Service successful";
- let req = httpMocks.createRequest({
- userId: testUser1.id,
- });
- let res = httpMocks.createResponse();
- await usersHandlers.agreeOnTermsOfServiceHandler(req, res);
-
- const resData = res._getData();
- expect(res).to.has.property("statusCode", 200);
- expect(resData).to.equal(msg);
- });
-});
-
-// 2. test1 유저의 agreeOnTermsOfService 정보를 가져와서 true인지 확인
-describe("[users] 2.getAgreeOnTermsOfServiceHandler", () => {
- it("should return AgreeOnTermsOfService of user", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- let req = httpMocks.createRequest({
- userId: testUser1.id,
- });
- let res = httpMocks.createResponse();
- await usersHandlers.getAgreeOnTermsOfServiceHandler(req, res);
-
- const resJson = res._getJSONData();
- expect(res).to.has.property("statusCode", 200);
- expect(resJson).to.has.property("agreeOnTermsOfService", true);
- });
-});
-
-// 3. test1 유저의 nickname을 test-nickname으로 변경, 성공 메세지가 제대로 오는지 확인
-describe("[users] 3.editNicknameHandler", () => {
- const testNickname = "test-nickname";
-
- it("should return correct response from handler", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- const msg = "User/editNickname : edit user nickname successful";
- let req = httpMocks.createRequest({
- userId: testUser1.id,
- body: {
- nickname: testNickname,
- },
- });
- let res = httpMocks.createResponse();
- await usersHandlers.editNicknameHandler(req, res);
-
- const resData = res._getData();
- expect(res).to.has.property("statusCode", 200);
- expect(resData).to.equal(msg);
- });
-
- it("should be changed to new nickname", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- expect(testUser1).to.have.property("nickname", testNickname);
- });
-});
-
-// 3. test1 유저의 계좌번호를 testAccount으로 변경, 성공 메세지가 제대로 오는지 확인
-describe("[users] 4.editAccountHandler", () => {
- const testAccount = "신한 0123456789012";
-
- it("should return correct response from handler", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- const msg = "User/editAccount : edit user account successful";
- let req = httpMocks.createRequest({
- userId: testUser1.id,
- body: {
- account: testAccount,
- },
- });
- let res = httpMocks.createResponse();
- await usersHandlers.editAccountHandler(req, res);
-
- const resData = res._getData();
- expect(res).to.has.property("statusCode", 200);
- expect(resData).to.equal(msg);
- });
-
- it("should be changed to new account", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- expect(testUser1).to.have.property("account", testAccount);
- });
-});
-
-// 5. test1 유저의 프로필 업로드를 위한 PUrl을 제대로 받았는지 확인
-// 추가 검증을 위해, key와 Content-Type이 일치하는지 확인
-describe("[users] 5.editProfileImgGetPUrlHandler", () => {
- it("should return url and fields of data", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- const testImgType = "image/jpg";
- let req = httpMocks.createRequest({
- userId: testUser1.id,
- body: {
- type: testImgType,
- },
- });
- let res = httpMocks.createResponse();
- await usersHandlers.editProfileImgGetPUrlHandler(req, res);
-
- const resJson = res._getJSONData();
- expect(res).to.has.property("statusCode", 200);
- expect(resJson).to.has.property("url");
- expect(resJson.fields).to.has.property(
- "key",
- `profile-img/${testUser1._id}`
- );
- expect(resJson.fields).to.has.property("Content-Type", testImgType);
- });
-});
-
-// 6. test1 유저의 프로필 업로드가 정상적으로 완료되었는지 확인
-describe("[users] 6.editProfileImgDoneHandler", () => {
- it("should return correct result and new profileImageUrl", async () => {
- const testUser1 = await userModel.findOne({ id: "test1" });
- let req = httpMocks.createRequest({
- userId: testUser1.id,
- });
- let res = httpMocks.createResponse();
- await usersHandlers.editProfileImgDoneHandler(req, res);
- afterEach(removeTestData);
-
- expect(res).to.has.property("statusCode", 200);
- });
-});
+const expect = require("chai").expect;
+const usersHandlers = require("../../src/services/users");
+const { userModel } = require("../../src/modules/stores/mongo");
+const { userGenerator, testRemover } = require("../utils");
+const httpMocks = require("node-mocks-http");
+
+let testData = { rooms: [], users: [], chat: [], location: [], report: [] };
+const removeTestData = async () => {
+ await testRemover(testData);
+};
+
+// users.js 관련 5개의 handler을 테스트
+// 1. test1 유저를 생성 후, agreeOnTermsOfServiceHandler가 제대로 msg를 send 하는지 확인
+describe("[users] 1.agreeOnTermsOfServiceHandler", () => {
+ it("should return correct response from handler", async () => {
+ const testUser1 = await userGenerator("test1", testData);
+ const msg =
+ "Users/agreeOnTermsOfService : agree on Terms of Service successful";
+ let req = httpMocks.createRequest({
+ userId: testUser1.id,
+ });
+ let res = httpMocks.createResponse();
+ await usersHandlers.agreeOnTermsOfServiceHandler(req, res);
+
+ const resData = res._getData();
+ expect(res).to.has.property("statusCode", 200);
+ expect(resData).to.equal(msg);
+ });
+});
+
+// 2. test1 유저의 agreeOnTermsOfService 정보를 가져와서 true인지 확인
+describe("[users] 2.getAgreeOnTermsOfServiceHandler", () => {
+ it("should return AgreeOnTermsOfService of user", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ let req = httpMocks.createRequest({
+ userId: testUser1.id,
+ });
+ let res = httpMocks.createResponse();
+ await usersHandlers.getAgreeOnTermsOfServiceHandler(req, res);
+
+ const resJson = res._getJSONData();
+ expect(res).to.has.property("statusCode", 200);
+ expect(resJson).to.has.property("agreeOnTermsOfService", true);
+ });
+});
+
+// 3. test1 유저의 nickname을 test-nickname으로 변경, 성공 메세지가 제대로 오는지 확인
+describe("[users] 3.editNicknameHandler", () => {
+ const testNickname = "test-nickname";
+
+ it("should return correct response from handler", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ const msg = "Users/editNickname : edit user nickname successful";
+ let req = httpMocks.createRequest({
+ userId: testUser1.id,
+ body: {
+ nickname: testNickname,
+ },
+ });
+ let res = httpMocks.createResponse();
+ await usersHandlers.editNicknameHandler(req, res);
+
+ const resData = res._getData();
+ expect(res).to.has.property("statusCode", 200);
+ expect(resData).to.equal(msg);
+ });
+
+ it("should be changed to new nickname", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ expect(testUser1).to.have.property("nickname", testNickname);
+ });
+});
+
+// 3. test1 유저의 계좌번호를 testAccount으로 변경, 성공 메세지가 제대로 오는지 확인
+describe("[users] 4.editAccountHandler", () => {
+ const testAccount = "신한 0123456789012";
+
+ it("should return correct response from handler", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ const msg = "Users/editAccount : edit user account successful";
+ let req = httpMocks.createRequest({
+ userId: testUser1.id,
+ body: {
+ account: testAccount,
+ },
+ });
+ let res = httpMocks.createResponse();
+ await usersHandlers.editAccountHandler(req, res);
+
+ const resData = res._getData();
+ expect(res).to.has.property("statusCode", 200);
+ expect(resData).to.equal(msg);
+ });
+
+ it("should be changed to new account", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ expect(testUser1).to.have.property("account", testAccount);
+ });
+});
+
+// 5. test1 유저의 프로필 업로드를 위한 PUrl을 제대로 받았는지 확인
+// 추가 검증을 위해, key와 Content-Type이 일치하는지 확인
+describe("[users] 5.editProfileImgGetPUrlHandler", () => {
+ it("should return url and fields of data", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ const testImgType = "image/jpg";
+ let req = httpMocks.createRequest({
+ userId: testUser1.id,
+ body: {
+ type: testImgType,
+ },
+ });
+ let res = httpMocks.createResponse();
+ await usersHandlers.editProfileImgGetPUrlHandler(req, res);
+
+ const resJson = res._getJSONData();
+ expect(res).to.has.property("statusCode", 200);
+ expect(resJson).to.has.property("url");
+ expect(resJson.fields).to.has.property(
+ "key",
+ `profile-img/${testUser1._id}`
+ );
+ expect(resJson.fields).to.has.property("Content-Type", testImgType);
+ });
+});
+
+// 6. test1 유저의 프로필 업로드가 정상적으로 완료되었는지 확인
+describe("[users] 6.editProfileImgDoneHandler", () => {
+ it("should return correct result and new profileImageUrl", async () => {
+ const testUser1 = await userModel.findOne({ id: "test1" });
+ let req = httpMocks.createRequest({
+ userId: testUser1.id,
+ });
+ let res = httpMocks.createResponse();
+ await usersHandlers.editProfileImgDoneHandler(req, res);
+ afterEach(removeTestData);
+
+ expect(res).to.has.property("statusCode", 200);
+ });
+});
diff --git a/test/utils.js b/test/utils.js
index 5fbfcd38..e537913b 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -4,8 +4,12 @@ const {
chatModel,
locationModel,
reportModel,
+ connectDatabase,
} = require("../src/modules/stores/mongo");
const { generateProfileImageUrl } = require("../src/modules/modifyProfile");
+const { mongo: mongoUrl } = require("../loadenv");
+
+connectDatabase(mongoUrl);
// 테스트를 위한 유저 생성 함수
const userGenerator = async (username, testData) => {