Libeufin Tests.

Testing refunds due to invalid subject.  Up to the
point where the list of transactions is returned by
the local bank account.
This commit is contained in:
MS 2021-04-29 11:19:17 +02:00
parent faf83181de
commit 9928d2ef35
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
2 changed files with 57 additions and 6 deletions

View File

@ -39,8 +39,8 @@ export interface LibeufinNexusServiceInterface {
} }
export interface LibeufinServices { export interface LibeufinServices {
libeufinSandbox: LibeufinSandboxServiceInterface; libeufinSandbox: LibeufinSandboxService;
libeufinNexus: LibeufinNexusServiceInterface; libeufinNexus: LibeufinNexusService;
commonDb: DbInfo; commonDb: DbInfo;
} }
@ -279,7 +279,7 @@ export interface SimulateIncomingTransactionRequest {
/** /**
* The bundle aims at minimizing the amount of input * The bundle aims at minimizing the amount of input
* data that is required to initialize a new user + Ebics * data that is required to initialize a new user + Ebics
* connection thereof. * connection.
*/ */
export class NexusUserBundle { export class NexusUserBundle {
userReq: CreateNexusUserRequest; userReq: CreateNexusUserRequest;
@ -651,7 +651,7 @@ export namespace LibeufinSandboxApi {
} }
export async function bookPayment( export async function bookPayment(
libeufinSandboxService: LibeufinSandboxServiceInterface, libeufinSandboxService: LibeufinSandboxService,
creditorBundle: SandboxUserBundle, creditorBundle: SandboxUserBundle,
debitorBundle: SandboxUserBundle, debitorBundle: SandboxUserBundle,
subject: string, subject: string,
@ -849,9 +849,34 @@ export namespace LibeufinNexusApi {
); );
} }
export async function getAccountTransactions(
libeufinNexusService: LibeufinNexusService,
accountName: string,
username: string = "admin",
password: string = "test",
): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(
`/bank-accounts/${accountName}/transactions`,
baseUrl,
);
await axios.get(
url.href,
{
auth: {
username: username,
password: password,
},
},
);
}
export async function fetchAllTransactions( export async function fetchAllTransactions(
libeufinNexusService: LibeufinNexusService, libeufinNexusService: LibeufinNexusService,
accountName: string, accountName: string,
username: string = "admin",
password: string = "test",
): Promise<void> { ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl; const baseUrl = libeufinNexusService.baseUrl;
let url = new URL( let url = new URL(
@ -866,8 +891,8 @@ export namespace LibeufinNexusApi {
}, },
{ {
auth: { auth: {
username: "admin", username: username,
password: "test", password: password,
}, },
}, },
); );

View File

@ -23,6 +23,7 @@ import {
NexusUserBundle, NexusUserBundle,
launchLibeufinServices, launchLibeufinServices,
LibeufinSandboxApi, LibeufinSandboxApi,
LibeufinNexusApi,
} from "./libeufin"; } from "./libeufin";
/** /**
@ -46,6 +47,10 @@ export async function runLibeufinRefundTest(t: GlobalTestState) {
[user01sandbox, user02sandbox], [user01sandbox, user02sandbox],
); );
// user02 - acting as the Exchange - gets money from user01,
// but this one gets the subject wrong - not a valid public key.
// The result should be a reimbursement - minus a small fee - of
// the paid money to user01.
await LibeufinSandboxApi.bookPayment( await LibeufinSandboxApi.bookPayment(
libeufinServices.libeufinSandbox, libeufinServices.libeufinSandbox,
user02sandbox, user02sandbox,
@ -54,4 +59,25 @@ export async function runLibeufinRefundTest(t: GlobalTestState) {
"1", "1",
"EUR", "EUR",
); );
// STEPS.
// 1. Exchange must import this payment into its Nexus / Facade.
// 2. Facade logic should process incoming payments.
// 3. A reimbursement should be prepared.
// 4. The reimbursement payment should be sent.
// Steps 1-3 should happen all-at-once when triggering the import
// logic. 4 needs to be explicitly triggered (because here there's
// no background task activated, yet?)
await LibeufinNexusApi.fetchAllTransactions(
libeufinServices.libeufinNexus,
user02nexus.localAccountName,
);
await LibeufinNexusApi.getAccountTransactions(
libeufinServices.libeufinNexus,
user02nexus.localAccountName,
);
} }