Skip to content

Commit

Permalink
fix(api-dynamodb-to-elasticsearch): split files (#4343)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Nov 5, 2024
1 parent 09aff40 commit f15cee5
Show file tree
Hide file tree
Showing 19 changed files with 1,078 additions and 362 deletions.
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

0 comments on commit f15cee5

Please sign in to comment.