-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'adrian/migration-script-using-mt' of github.com:webiny/…
…webiny-js into adrian/migration-script-using-mt
- Loading branch information
Showing
3 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/api-dynamodb-to-elasticsearch/__tests__/transfer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters