From 2e27395ed00f3c4e1c413af7c5640dbdc2fb95fb Mon Sep 17 00:00:00 2001 From: Meik Date: Mon, 10 Nov 2025 12:19:37 +0100 Subject: [PATCH] removed mocks --- config/839246-pickup-config.json | 170 ------------------------------ config/admin-settings.json | 13 --- config/credentials.json | 7 -- config/pickup-config.json | 73 ------------- src/hooks/usePickupConfig.js | 39 +++---- src/hooks/usePickupConfig.test.js | 16 ++- 6 files changed, 28 insertions(+), 290 deletions(-) delete mode 100644 config/839246-pickup-config.json delete mode 100644 config/admin-settings.json delete mode 100644 config/credentials.json delete mode 100644 config/pickup-config.json diff --git a/config/839246-pickup-config.json b/config/839246-pickup-config.json deleted file mode 100644 index 8c8afa4..0000000 --- a/config/839246-pickup-config.json +++ /dev/null @@ -1,170 +0,0 @@ -[ - { - "id": "44972", - "label": "Aldi Süd RA Biblisweg", - "active": false, - "checkProfileId": true, - "onlyNotify": true - }, - { - "id": "44975", - "label": "Aldi Süd RA Kuppenheim", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "44971", - "label": "Aldi Süd RA LützowerStr.", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "63367", - "label": "Arena Balkan Bäckerei", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "59378", - "label": "Backwaren Kaufland", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "49712", - "label": "Baden-Baden foodsharing", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "42264", - "label": "Bildungshaus St. Bernhard, Rastatt", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "43191", - "label": "Café Böckeler Baden-Baden", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "33875", - "label": "CAP-Markt Sandweier", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "28513", - "label": "denn's Biomarkt", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "42322", - "label": "Edeka Fischer Haueneberstein", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "40082", - "label": "Ernteaktionen rund um Baden-Baden", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "40261", - "label": "Eventbetrieb Rastatt/Baden-Baden", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "51450", - "label": "Hornbach KA-Grünwinkel", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "62551", - "label": "Koordinationsbetrieb Fairteiler Sandweier ", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "53552", - "label": "Koordinationsbetrieb Fairteiler Spitalkirche", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "43754", - "label": "Koordinationsbetrieb Lebensmittelspenden für Geflüchtete bei Sinzheim", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "66125", - "label": "Murgtal Foodsharing", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "62533", - "label": "New Pop-Festival", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "31602", - "label": "Notfallteam Rastatt/Baden-Baden / spontane Abholungen", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "63448", - "label": "Penny Baden-Oos", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "41393", - "label": "Weihnachtsmarkt Baden-Baden", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "22787", - "label": "Weihnachtsmarkt Rastatt", - "active": false, - "checkProfileId": true, - "onlyNotify": false - }, - { - "id": "36100", - "label": "Bäckerei Späth", - "active": false, - "checkProfileId": true, - "onlyNotify": false - } -] \ No newline at end of file diff --git a/config/admin-settings.json b/config/admin-settings.json deleted file mode 100644 index af162f6..0000000 --- a/config/admin-settings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "scheduleCron": "*/10 7-22 * * *", - "randomDelayMinSeconds": 10, - "randomDelayMaxSeconds": 120, - "initialDelayMinSeconds": 5, - "initialDelayMaxSeconds": 30, - "ignoredSlots": [ - { - "storeId": "51450", - "description": "TVS" - } - ] -} \ No newline at end of file diff --git a/config/credentials.json b/config/credentials.json deleted file mode 100644 index 1cd9355..0000000 --- a/config/credentials.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "839246": { - "email": "meikdre@gmx.de", - "password": "R67aJUj2-wWVfP8", - "token": "5e5b273c-fd9c-4a1f-a4cd-55b26a3b6419" - } -} \ No newline at end of file diff --git a/config/pickup-config.json b/config/pickup-config.json deleted file mode 100644 index b44d5fe..0000000 --- a/config/pickup-config.json +++ /dev/null @@ -1,73 +0,0 @@ -[ - { - "id": "63448", - "active": false, - "checkProfileId": true, - "onlyNotify": true, - "label": "Penny Baden-Oos", - "desiredDate": null - }, - { - "id": "44975", - "active": false, - "checkProfileId": false, - "onlyNotify": true, - "label": "Aldi Kuppenheim", - "desiredWeekday": null - }, - { - "id": "44972", - "active": false, - "checkProfileId": false, - "onlyNotify": true, - "label": "Aldi Biblisweg", - "desiredWeekday": null - }, - { - "id": "44975", - "active": false, - "checkProfileId": true, - "onlyNotify": false, - "label": "Aldi Kuppenheim", - "desiredDate": "2025-06-28" - }, - { - "id": "33875", - "active": true, - "checkProfileId": true, - "onlyNotify": false, - "label": "Cap Markt", - "desiredWeekday": "Donnerstag", - "desiredDate": null - }, - { - "id": "42322", - "active": false, - "checkProfileId": true, - "onlyNotify": true, - "label": "Edeka Haueneberstein", - "desiredDate": null - }, - { - "id": "51450", - "active": false, - "checkProfileId": true, - "onlyNotify": true, - "label": "Hornbach Grünwinkel" - }, - { - "id": "63367", - "label": "Arena Balkan Bäckerei", - "active": false, - "checkProfileId": true, - "onlyNotify": true - }, - { - "id": "42264", - "label": "Bildungshaus St. Bernhard, Rastatt", - "active": false, - "checkProfileId": true, - "onlyNotify": false, - "desiredDate": null - } -] \ No newline at end of file diff --git a/src/hooks/usePickupConfig.js b/src/hooks/usePickupConfig.js index 497cb74..7641923 100644 --- a/src/hooks/usePickupConfig.js +++ b/src/hooks/usePickupConfig.js @@ -5,23 +5,6 @@ import { formatDateValue } from '../utils/dateUtils'; const API_URL = '/api/iobroker/pickup-config'; const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); -const STATIC_CONFIG = [ - { id: '63448', active: false, checkProfileId: true, onlyNotify: true, label: 'Penny Baden-Oos' }, - { id: '44975', active: false, checkProfileId: true, onlyNotify: false, label: 'Aldi Kuppenheim', desiredWeekday: 'Samstag' }, - { id: '44972', active: false, checkProfileId: true, onlyNotify: false, label: 'Aldi Biblisweg', desiredWeekday: 'Dienstag' }, - { - id: '44975', - active: false, - checkProfileId: true, - onlyNotify: false, - label: 'Aldi Kuppenheim', - desiredDateRange: { start: '2025-05-18', end: '2025-05-18' } - }, - { id: '33875', active: false, checkProfileId: true, onlyNotify: false, label: 'Cap Markt', desiredWeekday: 'Donnerstag' }, - { id: '42322', active: false, checkProfileId: false, onlyNotify: false, label: 'Edeka Haueneberstein' }, - { id: '51450', active: false, checkProfileId: true, onlyNotify: false, label: 'Hornbach Grünwinkel' } -]; - const usePickupConfig = () => { const [config, setConfig] = useState([]); const [loading, setLoading] = useState(true); @@ -33,11 +16,12 @@ const usePickupConfig = () => { setError(''); try { - // In einer echten Implementierung würde hier die API aufgerufen: - // const response = await fetch(API_URL); - // const data = await response.json(); - await delay(500); - setConfig(sortEntriesByLabel(STATIC_CONFIG)); + const response = await fetch(API_URL); + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } + const data = await response.json(); + setConfig(sortEntriesByLabel(Array.isArray(data) ? data : [])); } catch (err) { setError('Fehler beim Laden der Konfiguration: ' + err.message); } finally { @@ -50,9 +34,14 @@ const usePickupConfig = () => { setError(''); try { - // API-Aufruf zum Speichern der Konfiguration: - // await fetch(API_URL, { method: 'POST', body: JSON.stringify(config) }); - await delay(1000); + const response = await fetch(API_URL, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(config) + }); + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } setStatus('Konfiguration erfolgreich gespeichert!'); setTimeout(() => setStatus(''), 3000); } catch (err) { diff --git a/src/hooks/usePickupConfig.test.js b/src/hooks/usePickupConfig.test.js index c302880..a00c64a 100644 --- a/src/hooks/usePickupConfig.test.js +++ b/src/hooks/usePickupConfig.test.js @@ -3,6 +3,11 @@ import { act, render } from '@testing-library/react'; import usePickupConfig from './usePickupConfig'; describe('usePickupConfig', () => { + const mockConfig = [ + { id: '2', label: 'Beta Store', active: false, checkProfileId: true, onlyNotify: false }, + { id: '1', label: 'alpha Shop', active: false, checkProfileId: true, onlyNotify: false } + ]; + const advanceTimers = async (ms = 0) => { await act(async () => { jest.advanceTimersByTime(ms); @@ -22,9 +27,16 @@ describe('usePickupConfig', () => { beforeEach(() => { jest.useFakeTimers(); + global.fetch = jest.fn(() => + Promise.resolve({ + ok: true, + json: () => Promise.resolve(mockConfig) + }) + ); }); afterEach(() => { + global.fetch.mockRestore?.(); jest.useRealTimers(); }); @@ -33,8 +45,8 @@ describe('usePickupConfig', () => { await advanceTimers(600); const hook = getHook(); expect(hook.loading).toBe(false); - expect(hook.config[0].label).toBe('Aldi Biblisweg'); - expect(hook.config[hook.config.length - 1].label).toBe('Penny Baden-Oos'); + expect(hook.config[0].label).toBe('alpha Shop'); + expect(hook.config[hook.config.length - 1].label).toBe('Beta Store'); }); test('mutators update entries as expected', async () => {