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

+22
View File
@@ -0,0 +1,22 @@
import { User } from '@linux-odyssey/models'
import config from '../config.js'
import { createUser } from '../models/userManager.js'
export default async function setupTest() {
console.log('Setting up test account')
if (!(config.testing.username && config.testing.password)) {
throw new Error(
'No testing account found! Please set TESTING_USERNAME and TESTING_PASSWORD in .env'
)
}
const { username, password } = config.testing
const email = `${username}@example.com`
if (await User.exists({ username })) {
console.log('Testing account already exists')
return
}
await createUser(username, email, password)
console.log('Created testing account')
}