feat: add testing setup in backend

This commit is contained in:
Lin, Hung-Shin committed 2023-11-17 10:59:47 +08:00
1 parent cb376caff0
commit 1f77328362
15 files changed
+92 -100

No files matched your search

+3 -7
View File
@@ -1,6 +1,7 @@
import { matchedData } from 'express-validator'
import { User } from '@linux-odyssey/models'
import { genJWT, hashPassword } from '../../utils/auth.js'
import { genJWT } from '../../utils/auth.js'
import { createUser } from '../../models/userManager.js'
import { asyncHandler } from '../../middleware/error.js'
export const issueToken = asyncHandler(async (req, res) => {
@@ -16,12 +17,7 @@ export const issueToken = asyncHandler(async (req, res) => {
export const register = asyncHandler(async (req, res, next) => {
const { username, password, email } = matchedData(req)
const user = new User({
username,
email,
})
user.hashedPassword = await hashPassword(password)
await user.save()
const user = await createUser(username, email, password)
req.login(user, (err) => {
if (err) {
next(err)
@@ -2,7 +2,7 @@ import { Command, Session } from '@linux-odyssey/models'
import { matchedData } from 'express-validator'
import CommandHandler from '../../game/commandHandler.js'
import { pushToSession } from '../socket.js'
import { finishSession } from '../../game/sessionManager.js'
import { finishSession } from '../../models/sessionManager.js'
import { asyncHandler } from '../../middleware/error.js'
const commandCompleteCallbacks = new Map()
@@ -4,7 +4,7 @@ import {
createNewSession,
getOrCreateActiveSession,
isQuestUnlocked,
} from '../../game/sessionManager.js'
} from '../../models/sessionManager.js'
import { asyncHandler } from '../../middleware/error.js'
function sessionSummary(session) {