Skip to content

Commit

Permalink
chore: robust recovery info fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdethier committed Jun 11, 2024
1 parent 67a4e99 commit b6e9531
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/logion/controllers/account_recovery.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { LocRequestAdapter, UserPrivateData } from "./adapters/locrequestadapter
import { LocRequestRepository } from '../model/locrequest.model.js';
import { ValidAccountId } from "@logion/node-api";
import { LegalOfficerDecisionDescription } from '../model/decision.js';
import { EMPTY_POSTAL_ADDRESS } from '../model/postaladdress.js';
import { EMPTY_USER_IDENTITY } from '../model/useridentity.js';

type CreateAccountRecoveryRequestView = components["schemas"]["CreateAccountRecoveryRequestView"];
type AccountRecoveryRequestView = components["schemas"]["AccountRecoveryRequestView"];
Expand Down Expand Up @@ -257,8 +259,8 @@ export class AccountRecoveryController extends ApiController {
if(identity1Loc) {
const description = identity1Loc.getDescription();
identity1 = {
userIdentity: description.userIdentity,
userPostalAddress: description.userPostalAddress,
userIdentity: description.userIdentity || EMPTY_USER_IDENTITY,
userPostalAddress: description.userPostalAddress || EMPTY_POSTAL_ADDRESS,
};
}
const identity2PrivateData = await this.locRequestAdapter.getUserPrivateData(accountRecoveryRequest.requesterIdentityLocId!);
Expand Down
6 changes: 4 additions & 2 deletions src/logion/controllers/secret_recovery.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { LocalsObject } from "pug";
import { DirectoryService } from "../services/directory.service.js";
import { UUID, ValidAccountId } from "@logion/node-api";
import { LegalOfficerDecisionDescription } from "../model/decision.js";
import { EMPTY_POSTAL_ADDRESS } from "../model/postaladdress.js";
import { EMPTY_USER_IDENTITY } from "../model/useridentity.js";

type CreateSecretRecoveryRequestView = components["schemas"]["CreateSecretRecoveryRequestView"];
type RecoveryInfoView = components["schemas"]["RecoveryInfoView"];
Expand Down Expand Up @@ -178,8 +180,8 @@ export class SecretRecoveryController extends ApiController {
if(identity1Loc && identity1Loc.getOwner().equals(authenticatedUser.validAccountId)) {
const description = identity1Loc.getDescription();
identity1 = {
userIdentity: description.userIdentity,
userPostalAddress: description.userPostalAddress,
userIdentity: description.userIdentity || EMPTY_USER_IDENTITY,
userPostalAddress: description.userPostalAddress || EMPTY_POSTAL_ADDRESS,
};
}
return {
Expand Down
8 changes: 8 additions & 0 deletions src/logion/model/postaladdress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ export function toPostalAddress(embedded: EmbeddablePostalAddress | undefined):
}
: undefined;
}

export const EMPTY_POSTAL_ADDRESS: PostalAddress = {
city: "",
country: "",
line1: "",
line2: "",
postalCode: "",
}
7 changes: 7 additions & 0 deletions src/logion/model/useridentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ export function toUserIdentity(embedded: EmbeddableUserIdentity | undefined): Us
}
: undefined;
}

export const EMPTY_USER_IDENTITY: UserIdentity = {
email: "",
firstName: "",
lastName: "",
phoneNumber: "",
};
10 changes: 0 additions & 10 deletions test/unit/model/locrequest.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2437,16 +2437,6 @@ function expectSameLinks(item1: LinkDescription, item2: Partial<LinkDescription>
}
}

function thenHasLink(name: string) {
expect(request.hasLink(name)).toBeTrue();
}

function thenHasExpectedLinkIndices() {
for(let i = 0; i < request.links!.length; ++i) {
expect(request.links![i].index).toBe(i);
}
}

function whenPreClosing() {
request.preClose(false);
}
Expand Down

0 comments on commit b6e9531

Please sign in to comment.