Skip to content

Commit

Permalink
IMN-221 Agreement Submit test (#603)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Camellini <[email protected]>
  • Loading branch information
Viktor-K and ecamellini authored Jun 12, 2024
1 parent ec7deae commit 7a5ba15
Show file tree
Hide file tree
Showing 4 changed files with 2,164 additions and 14 deletions.
17 changes: 11 additions & 6 deletions packages/agreement-process/src/services/agreementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,12 @@ export function agreementServiceBuilder(
readModelService
);

await validateConsumerEmail(agreement.data, readModelService);
const consumer = await retrieveTenant(
agreement.data.consumerId,
readModelService
);

await validateConsumerEmail(consumer, agreement.data);

const eservice = await retrieveEService(
agreement.data.eserviceId,
Expand All @@ -392,11 +397,6 @@ export function agreementServiceBuilder(
agreement.data.descriptorId
);

const consumer = await retrieveTenant(
agreement.data.consumerId,
readModelService
);

const producer = await retrieveTenant(
agreement.data.producerId,
readModelService
Expand Down Expand Up @@ -503,6 +503,11 @@ export function agreementServiceBuilder(
);

const archivedAgreementsUpdates: Array<CreateEvent<AgreementEvent>> =
/*
This condition can only check if state is ACTIVE
at this point the SUSPENDED state is not available
after validateActiveOrPendingAgreement validation
*/
isActiveOrSuspended(submittedAgreement.state)
? agreements.map((agreement) =>
createAgreementArchivedByUpgradeEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import {
matchingVerifiedAttributes,
} from "../model/domain/validators.js";
import { ApiAgreementSubmissionPayload } from "../model/types.js";
import { retrieveTenant } from "./agreementService.js";
import { createStamp } from "./agreementStampUtils.js";
import { ReadModelService } from "./readModelService.js";

export type AgremeentSubmissionResults = {
events: Array<CreateEvent<AgreementEvent>>;
Expand All @@ -36,11 +34,9 @@ export type AgremeentSubmissionResults = {
};

export const validateConsumerEmail = async (
agreement: Agreement,
readModelService: ReadModelService
consumer: Tenant,
agreement: Agreement
): Promise<void> => {
const consumer = await retrieveTenant(agreement.consumerId, readModelService);

const hasContactEmail = consumer.mails.some(
(mail) => mail.kind === tenantMailKind.ContactEmail
);
Expand Down
Loading

0 comments on commit 7a5ba15

Please sign in to comment.