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

fix(api-dynamodb-to-elasticsearch): split files #4343

Merged
merged 3 commits into from
Oct 21, 2024
Merged
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
@@ -0,0 +1,65 @@
import { createGzipCompression } from "@webiny/api-elasticsearch";
import { Decompressor } from "~/Decompressor";
import { createPlugins } from "~tests/plugins";
import { FaultyDecompressorPlugin } from "~tests/mocks/FaultyDecompressorPlugin";
import { PluginsContainer } from "@webiny/plugins";

const compressor = createGzipCompression();

describe("Decompressor", () => {
it("should not do anything with the data because it is not compressed", async () => {
const decompressor = new Decompressor({
plugins: createPlugins()
});

const data = {
title: "Hello World"
};

const result = await decompressor.decompress(data);
expect(result).toEqual(data);
});

it("should decompress the data", async () => {
const decompressor = new Decompressor({
plugins: createPlugins()
});

const input = Object.freeze({
title: "Hello World"
});

const data = Object.freeze(await compressor.compress(input));

const result = await decompressor.decompress(data);
expect(result).toEqual(input);
});

it("should return null because something is wrong with the compressed data", async () => {
const decompressor = new Decompressor({
plugins: createPlugins()
});

const data = {
value: "some wrong value which cannot be decompressed",
compression: "gzip"
};

const result = await decompressor.decompress(data);
expect(result).toEqual(null);
});

it("should return null even if decompress throws an error", async () => {
const decompressor = new Decompressor({
plugins: new PluginsContainer([new FaultyDecompressorPlugin()])
});

const data = {
value: "some wrong value which cannot be decompressed",
compression: "gzip"
};

const result = await decompressor.decompress(data);
expect(result).toEqual(null);
});
});
129 changes: 129 additions & 0 deletions packages/api-dynamodb-to-elasticsearch/__tests__/Operations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { Operations } from "~/Operations";

describe("Operations", () => {
it("should insert an item", async () => {
const operations = new Operations();

operations.insert({
id: "1",
index: "test-index",
data: {
title: "Hello World"
}
});

expect(operations.items).toEqual([
{
index: {
_id: "1",
_index: "test-index"
}
},
{
title: "Hello World"
}
]);

expect(operations.total).toBe(2);
});

it("should modify an item", async () => {
const operations = new Operations();

operations.modify({
id: "1",
index: "test-index",
data: {
title: "Hello World"
}
});

expect(operations.items).toEqual([
{
index: {
_id: "1",
_index: "test-index"
}
},
{
title: "Hello World"
}
]);

expect(operations.total).toBe(2);
});

it("should delete an item", async () => {
const operations = new Operations();

operations.delete({
id: "1",
index: "test-index"
});

expect(operations.items).toEqual([
{
delete: {
_id: "1",
_index: "test-index"
}
}
]);

expect(operations.total).toBe(1);
});

it("should insert, update and delete items", async () => {
const operations = new Operations();

operations.insert({
id: "1",
index: "test-index",
data: {
title: "Hello World"
}
});

operations.modify({
id: "2",
index: "test-index-2",
data: {
title: "Hello World 2"
}
});

operations.delete({
id: "1",
index: "test-index"
});

expect(operations.items).toEqual([
{
index: {
_id: "1",
_index: "test-index"
}
},
{
title: "Hello World"
},
{
index: {
_id: "2",
_index: "test-index-2"
}
},
{
title: "Hello World 2"
},
{
delete: {
_id: "1",
_index: "test-index"
}
}
]);

expect(operations.total).toBe(5);
});
});
Loading