Skip to content

Commit

Permalink
Test: update test code
Browse files Browse the repository at this point in the history
  • Loading branch information
chlehdwon committed Aug 3, 2023
1 parent 37d2db7 commit 84ca67c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion test/reports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const expect = require("chai").expect;
const reportHandlers = require("../src/services/reports");
const { userModel } = require("../src/modules/stores/mongo");
const { userGenerator, testRemover } = require("./utils");
const { userGenerator, roomGenerator, testRemover } = require("./utils");
const httpMocks = require("node-mocks-http");

let testData = { rooms: [], users: [], chat: [], location: [], report: [] };
Expand All @@ -15,6 +15,7 @@ describe("[reports] 1.createHandler", () => {
it("should return correct response from handler", async () => {
const testUser1 = await userGenerator("test1", testData);
const testUser2 = await userGenerator("test2", testData);
const testRoom = await roomGenerator("test1", testData);
const msg = "User/report : report successful";
let req = httpMocks.createRequest({
userId: testUser1.id,
Expand All @@ -23,6 +24,7 @@ describe("[reports] 1.createHandler", () => {
type: "etc-reason",
etcDetail: "etc-detail",
time: Date.now(),
roomId: testRoom._id
},
});
let res = httpMocks.createResponse();
Expand Down
20 changes: 19 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ const userGenerator = async (username, testData) => {
return testUser;
};

const roomGenerator = async (roomname, testData) => {
const testFrom = await locationModel.findOne({ koName: "대전역" });
const testTo = await locationModel.findOne({ koName: "택시승강장" });
const testRoom = new roomModel({
name: roomname + "-room",
from: testFrom._id,
to: testTo._id,
time: Date.now() + 60 * 1000,
part: [],
madeat: Date.now(),
maxPartLength: 4,
settlementTotal: 0,
});
await testRoom.save();
testData["rooms"].push(testRoom);
return testRoom;
};

// 매 테스트가 끝나고 테스트 데이터를 초기화 해주기 위한 함수
// 더미 데이터를 생성할 경우 이 함수를 통해 제거
const testRemover = async (testData) => {
Expand All @@ -56,4 +74,4 @@ const testRemover = async (testData) => {
}
};

module.exports = { userGenerator, testRemover };
module.exports = { userGenerator, roomGenerator, testRemover };

0 comments on commit 84ca67c

Please sign in to comment.