make kestrel a tak server, so that it can send and receive pois as cots data
Some checks failed
ci/woodpecker/pr/pr Pipeline failed
Some checks failed
ci/woodpecker/pr/pr Pipeline failed
This commit is contained in:
51
test/unit/bootstrap.spec.js
vendored
Normal file
51
test/unit/bootstrap.spec.js
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { bootstrapAdmin } from '../../server/utils/bootstrap.js'
|
||||
|
||||
describe('bootstrapAdmin', () => {
|
||||
let run
|
||||
let get
|
||||
|
||||
beforeEach(() => {
|
||||
run = vi.fn().mockResolvedValue(undefined)
|
||||
get = vi.fn()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
delete process.env.BOOTSTRAP_EMAIL
|
||||
delete process.env.BOOTSTRAP_PASSWORD
|
||||
})
|
||||
|
||||
it('returns without inserting when users exist', async () => {
|
||||
get.mockResolvedValue({ n: 1 })
|
||||
await bootstrapAdmin(run, get)
|
||||
expect(get).toHaveBeenCalledWith('SELECT COUNT(*) as n FROM users')
|
||||
expect(run).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('inserts default admin when no users and no env', async () => {
|
||||
get.mockResolvedValue({ n: 0 })
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
await bootstrapAdmin(run, get)
|
||||
expect(run).toHaveBeenCalledTimes(1)
|
||||
const args = run.mock.calls[0][1]
|
||||
expect(args[1]).toBe('admin') // identifier
|
||||
expect(args[3]).toBe('admin') // role
|
||||
expect(logSpy).toHaveBeenCalled()
|
||||
logSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('inserts admin with BOOTSTRAP_EMAIL and BOOTSTRAP_PASSWORD when set', async () => {
|
||||
get.mockResolvedValue({ n: 0 })
|
||||
process.env.BOOTSTRAP_EMAIL = ' admin@example.com '
|
||||
process.env.BOOTSTRAP_PASSWORD = 'secret123'
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
await bootstrapAdmin(run, get)
|
||||
expect(run).toHaveBeenCalledTimes(1)
|
||||
const args = run.mock.calls[0][1]
|
||||
expect(args[1]).toBe('admin@example.com') // identifier
|
||||
expect(args[3]).toBe('admin') // role
|
||||
expect(logSpy).not.toHaveBeenCalled()
|
||||
logSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user