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

@@ -0,0 +1,68 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { listSourceCorpora, createSourceCorpus, deleteSourceCorpus } from './sourceCorpus.js';
const okResponse = (body) => ({
ok: true,
status: 200,
json: () => Promise.resolve(body),
});
describe('sourceCorpora API', () => {
beforeEach(() => {
vi.stubGlobal('fetch', vi.fn());
});
afterEach(() => {
vi.restoreAllMocks();
});
describe('listSourceCorpora', () => {
it('fetches GET /api/source-corpus', async () => {
const data = [{ id: '1', name: 'NB' }];
fetch.mockResolvedValue(okResponse(data));
const result = await listSourceCorpora();
expect(fetch).toHaveBeenCalledWith('/api/source-corpus');
expect(result).toEqual(data);
});
});
describe('createSourceCorpus', () => {
it('sends POST with name in JSON body', async () => {
const corpus = { id: '2', name: 'New' };
fetch.mockResolvedValue(okResponse(corpus));
const result = await createSourceCorpus('New');
expect(fetch).toHaveBeenCalledWith('/api/source-corpus', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'New' }),
});
expect(result).toEqual(corpus);
});
});
describe('deleteSourceCorpus', () => {
it('sends DELETE to /api/source-corpus/:id', async () => {
fetch.mockResolvedValue(okResponse({}));
await deleteSourceCorpus('abc-123');
expect(fetch).toHaveBeenCalledWith('/api/source-corpus/abc-123', {
method: 'DELETE',
});
});
});
it('throws on non-ok response', async () => {
fetch.mockResolvedValue({
ok: false,
status: 500,
json: () => Promise.resolve({ error: 'Server down' }),
});
await expect(listSourceCorpora()).rejects.toThrow('Server down');
});
});