Browse Source

fix: On test page, switch back to the current user (and not User 0).

master
Trent Larson 1 day ago
parent
commit
270e7ec8eb
  1. 4
      src/libs/util.ts
  2. 4
      src/services/PlatformService.ts
  3. 2
      src/services/platforms/CapacitorPlatformService.ts
  4. 2
      src/services/platforms/WebPlatformService.ts
  5. 13
      src/test/index.ts

4
src/libs/util.ts

@ -657,7 +657,7 @@ export async function saveNewIdentity(
await platformService.updateDefaultSettings({ activeDid: identity.did });
await platformService.insertDidSpecificSettings(identity.did);
await platformService.insertNewDidIntoSettings(identity.did);
} catch (error) {
logger.error("Failed to update default settings:", error);
throw new Error(
@ -954,7 +954,7 @@ export async function importFromMnemonic(
try {
// First, ensure the DID-specific settings record exists
await platformService.insertDidSpecificSettings(newId.did);
await platformService.insertNewDidIntoSettings(newId.did);
// Then update with Test User #0 specific settings
await platformService.updateDidSpecificSettings(newId.did, {

4
src/services/PlatformService.ts

@ -175,11 +175,11 @@ export interface PlatformService {
updateDefaultSettings(settings: Record<string, unknown>): Promise<void>;
/**
* Inserts DID-specific settings into the database.
* Inserts a new DID into the settings table.
* @param did - The DID to associate with the settings
* @returns Promise that resolves when the insertion is complete
*/
insertDidSpecificSettings(did: string): Promise<void>;
insertNewDidIntoSettings(did: string): Promise<void>;
/**
* Updates DID-specific settings in the database.

2
src/services/platforms/CapacitorPlatformService.ts

@ -1319,7 +1319,7 @@ export class CapacitorPlatformService implements PlatformService {
await this.dbExec(sql, params);
}
async insertDidSpecificSettings(did: string): Promise<void> {
async insertNewDidIntoSettings(did: string): Promise<void> {
await this.dbExec("INSERT INTO settings (accountDid) VALUES (?)", [did]);
}

2
src/services/platforms/WebPlatformService.ts

@ -681,7 +681,7 @@ export class WebPlatformService implements PlatformService {
await this.dbExec(sql, params);
}
async insertDidSpecificSettings(did: string): Promise<void> {
async insertNewDidIntoSettings(did: string): Promise<void> {
await this.dbExec("INSERT INTO settings (accountDid) VALUES (?)", [did]);
}

13
src/test/index.ts

@ -50,6 +50,10 @@ export async function testServerRegisterUser() {
"@/db/databaseUtil"
);
const settings = await retrieveSettingsForActiveAccount();
const currentDid = settings?.activeDid;
if (!currentDid) {
throw new Error("No active DID found");
}
// Make a claim
const vcClaim = {
@ -57,7 +61,7 @@ export async function testServerRegisterUser() {
"@type": "RegisterAction",
agent: { identifier: identity0.did },
object: SERVICE_ID,
participant: { identifier: settings.activeDid },
participant: { identifier: currentDid },
};
// Make a payload for the claim
@ -94,5 +98,12 @@ export async function testServerRegisterUser() {
const resp = await axios.post(url, payload, { headers });
logger.log("User registration result:", resp);
const platformService = await PlatformServiceFactory.getInstance();
await platformService.updateDefaultSettings({ activeDid: currentDid });
await platformService.updateDidSpecificSettings(currentDid!, {
isRegistered: true,
});
return resp;
}

Loading…
Cancel
Save