Plan Done, Dockerization and cleanup
Build & Push Docker Images / test-backend (push) Successful in 55s
Build & Push Docker Images / test-frontend (push) Successful in 43s
Run Tests / test-backend (push) Successful in 48s
Run Tests / test-frontend (push) Successful in 42s
Build & Push Docker Images / build-backend (push) Failing after 4m7s
Build & Push Docker Images / build-frontend (push) Failing after 32s
Build & Push Docker Images / test-backend (push) Successful in 55s
Build & Push Docker Images / test-frontend (push) Successful in 43s
Run Tests / test-backend (push) Successful in 48s
Run Tests / test-frontend (push) Successful in 42s
Build & Push Docker Images / build-backend (push) Failing after 4m7s
Build & Push Docker Images / build-frontend (push) Failing after 32s
This commit is contained in:
@@ -1,12 +1,80 @@
|
||||
import { describe, test, expect, beforeEach } from '@jest/globals'
|
||||
import { jest } from '@jest/globals'
|
||||
|
||||
describe('Server', () => {
|
||||
test('server module can be imported', () => {
|
||||
// Basic sanity test - just checking the module loads
|
||||
expect(typeof describe).toBe('function')
|
||||
})
|
||||
jest.unstable_mockModule('../cima-service.js', () => ({
|
||||
searchMedicines: jest.fn(async () => []),
|
||||
getMedicineDetails: jest.fn(async () => null),
|
||||
}))
|
||||
|
||||
test('1 + 1 equals 2', () => {
|
||||
expect(1 + 1).toBe(2)
|
||||
jest.unstable_mockModule('../farmacias-webhook-import.js', () => ({
|
||||
runFarmaciaWebhookImport: jest.fn(async () => ({})),
|
||||
DEFAULT_FARMACIAS_WEBHOOK: '',
|
||||
importPharmaciesFromRows: jest.fn(async () => ({})),
|
||||
}))
|
||||
|
||||
jest.unstable_mockModule('../../API/index.js', () => ({
|
||||
fetchPharmaciesExternal: jest.fn(async () => []),
|
||||
}))
|
||||
|
||||
process.env.DATABASE_PATH = ':memory:'
|
||||
process.env.NODE_ENV = 'test'
|
||||
|
||||
const { default: supertest } = await import('supertest')
|
||||
const { app, initDatabase, db } = await import('../server.js')
|
||||
const { default: bcrypt } = await import('bcrypt')
|
||||
|
||||
beforeAll(async () => {
|
||||
await initDatabase()
|
||||
const hash = await bcrypt.hash('testpass', 10)
|
||||
await new Promise((resolve, reject) => {
|
||||
db.run(
|
||||
'INSERT INTO users (username, password_hash) VALUES (?, ?)',
|
||||
['testadmin', hash],
|
||||
(err) => (err ? reject(err) : resolve())
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Medicine search', () => {
|
||||
test('GET /api/medicines/search with empty q returns []', async () => {
|
||||
const res = await supertest(app).get('/api/medicines/search?q=')
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.body).toEqual([])
|
||||
})
|
||||
|
||||
test('GET /api/medicines/search with short q returns array', async () => {
|
||||
const res = await supertest(app).get('/api/medicines/search?q=a')
|
||||
expect(res.status).toBe(200)
|
||||
expect(Array.isArray(res.body)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Authentication', () => {
|
||||
test('POST /api/auth/login with wrong creds returns 401', async () => {
|
||||
const res = await supertest(app)
|
||||
.post('/api/auth/login')
|
||||
.send({ username: 'nobody', password: 'wrong' })
|
||||
expect(res.status).toBe(401)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Admin routes', () => {
|
||||
test('GET /api/admin/medicines without auth returns 401', async () => {
|
||||
const res = await supertest(app).get('/api/admin/medicines')
|
||||
expect(res.status).toBe(401)
|
||||
})
|
||||
|
||||
test('POST /api/admin/pharmacies with valid auth returns 201', async () => {
|
||||
const agent = supertest.agent(app)
|
||||
const login = await agent
|
||||
.post('/api/auth/login')
|
||||
.send({ username: 'testadmin', password: 'testpass' })
|
||||
expect(login.status).toBe(200)
|
||||
|
||||
const res = await agent.post('/api/admin/pharmacies').send({
|
||||
name: 'Test Pharmacy',
|
||||
address: 'Test Street 1',
|
||||
})
|
||||
expect(res.status).toBe(201)
|
||||
expect(res.body).toMatchObject({ name: 'Test Pharmacy', address: 'Test Street 1' })
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user