taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 2a452cf295fb2f9368ef9ea76be72ca6c371fc1e
parent ea6ae2d92ea6a8cc13f1cdc8f25a13dc402f4cd6
Author: Florian Dold <dold@taler.net>
Date:   Tue, 21 Jul 2026 03:05:04 +0200

util: test that preparing a donau receipt accepts 201 Created

Diffstat:
Apackages/taler-util/src/http-client/donau-client.test.ts | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+), 0 deletions(-)

diff --git a/packages/taler-util/src/http-client/donau-client.test.ts b/packages/taler-util/src/http-client/donau-client.test.ts @@ -0,0 +1,59 @@ +/* + This file is part of GNU Taler + (C) 2024 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import { test } from "node:test"; +import assert from "node:assert"; +import { + HeadersImpl, + HttpRequestLibrary, + HttpRequestOptions, + HttpResponse, +} from "../http-common.js"; +import { isOperationOk } from "../operation.js"; +import { DonauHttpClient } from "./donau-client.js"; + +function fixedStatusLib(status: number, body: unknown): HttpRequestLibrary { + return { + async fetch( + url: string, + opt?: HttpRequestOptions, + ): Promise<HttpResponse> { + return { + requestUrl: url, + requestMethod: opt?.method ?? "GET", + status, + headers: new HeadersImpl(), + async json() { + return body; + }, + async text() { + return JSON.stringify(body); + }, + async bytes() { + return new Uint8Array(); + }, + }; + }, + }; +} + +test("prepareIssueReceipt treats 201 Created as success", async (t) => { + const client = new DonauHttpClient("https://donau.example.com/", { + httpClient: fixedStatusLib(201, { cipher: "CS" }), + }); + const res = await client.prepareIssueReceipt({} as any); + assert.ok(isOperationOk(res), `expected success, got case ${(res as any).case}`); +});