Compare commits
2 Commits
84bf5f3f79
...
e281bd4fa8
| Author | SHA1 | Date | |
|---|---|---|---|
| e281bd4fa8 | |||
| 52b5b72cfb |
@@ -31,6 +31,7 @@ jobs:
|
|||||||
needs: detect-changes
|
needs: detect-changes
|
||||||
if: needs.detect-changes.outputs.backend == 'true'
|
if: needs.detect-changes.outputs.backend == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
@@ -39,15 +40,18 @@ jobs:
|
|||||||
node-version: '22'
|
node-version: '22'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci --ignore-scripts
|
||||||
|
- name: Install backend native deps
|
||||||
|
run: npm rebuild sqlite3 bcrypt --workspace=farma-clic-backend
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: npm test --workspace=farma-clic-backend -- --ci
|
run: npm test --workspace=farma-clic-backend
|
||||||
|
|
||||||
test-frontend:
|
test-frontend:
|
||||||
name: Frontend Tests
|
name: Frontend Tests
|
||||||
needs: detect-changes
|
needs: detect-changes
|
||||||
if: needs.detect-changes.outputs.frontend == 'true'
|
if: needs.detect-changes.outputs.frontend == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
@@ -56,7 +60,7 @@ jobs:
|
|||||||
node-version: '22'
|
node-version: '22'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci --ignore-scripts
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
|
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
|
||||||
|
|
||||||
|
|||||||
@@ -6,42 +6,82 @@ on:
|
|||||||
- 'main'
|
- 'main'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
detect-changes:
|
||||||
name: Run Tests
|
name: Detect Changes
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
backend: ${{ steps.filter.outputs.backend }}
|
||||||
|
frontend: ${{ steps.filter.outputs.frontend }}
|
||||||
|
frontend-mobile: ${{ steps.filter.outputs.frontend-mobile }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- uses: dorny/paths-filter@v3
|
||||||
|
id: filter
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
filters: |
|
||||||
|
backend:
|
||||||
- name: Detect Changes
|
- 'apps/backend/**'
|
||||||
id: changes
|
- 'packages/**'
|
||||||
run: |
|
frontend:
|
||||||
BASE=${{ github.event.before }}
|
- 'apps/frontend/**'
|
||||||
[ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ] && BASE=$(git rev-parse HEAD~1)
|
- 'packages/**'
|
||||||
echo "backend=$(git diff --name-only "$BASE"...HEAD | grep -qE '^(apps/backend/|packages/)' && echo true || echo false)" >> "$GITHUB_OUTPUT"
|
frontend-mobile:
|
||||||
echo "frontend=$(git diff --name-only "$BASE"...HEAD | grep -qE '^(apps/frontend/|packages/)' && echo true || echo false)" >> "$GITHUB_OUTPUT"
|
- 'apps/frontend-mobile/**'
|
||||||
echo "frontend-mobile=$(git diff --name-only "$BASE"...HEAD | grep -qE '^(apps/frontend-mobile/|packages/)' && echo true || echo false)" >> "$GITHUB_OUTPUT"
|
- 'packages/**'
|
||||||
|
|
||||||
|
test-backend:
|
||||||
|
name: Backend Tests
|
||||||
|
needs: detect-changes
|
||||||
|
if: needs.detect-changes.outputs.backend == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 15
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: '22'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
- name: Install dependencies
|
||||||
- name: Install Dependencies
|
run: npm ci --ignore-scripts
|
||||||
run: npm ci
|
- name: Install backend native deps
|
||||||
|
run: npm rebuild sqlite3 bcrypt --workspace=farma-clic-backend
|
||||||
- name: Run Backend Tests
|
- name: Run Backend Tests
|
||||||
if: steps.changes.outputs.backend == 'true'
|
run: npm test --workspace=farma-clic-backend
|
||||||
run: npm test --workspace=farma-clic-backend -- --ci
|
|
||||||
|
|
||||||
|
test-frontend:
|
||||||
|
name: Frontend Tests
|
||||||
|
needs: detect-changes
|
||||||
|
if: needs.detect-changes.outputs.frontend == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '22'
|
||||||
|
cache: 'npm'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci --ignore-scripts
|
||||||
- name: Run Frontend Tests
|
- name: Run Frontend Tests
|
||||||
if: steps.changes.outputs.frontend == 'true'
|
|
||||||
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
|
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
|
||||||
|
|
||||||
|
test-frontend-mobile:
|
||||||
|
name: Frontend Mobile Tests
|
||||||
|
needs: detect-changes
|
||||||
|
if: needs.detect-changes.outputs.frontend-mobile == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '22'
|
||||||
|
cache: 'npm'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci --ignore-scripts
|
||||||
- name: Run Frontend Mobile Tests
|
- name: Run Frontend Mobile Tests
|
||||||
if: steps.changes.outputs.frontend-mobile == 'true'
|
|
||||||
run: npm test --workspace=frontend-mobile -- --ci
|
run: npm test --workspace=frontend-mobile -- --ci
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|||||||
@@ -3,4 +3,8 @@ export default {
|
|||||||
transform: {},
|
transform: {},
|
||||||
moduleFileExtensions: ['js', 'json'],
|
moduleFileExtensions: ['js', 'json'],
|
||||||
testMatch: ['**/__tests__/**/*.test.js'],
|
testMatch: ['**/__tests__/**/*.test.js'],
|
||||||
|
testTimeout: 15000,
|
||||||
|
openHandlesTimeout: 5000,
|
||||||
|
// Run test files in parallel (not individual tests within a file)
|
||||||
|
// workerIdleMemoryLimit: '512MB',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"migrate": "node migrate.js",
|
"migrate": "node migrate.js",
|
||||||
"reset-db": "bash reset-db.sh",
|
"reset-db": "bash reset-db.sh",
|
||||||
"import-farmacias": "node import-farmacias.js",
|
"import-farmacias": "node import-farmacias.js",
|
||||||
"test": "NODE_OPTIONS='--experimental-vm-modules' npx jest --forceExit"
|
"test": "NODE_OPTIONS='--experimental-vm-modules' npx jest --ci --forceExit --forceExitTimeout=30000"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ import * as appMetrics from './src/metrics.js';
|
|||||||
const redisClient = createClient({
|
const redisClient = createClient({
|
||||||
socket: {
|
socket: {
|
||||||
host: process.env.REDIS_HOST || 'localhost',
|
host: process.env.REDIS_HOST || 'localhost',
|
||||||
port: process.env.REDIS_PORT || 6379
|
port: process.env.REDIS_PORT || 6379,
|
||||||
|
reconnectStrategy: (retries) => {
|
||||||
|
if (retries > 10) return new Error('Redis max retries reached');
|
||||||
|
return Math.min(retries * 100, 3000);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
password: process.env.REDIS_PASSWORD || undefined
|
password: process.env.REDIS_PASSWORD || undefined
|
||||||
});
|
});
|
||||||
@@ -44,5 +48,9 @@ redisClient.setEx = async (...args) => {
|
|||||||
|
|
||||||
// Connect to Redis
|
// Connect to Redis
|
||||||
await redisClient.connect();
|
await redisClient.connect();
|
||||||
|
// Connect to Redis — skip in test (services are mocked) or when REDIS_URL is unset
|
||||||
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
|
await redisClient.connect();
|
||||||
|
}
|
||||||
|
|
||||||
export default redisClient;
|
export default redisClient;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
// OpenTelemetry SDK — must be imported first to instrument http, express, pg, etc.
|
// OpenTelemetry SDK — must be imported first to instrument http, express, pg, etc.
|
||||||
import './src/tracing.js';
|
// Skipped in test to avoid gRPC connection attempts to a non-existent collector.
|
||||||
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
|
await import('./src/tracing.js');
|
||||||
|
}
|
||||||
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import redisClient from './redis-client.js';
|
import redisClient from './redis-client.js';
|
||||||
@@ -19,8 +22,6 @@ import webpush from 'web-push';
|
|||||||
import pino from 'pino';
|
import pino from 'pino';
|
||||||
import pinoHttp from 'pino-http';
|
import pinoHttp from 'pino-http';
|
||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
import { createWorker } from 'tesseract.js';
|
|
||||||
import { BarcodeDetector } from 'barcode-detector';
|
|
||||||
import { searchMedicines, getMedicineDetails, searchOTC } from './cima-service.js';
|
import { searchMedicines, getMedicineDetails, searchOTC } from './cima-service.js';
|
||||||
import { searchBabyProducts, getBabyProductDetails } from './off-service.js';
|
import { searchBabyProducts, getBabyProductDetails } from './off-service.js';
|
||||||
import { runFarmaciaWebhookImport, DEFAULT_FARMACIAS_WEBHOOK, importPharmaciesFromRows } from './farmacias-webhook-import.js';
|
import { runFarmaciaWebhookImport, DEFAULT_FARMACIAS_WEBHOOK, importPharmaciesFromRows } from './farmacias-webhook-import.js';
|
||||||
@@ -914,6 +915,7 @@ app.post('/api/tsi/ocr', upload.single('photo'), async (req, res) => {
|
|||||||
|
|
||||||
console.log('[OCR] Processing image, size:', req.file.size, 'bytes');
|
console.log('[OCR] Processing image, size:', req.file.size, 'bytes');
|
||||||
|
|
||||||
|
const { createWorker } = await import('tesseract.js');
|
||||||
const worker = await createWorker('spa+eng');
|
const worker = await createWorker('spa+eng');
|
||||||
const { data } = await worker.recognize(req.file.buffer);
|
const { data } = await worker.recognize(req.file.buffer);
|
||||||
await worker.terminate();
|
await worker.terminate();
|
||||||
|
|||||||
Reference in New Issue
Block a user