Skip to content

Commit

Permalink
Merge branch 'adrian/migration-script-using-mt' of github.com:webiny/…
Browse files Browse the repository at this point in the history
…webiny-js into adrian/migration-script-using-mt
  • Loading branch information
adrians5j committed Jun 4, 2024
2 parents d581785 + 520ed32 commit 657e322
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ describe("event", () => {
},
lambdaContext,
request,
reply
reply,
next: jest.fn()
});

expect(result).toEqual(null);
Expand All @@ -86,7 +87,8 @@ describe("event", () => {
event,
lambdaContext,
request,
reply
reply,
next: jest.fn()
});

expect(result).toEqual(null);
Expand Down
56 changes: 56 additions & 0 deletions packages/api-dynamodb-to-elasticsearch/__tests__/transfer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createEventHandler, Operations } from "~/index";
import { createElasticsearchClient } from "@webiny/project-utils/testing/elasticsearch/createClient";
import { ElasticsearchContext } from "@webiny/api-elasticsearch/types";
import { Context, LambdaContext, Reply, Request } from "@webiny/handler-aws/types";
import { marshall } from "@webiny/aws-sdk/client-dynamodb";
import { PluginsContainer } from "@webiny/plugins";

describe("transfer data", () => {
it("should transfer data from event to elasticsearch", async () => {
const event = createEventHandler();

const elasticsearch = createElasticsearchClient();

const context = {
elasticsearch,
plugins: new PluginsContainer()
} as unknown as ElasticsearchContext & Context;
/**
* Register index which is going to get created, so it can be deleted after the test.
*/
const index = "a-test-index";
elasticsearch.indices.registerIndex(index);

const result = await event.cb({
context,
reply: {} as Reply,
request: {} as Request,
event: {
Records: [
{
eventName: Operations.INSERT,
dynamodb: {
Keys: marshall({
PK: "PK_TEST",
SK: "SK_TEST"
}) as any,
NewImage: marshall({
index,
ignore: false,
data: {
title: "Hello World"
}
}) as any
}
}
]
},
lambdaContext: {} as LambdaContext,
next: jest.fn()
});

expect(result).toEqual(null);

await elasticsearch.indices.deleteAll();
});
});
4 changes: 2 additions & 2 deletions packages/api-dynamodb-to-elasticsearch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ElasticsearchCatClusterHealthStatus } from "@webiny/api-elasticsearch/o
import pRetry from "p-retry";
import { NotEnoughRemainingTimeError } from "./NotEnoughRemainingTimeError";

enum Operations {
export enum Operations {
INSERT = "INSERT",
MODIFY = "MODIFY",
REMOVE = "REMOVE"
Expand Down Expand Up @@ -220,7 +220,7 @@ export const createEventHandler = () => {
const execute = async (): Promise<void> => {
const remainingTime = timer.getRemainingSeconds();
const runningTime = MAX_RUNNING_TIME - remainingTime;
const maxWaitingTime = MAX_RUNNING_TIME - 90 - remainingTime;
const maxWaitingTime = remainingTime - 90;

if (process.env.DEBUG === "true") {
console.debug(
Expand Down

0 comments on commit 657e322

Please sign in to comment.