Created
November 26, 2022 20:33
-
-
Save harazdovskiy/3d223a3d5b37efdf7673a0ba7c9f4235 to your computer and use it in GitHub Desktop.
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
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