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:
@@ -50,8 +50,9 @@ import {
|
||||
routeSchema,
|
||||
DeepLinkRoute,
|
||||
} from "../interfaces/deepLinks";
|
||||
import { logConsoleAndDb } from "../db/databaseUtil";
|
||||
// Legacy databaseUtil import removed - using logger instead
|
||||
import type { DeepLinkError } from "../interfaces/deepLinks";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
/**
|
||||
* Handles processing and routing of deep links in the application.
|
||||
@@ -173,7 +174,7 @@ export class DeepLinkHandler {
|
||||
routeName = this.ROUTE_MAP[validRoute].name;
|
||||
} catch (error) {
|
||||
// Log the invalid route attempt
|
||||
logConsoleAndDb(`[DeepLink] Invalid route path: ${path}`, true);
|
||||
logger.error(`[DeepLink] Invalid route path: ${path}`);
|
||||
|
||||
// Redirect to error page with information about the invalid link
|
||||
await this.router.replace({
|
||||
@@ -235,7 +236,7 @@ export class DeepLinkHandler {
|
||||
*/
|
||||
async handleDeepLink(url: string): Promise<void> {
|
||||
try {
|
||||
logConsoleAndDb("[DeepLink] Processing URL: " + url, false);
|
||||
logger.info("[DeepLink] Processing URL: " + url);
|
||||
const { path, params, query } = this.parseDeepLink(url);
|
||||
// Ensure params is always a Record<string,string> by converting undefined to empty string
|
||||
const sanitizedParams = Object.fromEntries(
|
||||
@@ -244,9 +245,8 @@ export class DeepLinkHandler {
|
||||
await this.validateAndRoute(path, sanitizedParams, query);
|
||||
} catch (error) {
|
||||
const deepLinkError = error as DeepLinkError;
|
||||
logConsoleAndDb(
|
||||
logger.error(
|
||||
`[DeepLink] Error (${deepLinkError.code}): ${deepLinkError.message}`,
|
||||
true,
|
||||
);
|
||||
|
||||
throw {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1423,7 +1423,7 @@ export default class AccountViewView extends Vue {
|
||||
} catch (error) {
|
||||
this.limitsMessage =
|
||||
ACCOUNT_VIEW_CONSTANTS.LIMITS.ERROR_RETRIEVING_LIMITS;
|
||||
this.notify.error(ACCOUNT_VIEW_CONSTANTS.LIMITS.ERROR_RETRIEVING_LIMITS);
|
||||
this.notify.error(this.limitsMessage, TIMEOUTS.STANDARD);
|
||||
} finally {
|
||||
this.loadingLimits = false;
|
||||
}
|
||||
|
||||
@@ -365,8 +365,6 @@ import TopMessage from "../components/TopMessage.vue";
|
||||
import { APP_SERVER, AppString, NotificationIface } from "../constants/app";
|
||||
import { logConsoleAndDb } from "../db/index";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
// No longer needed - using PlatformServiceMixin methods
|
||||
// import * as databaseUtil from "../db/databaseUtil";
|
||||
import { getContactJwtFromJwtUrl } from "../libs/crypto";
|
||||
import { decodeEndorserJwt } from "../libs/crypto/vc";
|
||||
import {
|
||||
@@ -475,7 +473,6 @@ export default class ContactsView extends Vue {
|
||||
public async created() {
|
||||
this.notify = createNotifyHelpers(this.$notify);
|
||||
|
||||
// Replace databaseUtil.retrieveSettingsForActiveAccount() with mixin method
|
||||
const settings = await this.$accountSettings();
|
||||
this.activeDid = settings.activeDid || "";
|
||||
this.apiServer = settings.apiServer || "";
|
||||
@@ -544,7 +541,6 @@ export default class ContactsView extends Vue {
|
||||
if (response.status != 201) {
|
||||
throw { error: { response: response } };
|
||||
}
|
||||
// Replace databaseUtil.updateDidSpecificSettings with mixin method
|
||||
await this.$saveUserSettings(this.activeDid, { isRegistered: true });
|
||||
this.isRegistered = true;
|
||||
this.notify.success(NOTIFY_INVITE_REGISTRATION_SUCCESS.message);
|
||||
@@ -900,7 +896,6 @@ export default class ContactsView extends Vue {
|
||||
text: "Do you want to register them?",
|
||||
onCancel: async (stopAsking?: boolean) => {
|
||||
if (stopAsking) {
|
||||
// Replace databaseUtil.updateDefaultSettings with mixin method
|
||||
await this.$saveSettings({
|
||||
hideRegisterPromptOnNewContact: stopAsking,
|
||||
});
|
||||
@@ -909,7 +904,6 @@ export default class ContactsView extends Vue {
|
||||
},
|
||||
onNo: async (stopAsking?: boolean) => {
|
||||
if (stopAsking) {
|
||||
// Replace databaseUtil.updateDefaultSettings with mixin method
|
||||
await this.$saveSettings({
|
||||
hideRegisterPromptOnNewContact: stopAsking,
|
||||
});
|
||||
@@ -1128,7 +1122,6 @@ export default class ContactsView extends Vue {
|
||||
private async toggleShowContactAmounts() {
|
||||
const newShowValue = !this.showGiveNumbers;
|
||||
try {
|
||||
// Replace databaseUtil.updateDefaultSettings with mixin method
|
||||
await this.$saveSettings({
|
||||
showContactGivesInline: newShowValue,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user