Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PN-13958] Feat: Updated versioning lambda #1175

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class EventHandler {
numRetry;
constructor() {
this.baseUrl = process.env.PN_WEBHOOK_URL;
if (Date.now() < new Date(`${process.env.START_READ_STREAM_TIMESTAMP}`) || Date.now() >= new Date(`${process.env.STOP_READ_STREAM_TIMESTAMP}`)) {
this.baseUrl = process.env.PN_STREAM_URL;
}
this.attemptTimeout = process.env.ATTEMPT_TIMEOUT_SEC * 1000;
this.numRetry = process.env.NUM_RETRY;
}
Expand Down Expand Up @@ -66,6 +69,11 @@ class EventHandler {
version = 25;
}

if (event["path"].includes("v2.6")) {
version = 26;
}


console.log('version is ', version);

return version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class ConsumeEventStreamHandler extends EventHandler {
console.debug('Mapping to v25')
responseBody.push(data);
break;
case 26:
console.debug('Mapping to v26')
responseBody.push(data);
break;
default:
console.error('Invalid version ', version)
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CreateEventStreamHandler extends EventHandler {
case 23:
case 24:
case 25:
case 26:
requestBody = requestBody;
break;
default:
Expand Down Expand Up @@ -60,6 +61,9 @@ class CreateEventStreamHandler extends EventHandler {
case 25:
transformedObject = response.data;
break;
case 26:
transformedObject = response.data;
break;
default:
console.error('Invalid version ', version)
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class DisableEventStreamHandler extends EventHandler {
case 25:
transformedObject = response.data;
break;
case 26:
transformedObject = response.data;
break;
default:
console.error('Invalid version ', version)
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class GetEventStreamHandler extends EventHandler {
case 23:
case 24:
case 25:
case 26:
transformedObject = response.data;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class UpdateEventStreamHandler extends EventHandler {
case 24:
requestBody = requestBody;
break;
case 26:
requestBody = requestBody;
break;
default:
console.error('Invalid version ', version)
break;
Expand Down Expand Up @@ -68,6 +71,7 @@ class UpdateEventStreamHandler extends EventHandler {
case 23:
case 24:
case 25:
case 26:
transformedObject = response.data;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ describe("ConsumeEventStreamHandler", () => {
});
});
describe("handlerEvent", () => {

process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.4",
});

it("successful request - with element", async () => {
process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.6",
PN_STREAM_URL: "https://api.dev.notifichedigitali.it/delivery-progresses-2/v2.6",
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
STOP_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z"
});

const streamId = "12345";
const event = {
path: "/delivery-progresses/streams/"+ streamId +"/events",
Expand Down Expand Up @@ -162,6 +164,13 @@ describe("ConsumeEventStreamHandler", () => {
});

it("successful request V24 to V23", async () => {
process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.6",
PN_STREAM_URL: "https://api.dev.notifichedigitali.it/delivery-progresses-2/v2.6",
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
STOP_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z"
});

const streamId = "12345";
const event = {
path: "/delivery-progresses/v2.3/streams/"+ streamId +"/events",
Expand Down Expand Up @@ -284,6 +293,13 @@ describe("ConsumeEventStreamHandler", () => {
});

it("successful request V24 to V10", async () => {
process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.6",
PN_STREAM_URL: "https://api.dev.notifichedigitali.it/delivery-progresses-2/v2.6",
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
STOP_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z"
});

const streamId = "12345";
const event = {
path: "/delivery-progresses/streams/"+ streamId +"/events",
Expand Down Expand Up @@ -571,6 +587,13 @@ describe("ConsumeEventStreamHandler", () => {
});

it("successful request V26 to V25", async () => {
process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.6",
PN_STREAM_URL: "https://api.dev.notifichedigitali.it/delivery-progresses-2/v2.6",
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
STOP_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z"
});

const streamId = "12345";
const event = {
path: "/delivery-progresses/v2.5/streams/"+ streamId +"/events",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ describe("CreateEventStreamHandler", () => {

describe("handlerEvent that applies a map function for response body", () => {

process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.6",
});

it("successful request v10", async () => {
process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.6",
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
STOP_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z"
});

const b = JSON.stringify({
title: "stream name",
Expand Down Expand Up @@ -182,13 +183,31 @@ describe("CreateEventStreamHandler", () => {
disabledDate: "2024-02-02T12:00:00Z",
version: "v25"
}
},
{
version: "v2.6",
responseBody: {
title: "stream name",
eventType: "STATUS",
groups: [
{ groupId: "group1", groupName: "Group One" },
{ groupId: "group2", groupName: "Group Two" }
],
filterValues: ["status_1", "status_2"],
streamId: "12345678-90ab-cdef-ghij-klmnopqrstuv",
activationDate: "2024-02-01T12:00:00Z",
disabledDate: "2024-02-02T12:00:00Z",
version: "v26"
}
}
];

describe("handlerEvent test", () => {

process.env = Object.assign(process.env, {
PN_WEBHOOK_URL: "https://api.dev.notifichedigitali.it/delivery-progresses/v2.6",
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
STOP_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z"
});

testCases.forEach(({ version, responseBody }) => {
Expand Down Expand Up @@ -224,5 +243,50 @@ describe("CreateEventStreamHandler", () => {
});
});
});

describe("handlerEvent test url change", () => {
testCases.forEach(({ version, responseBody }) => {
it(`successful request ${version}`, async () => {
process.env = Object.assign(process.env, {
PN_STREAM_URL: "https://api.dev.notifichedigitali.it/delivery-progresses-2/v2.6",
START_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z",
});

createEventStreamHandler = new CreateEventStreamHandler();

const b = JSON.stringify({
title: "stream name",
eventType: "STATUS",
filterValues: ["status_1", "status_2"]
});

const event = {
path: `/delivery-progresses/${version}/streams`,
httpMethod: "POST",
headers: {},
requestContext: {
authorizer: {},
},
body: b
};

let url = `${process.env.PN_STREAM_URL}/streams`;

mock.onPost(url).reply(200, responseBody);

const context = {};
const response = await createEventStreamHandler.handlerEvent(event, context);

expect(response.statusCode).to.equal(200);
expect(response.body).to.equal(JSON.stringify(responseBody));

expect(mock.history.post.length).to.equal(1);

process.env = Object.assign(process.env, {
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
});
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,42 @@ describe("DeleteEventStreamHandler", () => {
});
});

describe("handlerEvent flag url change", () => {
it("successful request", async () => {
process.env = Object.assign(process.env, {
PN_STREAM_URL: "https://api.dev.notifichedigitali.it/delivery-progresses-2/v2.6",
START_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z",
});

deleteEventStreamHandler = new DeleteEventStreamHandler();

const streamId = "12345";
const event = {
path: "/delivery-progresses/streams",
pathParameters : { streamId: streamId },
httpMethod: "DELETE",
headers: {},
requestContext: {
authorizer: {},
},
};

let url = `${process.env.PN_STREAM_URL}/streams/${streamId}`;

mock.onDelete(url).reply(204);

const context = {};
const response = await deleteEventStreamHandler.handlerEvent(event, context);

expect(response.statusCode).to.equal(204);

expect(mock.history.delete.length).to.equal(1);

process.env = Object.assign(process.env, {
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
});
});
});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,66 @@ describe("DisableEventStreamHandler", () => {
});
});

describe("handlerEvent", () => {

it("successful request 2.6", async () => {

process.env = Object.assign(process.env, {
PN_STREAM_URL: "https://api.dev.notifichedigitali.it/delivery-progresses-2/v2.6",
START_READ_STREAM_TIMESTAMP: "2099-01-01T00:00:00Z",
});

disableEventStreamHandler = new DisableEventStreamHandler();

const streamId = "12345";
const b = '{}'
const event = {
path: "/delivery-progresses/v2.6/streams/{streamId}/action/disable",
pathParameters : { streamId: streamId },
httpMethod: "PUT",
headers: {},
requestContext: {
authorizer: {},
},
body: b
};

let url = `${process.env.PN_STREAM_URL}/streams/${streamId}/action/disable`;

const responseBodyV26 = {
title: "stream name",
eventType: "STATUS",
groups: [{
groupId: "group1",
groupName: "Group One"
},
{
groupId: "group2",
groupName: "Group Two"
}],
filterValues: ["status_1", "status_2"],
streamId: "12345678-90ab-cdef-ghij-klmnopqrstuv",
activationDate: "2024-02-01T12:00:00Z",
disabledDate: "2024-02-02T12:00:00Z",
version: "v26"
}

mock.onPost(url).reply(200, responseBodyV26);

const context = {};
const response = await disableEventStreamHandler.handlerEvent(event, context);

expect(response.statusCode).to.equal(200);
expect(response.body).to.equal(JSON.stringify(responseBodyV26));

expect(mock.history.post.length).to.equal(1);

process.env = Object.assign(process.env, {
START_READ_STREAM_TIMESTAMP: "2019-01-01T00:00:00Z",
});
});
});

describe("handlerEvent 1.0 error", () => {

process.env = Object.assign(process.env, {
Expand Down
Loading