chore: remove Open Food Facts (OFF) integration

- Remove off-service.js and off-service.test.js
- Remove OFF import from server.js
- Simplify /api/products/search to only use CIMA
- Remove 'openfoodfacts' from valid product sources
- Update frontend-mobile Product interface to remove OFF source
- Remove OFF env vars from .env.example
- Add PARAPHARMACY_API_URL to .env.example

OFF was replaced by the new parapharmacy-api microservice.
This commit is contained in:
Antoni Nuñez Romeu
2026-07-16 12:34:08 +02:00
parent b34657c78f
commit 7274979f62
6 changed files with 11 additions and 351 deletions
-107
View File
@@ -1,107 +0,0 @@
import { jest } from '@jest/globals'
jest.unstable_mockModule('../redis-client.js', () => ({
default: {
get: jest.fn(async () => null),
setEx: jest.fn(async () => 'OK'),
},
}))
jest.unstable_mockModule('axios', () => ({
default: {
get: jest.fn(async () => ({ data: { products: [] } })),
},
}))
const { transformOFFProduct, searchBabyProducts, getBabyProductDetails } = await import('../off-service.js')
describe('transformOFFProduct', () => {
test('transforms a valid OFF product to unified model', () => {
const offProduct = {
_id: '12345',
product_name: 'Baby Rice',
brands: 'Nestlé',
image_url: 'https://example.com/image.jpg',
nutriscore_grade: 'a',
ingredients_text: 'Rice, Iron, Vitamins',
nova_group: 1,
ecoscore_grade: 'b',
categories_tags: ['en:baby-foods', 'en:baby-rice'],
}
const result = transformOFFProduct(offProduct)
expect(result).toEqual({
id: '12345',
source: 'openfoodfacts',
name: 'Baby Rice',
brand: 'Nestlé',
category: 'baby_food',
image_url: 'https://example.com/image.jpg',
nutriscore: 'a',
ingredients: 'Rice, Iron, Vitamins',
nova_group: 1,
eco_score: 'b',
})
})
test('returns null for null/undefined input', () => {
expect(transformOFFProduct(null)).toBeNull()
expect(transformOFFProduct(undefined)).toBeNull()
})
test('returns null when missing required fields', () => {
expect(transformOFFProduct({ _id: '123' })).toBeNull()
expect(transformOFFProduct({ product_name: 'Test' })).toBeNull()
})
test('sets default brand to empty string when missing', () => {
const result = transformOFFProduct({
_id: '999',
product_name: 'Plain Product',
})
expect(result.brand).toBe('')
expect(result.image_url).toBeNull()
expect(result.nutriscore).toBeNull()
expect(result.ingredients).toBeNull()
expect(result.nova_group).toBeNull()
expect(result.eco_score).toBeNull()
})
test('detects baby_milk category from tags', () => {
const result = transformOFFProduct({
_id: '200',
product_name: 'Infant Formula',
categories_tags: ['en:infant-milk'],
})
expect(result.category).toBe('baby_milk')
})
test('detects baby_cereal category from tags', () => {
const result = transformOFFProduct({
_id: '300',
product_name: 'Baby Cereal',
categories_tags: ['en:baby-cereals'],
})
expect(result.category).toBe('baby_cereal')
})
})
describe('searchBabyProducts', () => {
test('returns empty array for short query', async () => {
const result = await searchBabyProducts('a')
expect(result).toEqual([])
})
test('returns empty array for null/empty query', async () => {
expect(await searchBabyProducts(null)).toEqual([])
expect(await searchBabyProducts('')).toEqual([])
})
})
describe('getBabyProductDetails', () => {
test('returns null for null barcode', async () => {
const result = await getBabyProductDetails(null)
expect(result).toBeNull()
})
})
-5
View File
@@ -6,11 +6,6 @@ jest.unstable_mockModule('../cima-service.js', () => ({
searchOTC: jest.fn(async () => []),
}))
jest.unstable_mockModule('../off-service.js', () => ({
searchBabyProducts: jest.fn(async () => []),
getBabyProductDetails: jest.fn(async () => null),
}))
jest.unstable_mockModule('../farmacias-webhook-import.js', () => ({
runFarmaciaWebhookImport: jest.fn(async () => ({})),
DEFAULT_FARMACIAS_WEBHOOK: '',