Eingangsrechnungen: neue Endpunkte editForm.php und update.php
Agrarmonitor hat eingangsrechnungen.php entfernt (404). Das
Bearbeiten-Formular kommt jetzt von editForm.php?invoiceID=<id>,
gespeichert wird per JSON-POST an update.php mit
{ rechnungID, formData }. setRechnungsdaten laedt dafuer das
aktuelle Formular, uebernimmt alle Felder und ueberschreibt nur die
geaenderten Werte. Eine Fehlermeldung (msg) aus update.php wird als
Exception weitergegeben.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4cd0da4a8a
commit
0a01fbe8ca
6 files changed
+307
-50
No files matched your search
@@ -0,0 +1,158 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const http = require('node:http');
|
||||
const test = require('node:test');
|
||||
|
||||
const { AgrarmonitorConnector, MemoryCookieStore } = require('../dist');
|
||||
|
||||
// Gekuerzter Formularausschnitt, wie ihn editForm.php liefert.
|
||||
const editForm = `
|
||||
<form id="rechnung-detail">
|
||||
<select name="typ" id="typ">
|
||||
<option value="0" selected>Eingangsrechnung</option>
|
||||
<option value="1">Gutschrift</option>
|
||||
</select>
|
||||
<select name="mengenUndPreisAnpassung">
|
||||
<option value="0" selected>Preise und Mengen beibehalten</option>
|
||||
<option value="1">Anpassen</option>
|
||||
</select>
|
||||
<input type="text" name="lieferscheinnummer" value="">
|
||||
<input type="text" name="rechnungsnummer" id="rechnungsnummer" value="5355771416">
|
||||
<input type="text" name="rechnungsdatum" value="19.08.26">
|
||||
<select name="firma_id">
|
||||
<option value="1">Andere GmbH</option>
|
||||
<option value="3" selected>Poettker GmbH</option>
|
||||
</select>
|
||||
<select name="rgempf">
|
||||
<option value="34079" selected>15550519 TUEV NORD Mobilitaet</option>
|
||||
</select>
|
||||
<input name="addressName" value="TUEV NORD Mobilitaet GmbH & Co. KG">
|
||||
<input name="additionalAddressLineOne" value="">
|
||||
<input name="additionalAddressLineTwo" value="">
|
||||
<input name="addressStreet" value="Postfach 810551">
|
||||
<input name="addressPostalcode" value="30505">
|
||||
<input name="addressCity" value="Hannover">
|
||||
<select name="addressCountryISO3166">
|
||||
<option value="DE" selected>Deutschland</option>
|
||||
</select>
|
||||
<textarea name="notiz">Zeile 1</textarea>
|
||||
<button type="submit" name="speichern">Speichern</button>
|
||||
</form>
|
||||
<script>admin.Eingangsrechnungen.editRechnung(388444);</script>
|
||||
`;
|
||||
|
||||
function createServer({ updateResponse = [] } = {}) {
|
||||
const requests = [];
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
let body = '';
|
||||
req.on('data', chunk => {
|
||||
body += chunk;
|
||||
});
|
||||
req.on('end', () => {
|
||||
requests.push({ method: req.method, url: req.url, headers: req.headers, body });
|
||||
|
||||
if (req.method === 'POST' && req.url === '/login/api/login.php') {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json',
|
||||
'Set-Cookie': 'agrar_session=test; Path=/',
|
||||
});
|
||||
res.end(JSON.stringify({ success: true }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && req.url === '/') {
|
||||
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
||||
res.end('<html><body>Mein AM</body></html>');
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && req.url === '/module/eingangsrechnungen/api/editForm.php?invoiceID=388444') {
|
||||
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
||||
res.end(editForm);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === 'POST' && req.url === '/module/eingangsrechnungen/api/update.php') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify(updateResponse));
|
||||
return;
|
||||
}
|
||||
|
||||
res.writeHead(404);
|
||||
res.end('not found');
|
||||
});
|
||||
});
|
||||
|
||||
return { server, requests };
|
||||
}
|
||||
|
||||
async function startConnector(t, options) {
|
||||
const { server, requests } = createServer(options);
|
||||
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
t.after(() => new Promise(resolve => server.close(resolve)));
|
||||
|
||||
const connector = new AgrarmonitorConnector({
|
||||
baseUrl: `http://127.0.0.1:${server.address().port}`,
|
||||
username: 'demo',
|
||||
password: 'secret',
|
||||
cookieStore: new MemoryCookieStore(),
|
||||
});
|
||||
await connector.init();
|
||||
|
||||
return { connector, requests };
|
||||
}
|
||||
|
||||
test('getRechnungsdaten liest das Formular aus editForm.php', async t => {
|
||||
const { connector } = await startConnector(t);
|
||||
|
||||
const daten = await connector.getRechnungsdaten(388444);
|
||||
|
||||
assert.equal(daten.lieferschein, '');
|
||||
assert.equal(daten.rechnung, '5355771416');
|
||||
assert.equal(daten.kundenId, 34079);
|
||||
assert.equal(daten.adresstext, 'TUEV NORD Mobilitaet GmbH & Co. KG');
|
||||
assert.equal(daten.datum.getFullYear(), 2026);
|
||||
assert.equal(daten.datum.getMonth(), 7);
|
||||
assert.equal(daten.datum.getDate(), 19);
|
||||
});
|
||||
|
||||
test('setLieferscheinNummer schickt das komplette Formular als JSON an update.php', async t => {
|
||||
const { connector, requests } = await startConnector(t);
|
||||
|
||||
await connector.setLieferscheinNummer(388444, '2026-001107');
|
||||
|
||||
const update = requests.find(request => request.url === '/module/eingangsrechnungen/api/update.php');
|
||||
assert.ok(update, 'update.php wurde nicht aufgerufen');
|
||||
assert.equal(update.method, 'POST');
|
||||
assert.match(update.headers['content-type'], /^application\/json/);
|
||||
assert.deepEqual(JSON.parse(update.body), {
|
||||
rechnungID: 388444,
|
||||
formData: {
|
||||
typ: '0',
|
||||
mengenUndPreisAnpassung: '0',
|
||||
lieferscheinnummer: '2026-001107',
|
||||
rechnungsnummer: '5355771416',
|
||||
rechnungsdatum: '19.08.26',
|
||||
firma_id: '3',
|
||||
rgempf: '34079',
|
||||
addressName: 'TUEV NORD Mobilitaet GmbH & Co. KG',
|
||||
additionalAddressLineOne: '',
|
||||
additionalAddressLineTwo: '',
|
||||
addressStreet: 'Postfach 810551',
|
||||
addressPostalcode: '30505',
|
||||
addressCity: 'Hannover',
|
||||
addressCountryISO3166: 'DE',
|
||||
notiz: 'Zeile 1',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('setRechnungsdaten meldet die Fehlermeldung aus update.php', async t => {
|
||||
const { connector } = await startConnector(t, { updateResponse: { msg: 'Rechnung ist gesperrt' } });
|
||||
|
||||
await assert.rejects(
|
||||
connector.setLieferscheinNummer(388444, '2026-001107'),
|
||||
/Rechnung ist gesperrt/
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user