60 lines
3.1 KiB
JavaScript
60 lines
3.1 KiB
JavaScript
// Generated, do not edit. sha256:2e4d24591409f9e23b4c9506d97e49fbede02ae3761449cb3964ef0391f78258
|
|||
|
|
import { describe, it, mock, beforeEach } from 'node:test';
|
||
|
|
import assert from 'node:assert/strict';
|
||
|
|
|
||
|
|
const dienst = { gevraagd: [] };
|
||
|
|
mock.module('../../server/market-service.mjs', {
|
||
|
|
namedExports: {
|
||
|
|
marketServiceUrl: async () => 'https://services.example',
|
||
|
|
marketSupportMessages: async (header) => { dienst.gevraagd.push(['lees', header]); return [{ from: 'seller', text: 'hoi' }]; },
|
||
|
|
marketSupportSend: async (header, body) => { dienst.gevraagd.push(['stuur', header, body]); return { from: 'buyer', text: 'vraag' }; },
|
||
|
|
marketSupportAttachment: async (header, id) => { dienst.gevraagd.push(['bijlage', header, id]); return { mime: 'image/png', data: 'iVBO' }; },
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
const { CONFIG } = await import('../../shared/config.js');
|
||
|
|
const { supportInfo, supportMessages, sendSupport, supportAttachment } = await import('../../server/data/support.js');
|
||
|
|
|
||
|
|
const NOSTR = 'Nostr eyJ0ZXN0Ijp0cnVlfQ==';
|
||
|
|
beforeEach(() => { dienst.gevraagd = []; });
|
||
|
|
|
||
|
|
describe('support: wat de pagina weet', () => {
|
||
|
|
it('geeft het adres om voor te tekenen, de grenzen en het supportaccount op nostr', async () => {
|
||
|
|
const info = await supportInfo();
|
||
|
|
assert.equal(info.serviceUrl, 'https://services.example');
|
||
|
|
assert.equal(info.maxText, CONFIG.LICENSE.SUPPORT.MAX_TEXT);
|
||
|
|
assert.equal(info.maxAttachmentBytes, 2 * 1024 * 1024);
|
||
|
|
assert.deepEqual(info.attachmentTypes, ['image/png', 'image/jpeg', 'image/webp']);
|
||
|
|
assert.equal(info.nostr.pubkey, CONFIG.LICENSE.SUPPORT.RECIPIENT);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('support: doorgeven aan de dienst', () => {
|
||
|
|
it('geeft de handtekening en de body ongewijzigd door', async () => {
|
||
|
|
const body = '{"text":"vraag","attachment":{"type":"image/png","data":"iVBO"}}';
|
||
|
|
assert.deepEqual(await supportMessages(NOSTR), [{ from: 'seller', text: 'hoi' }]);
|
||
|
|
assert.deepEqual(await sendSupport(NOSTR, body), { from: 'buyer', text: 'vraag' });
|
||
|
|
assert.deepEqual(await supportAttachment(NOSTR, 'a'.repeat(32)), { mime: 'image/png', data: 'iVBO' });
|
||
|
|
assert.deepEqual(dienst.gevraagd, [['lees', NOSTR], ['stuur', NOSTR, body], ['bijlage', NOSTR, 'a'.repeat(32)]]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('weigert iets anders dan een NIP-98-header, zonder de dienst te vragen', async () => {
|
||
|
|
for (const fout of [null, '', 'Bearer abc', 'Order ' + 'b'.repeat(64), 'Nostr niet base64!']) {
|
||
|
|
await assert.rejects(supportMessages(fout), /Authorization: Nostr/);
|
||
|
|
await assert.rejects(sendSupport(fout, '{}'), /Authorization: Nostr/);
|
||
|
|
}
|
||
|
|
assert.deepEqual(dienst.gevraagd, []);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('weigert een body die geen tekst is: dan is er niets getekend', async () => {
|
||
|
|
await assert.rejects(sendSupport(NOSTR, { text: 'vraag' }), /signed JSON text/);
|
||
|
|
assert.deepEqual(dienst.gevraagd, []);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('weigert een bijlage-id die geen 32 hex is, zodat er geen pad uit invoer ontstaat', async () => {
|
||
|
|
for (const fout of ['../health', 'A'.repeat(32), 'a'.repeat(31), null]) {
|
||
|
|
await assert.rejects(supportAttachment(NOSTR, fout), /32 hex/);
|
||
|
|
}
|
||
|
|
assert.deepEqual(dienst.gevraagd, []);
|
||
|
|
});
|
||
|
|
});
|