Initial commit: CraftDock as of 2026-11-01
The previous GitHub history was lost with the account (the local .git was missing its refs and most objects), so this repository starts from the existing code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
640e52c0c9
99 files changed
+12115
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import express from 'express';
|
||||
import session from 'express-session';
|
||||
import request from 'supertest';
|
||||
import { createAuthRouter } from '../../src/routes/auth.js';
|
||||
|
||||
function makeApp() {
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use(session({ secret: 't', resave: false, saveUninitialized: false }));
|
||||
const authService = { verifyPassword: async (p) => p === 'right' };
|
||||
app.use('/api/auth', createAuthRouter(authService));
|
||||
return app;
|
||||
}
|
||||
|
||||
describe('auth routes', () => {
|
||||
it('logs in with correct password and reports authed', async () => {
|
||||
const agent = request.agent(makeApp());
|
||||
const login = await agent.post('/api/auth/login').send({ password: 'right' });
|
||||
expect(login.status).toBe(200);
|
||||
const me = await agent.get('/api/auth/me');
|
||||
expect(me.body).toEqual({ authed: true });
|
||||
});
|
||||
|
||||
it('rejects wrong password', async () => {
|
||||
const res = await request(makeApp()).post('/api/auth/login').send({ password: 'no' });
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
|
||||
it('logs out', async () => {
|
||||
const agent = request.agent(makeApp());
|
||||
await agent.post('/api/auth/login').send({ password: 'right' });
|
||||
await agent.post('/api/auth/logout');
|
||||
const me = await agent.get('/api/auth/me');
|
||||
expect(me.body).toEqual({ authed: false });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user