Files
linux-odyssey/server/src/utils/setupTest.js
T
2023-11-17 11:41:33 +08:00

23 lines
691 B
JavaScript

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')
}