Files
alibb-server/backend/tests/auth.test.ts
T
2026-08-27 16:11:49 +08:00

30 lines
808 B
TypeScript

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import request from 'supertest';
import { setupApp, teardown } from './setup.js';
let app: any;
beforeAll(async () => {
({ app } = await setupApp());
}, 90000);
afterAll(async () => {
await teardown();
});
describe('auth', () => {
it('login with admin env creds returns token', async () => {
const res = await request(app)
.post('/api/auth/login')
.send({ username: 'admin', password: 'admin-password-1234' });
expect(res.status).toBe(200);
expect(res.body.token).toMatch(/^[A-Za-z0-9._-]+$/);
});
it('wrong password 401', async () => {
const res = await request(app)
.post('/api/auth/login')
.send({ username: 'admin', password: 'wrong' });
expect(res.status).toBe(401);
});
});