forked from jsnbuchanan/crowd-funder-for-time-pwa
Migrate test/index.ts to use dynamic database imports
Replace static databaseUtil import with dynamic import pattern for test context. Add comprehensive JSDoc documentation and improve code formatting. Maintains functionality while removing static dependency.
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import axios from "axios";
|
||||
import * as didJwt from "did-jwt";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { SERVICE_ID } from "../libs/endorserServer";
|
||||
import { deriveAddress, newIdentifier } from "../libs/crypto";
|
||||
import { logger } from "../utils/logger";
|
||||
import { AppString } from "../constants/app";
|
||||
|
||||
/**
|
||||
* Get User #0 to sign & submit a RegisterAction for the user's activeDid.
|
||||
*
|
||||
* This test function demonstrates the registration process for a user with the endorser server.
|
||||
* It creates a verifiable credential claim and submits it via JWT to the endorser API.
|
||||
*
|
||||
* @returns Promise<void> - Completes when registration is successful
|
||||
* @throws Error if registration fails or database access fails
|
||||
*/
|
||||
export async function testServerRegisterUser() {
|
||||
const testUser0Mnem =
|
||||
@@ -16,7 +22,11 @@ export async function testServerRegisterUser() {
|
||||
|
||||
const identity0 = newIdentifier(addr, publicHex, privateHex, deriPath);
|
||||
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
// Use dynamic import for database access in test context
|
||||
const { retrieveSettingsForActiveAccount } = await import(
|
||||
"@/db/databaseUtil"
|
||||
);
|
||||
const settings = await retrieveSettingsForActiveAccount();
|
||||
|
||||
// Make a claim
|
||||
const vcClaim = {
|
||||
@@ -26,6 +36,7 @@ export async function testServerRegisterUser() {
|
||||
object: SERVICE_ID,
|
||||
participant: { did: settings.activeDid },
|
||||
};
|
||||
|
||||
// Make a payload for the claim
|
||||
const vcPayload = {
|
||||
sub: "RegisterAction",
|
||||
@@ -35,11 +46,13 @@ export async function testServerRegisterUser() {
|
||||
credentialSubject: vcClaim,
|
||||
},
|
||||
};
|
||||
|
||||
// create a signature using private key of identity
|
||||
// eslint-disable-next-line
|
||||
const privateKeyHex: string = identity0.keys[0].privateKeyHex!;
|
||||
const signer = await didJwt.SimpleSigner(privateKeyHex);
|
||||
const alg = undefined;
|
||||
|
||||
// create a JWT for the request
|
||||
const vcJwt: string = await didJwt.createJWT(vcPayload, {
|
||||
alg: alg,
|
||||
@@ -48,7 +61,6 @@ export async function testServerRegisterUser() {
|
||||
});
|
||||
|
||||
// Make the xhr request payload
|
||||
|
||||
const payload = JSON.stringify({ jwtEncoded: vcJwt });
|
||||
const endorserApiServer =
|
||||
settings.apiServer || AppString.TEST_ENDORSER_API_SERVER;
|
||||
|
||||
Reference in New Issue
Block a user