Skip to content

Commit

Permalink
feat: prevent Logion Identity LOC creation if identity fields are mis…
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdevos committed Dec 23, 2021
1 parent bb0e608 commit 0c28de5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/logion/model/locrequest.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ export class LocRequestFactory {
public newLocRequest(params: NewLocRequestParameters): LocRequestAggregateRoot {
const { description } = params;
this.ensureCorrectRequester(description)
this.ensureUserIdentityPresent(description)
const request = new LocRequestAggregateRoot();
request.id = params.id;
request.status = "REQUESTED";
Expand Down Expand Up @@ -737,4 +738,18 @@ export class LocRequestFactory {
}
}
}

private ensureUserIdentityPresent(description: LocRequestDescription) {
if (description.locType === 'Identity' && !description.requesterAddress) {
const userIdentity = description.userIdentity;
if (!userIdentity
|| !userIdentity.firstName
|| !userIdentity.lastName
|| !userIdentity.email
|| !userIdentity.phoneNumber
) {
throw new Error("Logion Identity LOC request must contain first name, last name, email and phone number.")
}
}
}
}
20 changes: 17 additions & 3 deletions test/unit/model/locrequest.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
VoidInfo,
LocType
} from "../../../src/logion/model/locrequest.model";
import { UserIdentity } from "../../../src/logion/model/useridentity";

describe("LocRequestFactory", () => {

Expand Down Expand Up @@ -85,19 +86,32 @@ describe("LocRequestFactory", () => {

it("creates an open Identity LOC with no requester", () => {
givenRequestId(uuid());
const description = createDescription('Identity');
const userIdentity = {
firstName: "Scott",
lastName: "Tiger",
email: "[email protected]",
phoneNumber: "+789"
};
const description = createDescription('Identity', undefined, undefined, userIdentity);
givenLocDescription(description);
whenCreatingOpenLoc();
});

function createDescription(locType: LocType, requesterAddress?: string, requesterIdentityLoc?: string): LocRequestDescription {
it("fails to create an open Identity LOC with no requester when identity is missing", () => {
givenRequestId(uuid());
const description = createDescription('Identity');
givenLocDescription(description);
expect(() => whenCreatingOpenLoc()).toThrowError();
});

function createDescription(locType: LocType, requesterAddress?: string, requesterIdentityLoc?: string, userIdentity?: UserIdentity): LocRequestDescription {
return {
requesterAddress,
requesterIdentityLoc,
ownerAddress: ALICE,
description: "Mrs ALice, I want to sell my last art work",
createdOn: moment().toISOString(),
userIdentity: undefined,
userIdentity,
locType
};
}
Expand Down

0 comments on commit 0c28de5

Please sign in to comment.