refactor utils

This commit is contained in:
wancat committed 2024-02-19 18:05:00 +08:00
1 parent 9509bbc355
commit d6c95cea4a
13 files changed
+126 -31

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import { User } from '@linux-odyssey/models'
import config from '../config.js'
import { createUser } from '../models/userManager.js'
import logger from './logger.js'
export default async function setupTest() {
logger.info('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 })) {
logger.info('Testing account already exists')
return
}
await createUser(username, email, { password })
logger.info('Created testing account')
}