Slefhostet und postgres
This commit is contained in:
@@ -1,20 +1,16 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const { closeDatabase, openDatabase, run } = require('../../server/lib/sqlite');
|
||||
const { ensurePlantSchema, getPlants } = require('../../server/lib/plants');
|
||||
|
||||
describe('server plant search ranking', () => {
|
||||
let db;
|
||||
let dbPath;
|
||||
|
||||
beforeAll(async () => {
|
||||
dbPath = path.join(os.tmpdir(), `greenlns-search-${Date.now()}.sqlite`);
|
||||
db = await openDatabase(dbPath);
|
||||
await ensurePlantSchema(db);
|
||||
|
||||
const entries = [
|
||||
const { closeDatabase, openDatabase } = require('../../server/lib/sqlite');
|
||||
const { ensurePlantSchema, getPlants, rebuildPlantsCatalog } = require('../../server/lib/plants');
|
||||
|
||||
const describeIfDatabase = process.env.DATABASE_URL ? describe : describe.skip;
|
||||
|
||||
describeIfDatabase('server plant search ranking', () => {
|
||||
let db;
|
||||
|
||||
beforeAll(async () => {
|
||||
db = await openDatabase();
|
||||
await ensurePlantSchema(db);
|
||||
|
||||
const entries = [
|
||||
{
|
||||
id: '1',
|
||||
name: 'Snake Plant',
|
||||
@@ -83,45 +79,18 @@ describe('server plant search ranking', () => {
|
||||
},
|
||||
];
|
||||
|
||||
for (const entry of entries) {
|
||||
await run(
|
||||
db,
|
||||
`INSERT INTO plants (
|
||||
id,
|
||||
name,
|
||||
botanicalName,
|
||||
imageUri,
|
||||
imageStatus,
|
||||
description,
|
||||
categories,
|
||||
careInfo,
|
||||
confidence,
|
||||
createdAt,
|
||||
updatedAt
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))`,
|
||||
[
|
||||
entry.id,
|
||||
entry.name,
|
||||
entry.botanicalName,
|
||||
entry.imageUri,
|
||||
entry.imageStatus,
|
||||
entry.description,
|
||||
JSON.stringify(entry.categories),
|
||||
JSON.stringify(entry.careInfo),
|
||||
entry.confidence,
|
||||
],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (db) {
|
||||
await closeDatabase(db);
|
||||
}
|
||||
if (dbPath && fs.existsSync(dbPath)) {
|
||||
fs.unlinkSync(dbPath);
|
||||
}
|
||||
});
|
||||
await rebuildPlantsCatalog(db, entries, {
|
||||
source: 'plantsSearch.test',
|
||||
preserveExistingIds: false,
|
||||
enforceUniqueImages: true,
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (db) {
|
||||
await closeDatabase(db);
|
||||
}
|
||||
});
|
||||
|
||||
it('returns exact common name matches first', async () => {
|
||||
const results = await getPlants(db, { query: 'Monstera', limit: 3 });
|
||||
|
||||
Reference in New Issue
Block a user