forked from tsai/budibase
3 changed files with 106 additions and 1 deletions
@ -0,0 +1,24 @@ |
|||||
|
const elastic = {} |
||||
|
|
||||
|
elastic.Client = function() { |
||||
|
this.index = jest.fn().mockResolvedValue({ body: [] }) |
||||
|
this.search = jest.fn().mockResolvedValue({ |
||||
|
body: { |
||||
|
hits: { |
||||
|
hits: [ |
||||
|
{ |
||||
|
_source: { |
||||
|
name: "test", |
||||
|
}, |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
this.update = jest.fn().mockResolvedValue({ body: [] }) |
||||
|
this.delete = jest.fn().mockResolvedValue({ body: [] }) |
||||
|
|
||||
|
this.close = jest.fn() |
||||
|
} |
||||
|
|
||||
|
module.exports = elastic |
||||
@ -0,0 +1,81 @@ |
|||||
|
const elasticsearch = require("@elastic/elasticsearch") |
||||
|
const ElasticSearchIntegration = require("../elasticsearch") |
||||
|
jest.mock("@elastic/elasticsearch") |
||||
|
|
||||
|
class TestConfiguration { |
||||
|
constructor(config = {}) { |
||||
|
this.integration = new ElasticSearchIntegration.integration(config) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
describe("Elasticsearch Integration", () => { |
||||
|
let config |
||||
|
let indexName = "Users" |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
config = new TestConfiguration() |
||||
|
}) |
||||
|
|
||||
|
it("calls the create method with the correct params", async () => { |
||||
|
const body = { |
||||
|
name: "Hello" |
||||
|
} |
||||
|
const response = await config.integration.create({ |
||||
|
index: indexName, |
||||
|
json: body |
||||
|
}) |
||||
|
expect(config.integration.client.index).toHaveBeenCalledWith({ |
||||
|
index: indexName, |
||||
|
body |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("calls the read method with the correct params", async () => { |
||||
|
const body = { |
||||
|
query: { |
||||
|
term: { |
||||
|
name: "kimchy" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
const response = await config.integration.read({ |
||||
|
index: indexName, |
||||
|
json: body |
||||
|
}) |
||||
|
expect(config.integration.client.search).toHaveBeenCalledWith({ |
||||
|
index: indexName, |
||||
|
body |
||||
|
}) |
||||
|
expect(response).toEqual(expect.any(Array)) |
||||
|
}) |
||||
|
|
||||
|
it("calls the update method with the correct params", async () => { |
||||
|
const body = { |
||||
|
name: "updated" |
||||
|
} |
||||
|
|
||||
|
const response = await config.integration.update({ |
||||
|
id: "1234", |
||||
|
index: indexName, |
||||
|
json: body |
||||
|
}) |
||||
|
|
||||
|
expect(config.integration.client.update).toHaveBeenCalledWith({ |
||||
|
id: "1234", |
||||
|
index: indexName, |
||||
|
body |
||||
|
}) |
||||
|
expect(response).toEqual(expect.any(Array)) |
||||
|
}) |
||||
|
|
||||
|
it("calls the delete method with the correct params", async () => { |
||||
|
const body = { |
||||
|
id: "1234" |
||||
|
} |
||||
|
|
||||
|
const response = await config.integration.delete(body) |
||||
|
|
||||
|
expect(config.integration.client.delete).toHaveBeenCalledWith(body) |
||||
|
expect(response).toEqual(expect.any(Array)) |
||||
|
}) |
||||
|
}) |
||||
Loading…
Reference in new issue