feat: add has_notes and notes_preview to session list, omit full notes
Made-with: Cursor
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
const request = require('supertest');
|
||||
const { app } = require('../../backend/server');
|
||||
const { cleanDb, getAuthHeader, seedSession } = require('../helpers/test-utils');
|
||||
const { computeNotesPreview } = require('../../backend/utils/notes-preview');
|
||||
|
||||
describe('computeNotesPreview', () => {
|
||||
@@ -62,3 +65,42 @@ describe('computeNotesPreview', () => {
|
||||
expect(result.notes_preview).not.toContain('...');
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /api/sessions list', () => {
|
||||
beforeEach(() => {
|
||||
cleanDb();
|
||||
});
|
||||
|
||||
test('includes has_notes and notes_preview in list response', async () => {
|
||||
seedSession({ notes: '**Bold** first paragraph\n\nSecond paragraph' });
|
||||
seedSession({ notes: null });
|
||||
|
||||
const res = await request(app).get('/api/sessions');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toHaveLength(2);
|
||||
|
||||
const withNotes = res.body.find(s => s.has_notes === true);
|
||||
const withoutNotes = res.body.find(s => s.has_notes === false);
|
||||
|
||||
expect(withNotes.notes_preview).toBe('Bold first paragraph');
|
||||
expect(withNotes).not.toHaveProperty('notes');
|
||||
|
||||
expect(withoutNotes.notes_preview).toBeNull();
|
||||
expect(withoutNotes).not.toHaveProperty('notes');
|
||||
});
|
||||
|
||||
test('list response preserves existing fields', async () => {
|
||||
seedSession({ is_active: 1, notes: 'Test' });
|
||||
|
||||
const res = await request(app).get('/api/sessions');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body[0]).toHaveProperty('id');
|
||||
expect(res.body[0]).toHaveProperty('created_at');
|
||||
expect(res.body[0]).toHaveProperty('closed_at');
|
||||
expect(res.body[0]).toHaveProperty('is_active');
|
||||
expect(res.body[0]).toHaveProperty('games_played');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user