Slefhostet und postgres

This commit is contained in:
2026-04-02 11:39:57 +02:00
parent b1c99893a6
commit 08483c7075
215 changed files with 4584 additions and 5190 deletions

View File

@@ -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 });

View File

@@ -196,4 +196,81 @@ describe('mockBackendService billing simulation', () => {
expect(second.billing.credits.topupBalance).toBe(25);
});
it('ignores malformed pro entitlements coming from top-up customer info', async () => {
const response = await mockBackendService.syncRevenueCatState({
userId: 'test-user-rc-topup-misconfigured-entitlement',
source: 'topup_purchase',
customerInfo: {
entitlements: {
active: {
pro: {
productIdentifier: 'topup_small',
expirationDate: '2026-04-30T00:00:00.000Z',
},
},
},
nonSubscriptions: {
topup_small: [
{
productIdentifier: 'topup_small',
transactionIdentifier: 'rc-topup-malformed-1',
},
],
},
},
});
expect(response.billing.entitlement.plan).toBe('free');
expect(response.billing.entitlement.status).toBe('inactive');
expect(response.billing.credits.topupBalance).toBe(25);
expect(response.billing.credits.available).toBe(40);
});
it('does not downgrade an existing pro user during a top-up sync', async () => {
const userId = 'test-user-rc-pro-topup';
await mockBackendService.syncRevenueCatState({
userId,
source: 'subscription_purchase',
customerInfo: {
entitlements: {
active: {
pro: {
productIdentifier: 'monthly_pro',
expirationDate: '2026-04-30T00:00:00.000Z',
},
},
},
nonSubscriptions: {},
},
});
const response = await mockBackendService.syncRevenueCatState({
userId,
source: 'topup_purchase',
customerInfo: {
entitlements: {
active: {
pro: {
productIdentifier: 'topup_small',
expirationDate: '2026-04-30T00:00:00.000Z',
},
},
},
nonSubscriptions: {
topup_small: [
{
productIdentifier: 'topup_small',
transactionIdentifier: 'rc-topup-pro-1',
},
],
},
},
});
expect(response.billing.entitlement.plan).toBe('pro');
expect(response.billing.credits.available).toBe(275);
expect(response.billing.credits.topupBalance).toBe(25);
});
});