Syntax changes in front and back end dirs. These do not affect functionality and are purely intended to better capture and describe the app's functionality and purpose

This commit is contained in:
KS Jannette
2026-08-03 00:07:58 -04:00
parent 4a5e5d6612
commit 0352bdf516
42 changed files with 812 additions and 812 deletions

View File

@@ -4,11 +4,11 @@ import { handleResponse } from './client.js';
const BASE = '/api/documents';
export async function generateDocument(notebookId, type) {
export async function generateDocument(sourceCorpusId, type) {
const res = await fetch(`${BASE}/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId, type }),
body: JSON.stringify({ sourceCorpusId, type }),
});
return handleResponse(res);
}

View File

@@ -5,11 +5,11 @@ import { handleResponse } from './client.js';
const BASE = '/api/query';
const CITATION_DETAIL_BASE = '/api/citation-detail';
export async function sendQuery(notebookId, question, onCitationDetails) {
export async function sendQuery(sourceCorpusId, question, onCitationDetails) {
const res = await fetch(BASE, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId, question }),
body: JSON.stringify({ sourceCorpusId, question }),
});
const data = await handleResponse(res);

View File

@@ -16,7 +16,7 @@ describe('sendQuery', () => {
vi.restoreAllMocks();
});
it('sends POST to /api/query with notebookId and question', async () => {
it('sends POST to /api/query with sourceCorpusId and question', async () => {
const data = { answer: 'The answer', citations: [] };
fetch.mockResolvedValue(okResponse(data));
@@ -25,7 +25,7 @@ describe('sendQuery', () => {
expect(fetch).toHaveBeenCalledWith('/api/query', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId: 'nb-1', question: 'What is AI?' }),
body: JSON.stringify({ sourceCorpusId: 'nb-1', question: 'What is AI?' }),
});
expect(result).toEqual(data);
});

View File

@@ -2,14 +2,14 @@
import { handleResponse } from './client.js';
const BASE = '/api/notebooks';
const BASE = '/api/source-corpus';
export async function listNotebooks() {
export async function listSourceCorpora() {
const res = await fetch(BASE);
return handleResponse(res);
}
export async function createNotebook(name) {
export async function createSourceCorpus(name) {
const res = await fetch(BASE, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -18,7 +18,7 @@ export async function createNotebook(name) {
return handleResponse(res);
}
export async function deleteNotebook(id) {
export async function deleteSourceCorpus(id) {
const res = await fetch(`${BASE}/${id}`, { method: 'DELETE' });
return handleResponse(res);
}

View File

@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { listNotebooks, createNotebook, deleteNotebook } from './notebooks.js';
import { listSourceCorpora, createSourceCorpus, deleteSourceCorpus } from './sourceCorpus.js';
const okResponse = (body) => ({
ok: true,
@@ -7,7 +7,7 @@ const okResponse = (body) => ({
json: () => Promise.resolve(body),
});
describe('notebooks API', () => {
describe('sourceCorpora API', () => {
beforeEach(() => {
vi.stubGlobal('fetch', vi.fn());
});
@@ -16,41 +16,41 @@ describe('notebooks API', () => {
vi.restoreAllMocks();
});
describe('listNotebooks', () => {
it('fetches GET /api/notebooks', async () => {
describe('listSourceCorpora', () => {
it('fetches GET /api/source-corpus', async () => {
const data = [{ id: '1', name: 'NB' }];
fetch.mockResolvedValue(okResponse(data));
const result = await listNotebooks();
const result = await listSourceCorpora();
expect(fetch).toHaveBeenCalledWith('/api/notebooks');
expect(fetch).toHaveBeenCalledWith('/api/source-corpus');
expect(result).toEqual(data);
});
});
describe('createNotebook', () => {
describe('createSourceCorpus', () => {
it('sends POST with name in JSON body', async () => {
const nb = { id: '2', name: 'New' };
fetch.mockResolvedValue(okResponse(nb));
const corpus = { id: '2', name: 'New' };
fetch.mockResolvedValue(okResponse(corpus));
const result = await createNotebook('New');
const result = await createSourceCorpus('New');
expect(fetch).toHaveBeenCalledWith('/api/notebooks', {
expect(fetch).toHaveBeenCalledWith('/api/source-corpus', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'New' }),
});
expect(result).toEqual(nb);
expect(result).toEqual(corpus);
});
});
describe('deleteNotebook', () => {
it('sends DELETE to /api/notebooks/:id', async () => {
describe('deleteSourceCorpus', () => {
it('sends DELETE to /api/source-corpus/:id', async () => {
fetch.mockResolvedValue(okResponse({}));
await deleteNotebook('abc-123');
await deleteSourceCorpus('abc-123');
expect(fetch).toHaveBeenCalledWith('/api/notebooks/abc-123', {
expect(fetch).toHaveBeenCalledWith('/api/source-corpus/abc-123', {
method: 'DELETE',
});
});
@@ -63,6 +63,6 @@ describe('notebooks API', () => {
json: () => Promise.resolve({ error: 'Server down' }),
});
await expect(listNotebooks()).rejects.toThrow('Server down');
await expect(listSourceCorpora()).rejects.toThrow('Server down');
});
});

View File

@@ -4,15 +4,15 @@ import { handleResponse } from './client.js';
const BASE = '/api/sources';
export async function listSources(notebookId) {
const res = await fetch(`${BASE}?notebookId=${notebookId}`);
export async function listSources(sourceCorpusId) {
const res = await fetch(`${BASE}?sourceCorpusId=${sourceCorpusId}`);
return handleResponse(res);
}
export async function uploadSource(notebookId, file) {
export async function uploadSource(sourceCorpusId, file) {
const formData = new FormData();
formData.append('file', file);
formData.append('notebookId', notebookId);
formData.append('sourceCorpusId', sourceCorpusId);
const res = await fetch(BASE, {
method: 'POST',
body: formData,
@@ -20,11 +20,11 @@ export async function uploadSource(notebookId, file) {
return handleResponse(res);
}
export async function addUrlSource(notebookId, url) {
export async function addUrlSource(sourceCorpusId, url) {
const res = await fetch(`${BASE}/url`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId, url }),
body: JSON.stringify({ sourceCorpusId, url }),
});
return handleResponse(res);
}

View File

@@ -17,19 +17,19 @@ describe('sources API', () => {
});
describe('listSources', () => {
it('fetches GET /api/sources with notebookId query param', async () => {
it('fetches GET /api/sources with sourceCorpusId query param', async () => {
const data = [{ id: 's1', name: 'file.pdf' }];
fetch.mockResolvedValue(okResponse(data));
const result = await listSources('nb-42');
expect(fetch).toHaveBeenCalledWith('/api/sources?notebookId=nb-42');
expect(fetch).toHaveBeenCalledWith('/api/sources?sourceCorpusId=nb-42');
expect(result).toEqual(data);
});
});
describe('uploadSource', () => {
it('sends POST with FormData containing file and notebookId', async () => {
it('sends POST with FormData containing file and sourceCorpusId', async () => {
const source = { id: 's2', name: 'doc.pdf' };
fetch.mockResolvedValue(okResponse(source));
@@ -42,7 +42,7 @@ describe('sources API', () => {
});
const formData = fetch.mock.calls[0][1].body;
expect(formData.get('notebookId')).toBe('nb-1');
expect(formData.get('sourceCorpusId')).toBe('nb-1');
expect(formData.get('file')).toBeInstanceOf(File);
expect(result).toEqual(source);
});
@@ -58,7 +58,7 @@ describe('sources API', () => {
expect(fetch).toHaveBeenCalledWith('/api/sources/url', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId: 'nb-5', url: 'https://example.com' }),
body: JSON.stringify({ sourceCorpusId: 'nb-5', url: 'https://example.com' }),
});
expect(result).toEqual(source);
});