Add scouthub-attivit-be
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import request from 'supertest';
|
||||
import { app } from '../../src/app';
|
||||
import { prisma } from '../../src/db/prisma';
|
||||
|
||||
// L'unica tabella che questi endpoint (read-only sulle anagrafiche) potrebbero
|
||||
// trovare "sporca" e' `materiale` (il seed non ne inserisce nessuno): la
|
||||
// puliamo prima di ogni test per non dipendere dall'ordine di esecuzione
|
||||
// rispetto alle altre suite.
|
||||
beforeEach(async () => {
|
||||
await prisma.materiale.deleteMany();
|
||||
});
|
||||
|
||||
describe('autocomplete endpoints', () => {
|
||||
test('POST /public/autocomplete/get/search senza body contiene il gruppo Testo', async () => {
|
||||
const res = await request(app).post('/public/autocomplete/get/search');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.some((g: { label: string }) => g.label === 'Testo')).toBe(true);
|
||||
});
|
||||
|
||||
test('POST /public/autocomplete/get/search con "gioco" contiene Categoria con le sotto-categorie', async () => {
|
||||
const res = await request(app)
|
||||
.post('/public/autocomplete/get/search')
|
||||
.set('Content-Type', 'application/json')
|
||||
.send('"gioco"');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
const categoria = res.body.find((g: { label: string }) => g.label === 'Categoria');
|
||||
expect(categoria).toBeDefined();
|
||||
expect(categoria.objectsList.map((o: { nome: string }) => o.nome).sort()).toEqual(
|
||||
["gioco", "gioco d'acqua", 'gioco giungla', 'gioco notturno', 'grande gioco'].sort(),
|
||||
);
|
||||
});
|
||||
|
||||
test('POST /public/autocomplete/get/branca con "e/g" restituisce un solo elemento E/G', async () => {
|
||||
const res = await request(app)
|
||||
.post('/public/autocomplete/get/branca')
|
||||
.set('Content-Type', 'application/json')
|
||||
.send('"e/g"');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toHaveLength(1);
|
||||
expect(res.body[0]).toMatchObject({ nome: 'E/G', gruppo: 'branca' });
|
||||
});
|
||||
|
||||
test('POST /public/autocomplete/get/materiale senza body restituisce array vuoto', async () => {
|
||||
const res = await request(app).post('/public/autocomplete/get/materiale');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user