removed mocks

This commit is contained in:
2025-11-10 12:19:37 +01:00
parent eee254ff9f
commit 2e27395ed0
6 changed files with 28 additions and 290 deletions

View File

@@ -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
}
]

View File

@@ -1,13 +0,0 @@
{
"scheduleCron": "*/10 7-22 * * *",
"randomDelayMinSeconds": 10,
"randomDelayMaxSeconds": 120,
"initialDelayMinSeconds": 5,
"initialDelayMaxSeconds": 30,
"ignoredSlots": [
{
"storeId": "51450",
"description": "TVS"
}
]
}

View File

@@ -1,7 +0,0 @@
{
"839246": {
"email": "meikdre@gmx.de",
"password": "R67aJUj2-wWVfP8",
"token": "5e5b273c-fd9c-4a1f-a4cd-55b26a3b6419"
}
}

View File

@@ -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
}
]

View File

@@ -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) {

View File

@@ -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 () => {