fix: address code review findings from story #01

- Makefile: -include .env (soft) so fresh clone doesn't hard-fail
- main.go: replace log.Fatalf-in-goroutine with error channel; startup
  failures now reach main goroutine so defer pool.Close() always runs
- main.go: context.WithTimeout(30s) on database.Connect to fail fast
  instead of hanging indefinitely on unreachable Postgres
- router.go: store pool on Echo context via middleware so future story
  handlers can retrieve it with c.Get("pool")
- config.go: require DATABASE_URL explicitly (log.Fatal if missing)
  instead of falling back to hardcoded credentials
- HelloWorld.test.ts: URL-aware fetch stub + afterEach restoreAllMocks;
  add flushPromises test verifying backend status renders

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-16 17:14:29 +02:00
co-authored by Claude Sonnet 4.6
parent 24a368cac3
commit 4d28916c7b
5 changed files with 60 additions and 19 deletions
+24 -10
View File
@@ -1,23 +1,37 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { mount, flushPromises } from '@vue/test-utils'
import { createPinia } from 'pinia'
import HelloWorld from './HelloWorld.vue'
// Stub fetch so the component's onMounted health call doesn't hit the network.
// Stub fetch; URL-aware so future tests can extend without cross-contamination.
const fetchMock = vi.fn((url: string) => {
if (url === '/api/v1/health') {
return Promise.resolve({ ok: true, json: async () => ({ status: 'ok' }) })
}
return Promise.reject(new Error(`Unexpected fetch: ${url}`))
})
beforeEach(() => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ status: 'ok' }),
}))
vi.stubGlobal('fetch', fetchMock)
})
afterEach(() => {
vi.restoreAllMocks()
})
describe('HelloWorld', () => {
it('renders the OSDB greeting', async () => {
const wrapper = mount(HelloWorld, {
global: {
plugins: [createPinia()],
},
global: { plugins: [createPinia()] },
})
expect(wrapper.text()).toContain('Hello, OSDB!')
})
it('displays backend status after health check resolves', async () => {
const wrapper = mount(HelloWorld, {
global: { plugins: [createPinia()] },
})
await flushPromises()
expect(wrapper.text()).toContain('ok')
})
})