diff --git a/api/src/repositories/item.repository.js b/api/src/repositories/item.repository.js index ac9455006..006618a2b 100644 --- a/api/src/repositories/item.repository.js +++ b/api/src/repositories/item.repository.js @@ -4109,7 +4109,21 @@ class ItemRepository extends BaseModel { licenseId: branchDoc.license, }); const values = (read && read.status && read.data && read.data.values) || {}; - return values.table_options === 'enable' ? 'restaurant' : 'retail'; + /* + * Stored as the STRING 'true' by the Features page, as a boolean by + * older saves, and as 'enable' only in the console's own cache. The + * first cut of this read 'enable' and made every shop a shop. + */ + const raw = values.table_options; + const on = + raw === true || + raw === 1 || + ['true', 'enable', 'enabled', '1', 'on', 'yes'].includes( + String(raw == null ? '' : raw) + .trim() + .toLowerCase() + ); + return on ? 'restaurant' : 'retail'; } catch (e) { console.warn('[storefront] could not read the shop kind:', e.message); return 'retail'; diff --git a/api/tests/unit/repositories/item.repository.test.js b/api/tests/unit/repositories/item.repository.test.js index d7accc169..aca0b460e 100644 --- a/api/tests/unit/repositories/item.repository.test.js +++ b/api/tests/unit/repositories/item.repository.test.js @@ -1522,15 +1522,22 @@ describe('ItemRepository', () => { }; test('the Restaurant module makes it a restaurant, with a note for the kitchen', async () => { - const data = await storefrontFor({ store_id: 'AZ100' }, 'enable'); - expect(data.store.kind).toBe('restaurant'); - expect(data.features.notes).toBe(true); + /* The Features page saves the switch as the STRING 'true'; older saves + hold a boolean; the console's own cache says 'enable'. The first cut + read only the cache's word and made every shop a shop. */ + for (const stored of ['true', true, 'enable', 1]) { + const data = await storefrontFor({ store_id: 'AZ100' }, stored); + expect(data.store.kind).toBe('restaurant'); + expect(data.features.notes).toBe(true); + } }); test('without it the page is told this is a shop', async () => { - const data = await storefrontFor({ store_id: 'AZ100' }, 'disable'); - expect(data.store.kind).toBe('retail'); - expect(data.features.notes).toBe(false); + for (const stored of ['false', false, 'disable', undefined, '']) { + const data = await storefrontFor({ store_id: 'AZ100' }, stored); + expect(data.store.kind).toBe('retail'); + expect(data.features.notes).toBe(false); + } }); test('a shop with no gateway takes payment at the counter', async () => {