Skip to content

Instantly share code, notes, and snippets.

@harazdovskiy
Created November 26, 2022 20:33
Show Gist options
  • Save harazdovskiy/3d223a3d5b37efdf7673a0ba7c9f4235 to your computer and use it in GitHub Desktop.
Save harazdovskiy/3d223a3d5b37efdf7673a0ba7c9f4235 to your computer and use it in GitHub Desktop.
const {create} = require("./index.js");
const {client, index} = require("../elastic");
describe('#create', () => {
beforeEach(async () => {
await client.deleteByQuery({
index,
query: {
match_all: {}
}
})
await client.indices.refresh({index})
})
it('should insert data', async () => {
expect.assertions(3);
const res = await create({type: 'some', value: 100, name: 'jacket'})
await client.indices.refresh();
const data = await client.search({
index,
query: {
match: {
"id": res
}
}
})
expect(res).toEqual(expect.any(String))
expect(res).toHaveLength(26);
expect(data.hits.hits[0]._source).toEqual({
"id": res,
"name": "jacket",
"type": "some",
"value": 100
}
);
})
it('should insert and process the inserted fields', async () => {
const res = await create({type: 'UPPERCASE', value: 25.99, name: ' spaces '})
await client.indices.refresh();
const data = await client.search({
index,
query: {
match: {
"id": res
}
}
})
expect(data.hits.hits[0]._source).toEqual({
"id": res,
"name": "spaces",
"type": "uppercase",
"value": 26
}
);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment