2022-09-01 06:21:45 +12:00
|
|
|
import { default as ElasticSearchIntegration } from "../elasticsearch"
|
2021-03-17 00:46:13 +13:00
|
|
|
jest.mock("@elastic/elasticsearch")
|
|
|
|
|
|
|
|
class TestConfiguration {
|
2022-09-01 06:21:45 +12:00
|
|
|
integration: any
|
|
|
|
|
|
|
|
constructor(config: any = {}) {
|
|
|
|
this.integration = new ElasticSearchIntegration.integration(config)
|
2021-03-17 00:46:13 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("Elasticsearch Integration", () => {
|
2022-09-01 06:21:45 +12:00
|
|
|
let config: any
|
2021-03-17 00:46:13 +13:00
|
|
|
let indexName = "Users"
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
config = new TestConfiguration()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("calls the create method with the correct params", async () => {
|
|
|
|
const body = {
|
2022-09-01 06:21:45 +12:00
|
|
|
name: "Hello",
|
2021-03-17 00:46:13 +13:00
|
|
|
}
|
2022-09-01 06:21:45 +12:00
|
|
|
const response = await config.integration.create({
|
2021-03-17 00:46:13 +13:00
|
|
|
index: indexName,
|
2022-09-01 06:21:45 +12:00
|
|
|
json: body,
|
2021-03-17 00:46:13 +13:00
|
|
|
})
|
|
|
|
expect(config.integration.client.index).toHaveBeenCalledWith({
|
|
|
|
index: indexName,
|
2022-09-01 06:21:45 +12:00
|
|
|
body,
|
2021-03-17 00:46:13 +13:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("calls the read method with the correct params", async () => {
|
|
|
|
const body = {
|
|
|
|
query: {
|
|
|
|
term: {
|
2022-09-01 06:21:45 +12:00
|
|
|
name: "kimchy",
|
|
|
|
},
|
|
|
|
},
|
2021-03-17 00:46:13 +13:00
|
|
|
}
|
2022-09-01 06:21:45 +12:00
|
|
|
const response = await config.integration.read({
|
2021-03-17 00:46:13 +13:00
|
|
|
index: indexName,
|
2022-09-01 06:21:45 +12:00
|
|
|
json: body,
|
2021-03-17 00:46:13 +13:00
|
|
|
})
|
|
|
|
expect(config.integration.client.search).toHaveBeenCalledWith({
|
|
|
|
index: indexName,
|
2022-09-01 06:21:45 +12:00
|
|
|
body,
|
2021-03-17 00:46:13 +13:00
|
|
|
})
|
|
|
|
expect(response).toEqual(expect.any(Array))
|
|
|
|
})
|
|
|
|
|
|
|
|
it("calls the update method with the correct params", async () => {
|
|
|
|
const body = {
|
2022-09-01 06:21:45 +12:00
|
|
|
name: "updated",
|
2021-03-17 00:46:13 +13:00
|
|
|
}
|
|
|
|
|
2022-09-01 06:21:45 +12:00
|
|
|
const response = await config.integration.update({
|
2021-03-17 00:46:13 +13:00
|
|
|
id: "1234",
|
|
|
|
index: indexName,
|
2022-09-01 06:21:45 +12:00
|
|
|
json: body,
|
2021-03-17 00:46:13 +13:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(config.integration.client.update).toHaveBeenCalledWith({
|
|
|
|
id: "1234",
|
|
|
|
index: indexName,
|
2022-09-01 06:21:45 +12:00
|
|
|
body,
|
2021-03-17 00:46:13 +13:00
|
|
|
})
|
|
|
|
expect(response).toEqual(expect.any(Array))
|
|
|
|
})
|
|
|
|
|
|
|
|
it("calls the delete method with the correct params", async () => {
|
|
|
|
const body = {
|
2022-09-01 06:21:45 +12:00
|
|
|
id: "1234",
|
2021-03-17 00:46:13 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
const response = await config.integration.delete(body)
|
|
|
|
|
|
|
|
expect(config.integration.client.delete).toHaveBeenCalledWith(body)
|
|
|
|
expect(response).toEqual(expect.any(Array))
|
|
|
|
})
|
2022-09-01 06:21:45 +12:00
|
|
|
})
|