mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
refactor utils
This commit is contained in:
1 parent
9509bbc355
commit
d6c95cea4a
13 files changed
+126
-31
No files matched your search
@@ -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')
|
||||
}
|
||||
Reference in new issue
Block a user