-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api-dynamodb-to-elasticsearch): split files (#4343)
- Loading branch information
1 parent
004f3d7
commit a3452d4
Showing
20 changed files
with
1,079 additions
and
363 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
packages/api-dynamodb-to-elasticsearch/__tests__/Decompressor.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,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
129
packages/api-dynamodb-to-elasticsearch/__tests__/Operations.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,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); | ||
}); | ||
}); |
Oops, something went wrong.