Skip to content

Commit

Permalink
Descriptor approval rejection event models (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carminepo2 authored Oct 16, 2024
1 parent 8a48222 commit a520391
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pagopa/interop-outbound-models",
"version": "1.0.6",
"version": "1.0.7",
"description": "PagoPA Interoperability outbound models",
"main": "dist",
"type": "module",
Expand Down
7 changes: 7 additions & 0 deletions proto/v2/eservice/eservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ message EServiceAttributesV2 {
repeated EServiceAttributeV2 verified = 3;
}

message DescriptorRejectionReasonV2 {
string rejectionReason = 1;
int64 rejectedAt = 2;
}

message EServiceDescriptorV2 {
string id = 1;
int64 version = 2;
Expand All @@ -47,6 +52,7 @@ message EServiceDescriptorV2 {
optional int64 deprecatedAt = 16;
optional int64 archivedAt = 17;
EServiceAttributesV2 attributes = 18;
repeated DescriptorRejectionReasonV2 rejectedReasons = 19;
}

message EServiceDocumentV2 {
Expand All @@ -64,6 +70,7 @@ enum EServiceDescriptorStateV2 {
DEPRECATED = 2;
SUSPENDED = 3;
ARCHIVED = 4;
WAITING_FOR_APPROVAL = 5;
}

enum EServiceTechnologyV2 {
Expand Down
10 changes: 10 additions & 0 deletions proto/v2/eservice/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ message EServiceDescriptorDocumentDeletedV2 {
message EServiceDescriptionUpdatedV2 {
EServiceV2 eservice = 1;
}

message EServiceDescriptorApprovedV2 {
string descriptorId = 1;
EServiceV2 eservice = 2;
}

message EServiceDescriptorRejectedV2 {
string descriptorId = 1;
EServiceV2 eservice = 2;
}
24 changes: 24 additions & 0 deletions src/eservice/eventsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
EServiceDraftDescriptorUpdatedV2,
EServiceDescriptorQuotasUpdatedV2,
EServiceDescriptionUpdatedV2,
EServiceDescriptorApprovedV2,
EServiceDescriptorRejectedV2,
} from "../gen/v2/eservice/events.js";

export function eServiceEventToBinaryDataV2(
Expand Down Expand Up @@ -84,6 +86,12 @@ export function eServiceEventToBinaryDataV2(
.with({ type: "EServiceDescriptionUpdated" }, ({ data }) =>
EServiceDescriptionUpdatedV2.toBinary(data)
)
.with({ type: "EServiceDescriptorApproved" }, ({ data }) =>
EServiceDescriptorApprovedV2.toBinary(data)
)
.with({ type: "EServiceDescriptorRejected" }, ({ data }) =>
EServiceDescriptorRejectedV2.toBinary(data)
)
.exhaustive();
}

Expand Down Expand Up @@ -240,6 +248,22 @@ export const EServiceEventV2 = z.discriminatedUnion("type", [
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("EServiceDescriptorApproved"),
data: protobufDecoder(EServiceDescriptorApprovedV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("EServiceDescriptorRejected"),
data: protobufDecoder(EServiceDescriptorRejectedV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
]);

export type EServiceEventV2 = z.infer<typeof EServiceEventV2>;
42 changes: 38 additions & 4 deletions tests/eservice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,49 @@ import {
encodeOutboundEServiceEvent,
decodeOutboundEServiceEvent,
EServiceEvent,
EServiceModeV2,
EServiceTechnologyV2,
EServiceDescriptorStateV2,
AgreementApprovalPolicyV2,
} from "../src/index.js";

describe("eservice", () => {
it("should correctly encode and decode EServiceDeleted event", () => {
it("should correctly encode and decode EServiceDescriptorArchived event", () => {
const event: EServiceEvent = {
event_version: 1,
type: "EServiceDeleted",
event_version: 2,
type: "EServiceDescriptorArchived",
data: {
eserviceId: "123",
descriptorId: "testtea",
eservice: {
id: "test",
createdAt: 1n,
producerId: "test",
mode: EServiceModeV2.DELIVER,
description: "testtest",
name: "test",
technology: EServiceTechnologyV2.REST,
descriptors: [
{
id: "id",
version: 1n,
docs: [],
state: EServiceDescriptorStateV2.DRAFT,
audience: [],
voucherLifespan: 60,
dailyCallsPerConsumer: 10,
dailyCallsTotal: 1000,
createdAt: 1n,
serverUrls: ["pagopa.it"],
agreementApprovalPolicy: AgreementApprovalPolicyV2.AUTOMATIC,
attributes: {
certified: [],
verified: [],
declared: [],
},
rejectedReasons: [],
},
],
},
},
stream_id: "123",
timestamp: new Date(),
Expand Down

0 comments on commit a520391

Please sign in to comment.