UNPKG

kuzzle-sdk

Version:
250 lines 10.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const cucumber_1 = require("@cucumber/cucumber"); const should_1 = __importDefault(require("should")); (0, cucumber_1.Given)(/^the collection doesn't have a document with id '(.*?)'$/, async function (id) { try { this.content = await this.kuzzle.document.delete(this.index, this.collection, id); } catch (err) { this.error = err; } }); (0, cucumber_1.Given)("the collection has a document with id {string}", async function (id) { this.content = await this.kuzzle.document.create(this.index, this.collection, { a: "document" }, id, { refresh: "wait_for", }); }); (0, cucumber_1.Then)("I get an error in the errors array", function () { (0, should_1.default)(this.content.errors).be.Array().not.be.empty(); }); (0, cucumber_1.Then)("I should have no errors in the errors array", function () { (0, should_1.default)(this.content.errors).be.empty(); }); (0, cucumber_1.When)("I check if {string} exists", async function (id) { this.content = await this.kuzzle.document.exists(this.index, this.collection, id); }); (0, cucumber_1.When)("I count how many documents there is in the collection", async function () { this.content = await this.kuzzle.document.count(this.index, this.collection, {}); }); (0, cucumber_1.When)("I create a document in {string}", async function (collection) { this.content = await this.kuzzle.document.create(this.index, collection, { a: "document" }, "some-id", { refresh: "wait_for", }); }); (0, cucumber_1.When)("I create a document with id {string}", async function (id) { this.ids = [id]; try { this.content = await this.kuzzle.document.create(this.index, this.collection, { a: "document" }, id, { refresh: "wait_for", }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I create the documents [{string}, {string}]", async function (id1, id2) { this.ids = [id1, id2]; try { this.content = await this.kuzzle.document.mCreate(this.index, this.collection, [ { _id: id1, body: { a: "document" } }, { _id: id2, body: { a: "document" } }, ], { refresh: "wait_for", }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I createOrReplace a document with id {string}", async function (id) { this.ids = [id]; try { this.content = await this.kuzzle.document.createOrReplace(this.index, this.collection, id, { a: "replaced document" }, { refresh: "wait_for" }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I createOrReplace the documents [{string}, {string}]", async function (id1, id2) { this.ids = [id1, id2]; try { this.content = await this.kuzzle.document.mCreateOrReplace(this.index, this.collection, [ { _id: id1, body: { a: "replaced document" } }, { _id: id2, body: { a: "replaced document" } }, ], { refresh: "wait_for", }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I delete the document with id {string}", async function (id) { this.ids = [id]; try { this.content = await this.kuzzle.document.delete(this.index, this.collection, id); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I delete the documents [{string}, {string}]", async function (id1, id2) { this.ids = [id1, id2]; try { this.content = await this.kuzzle.document.mDelete(this.index, this.collection, [id1, id2], { refresh: "wait_for" }); } catch (error) { this.error = error; } }); (0, cucumber_1.When)("I replace a document with id {string}", async function (id) { this.ids = [id]; try { this.content = await this.kuzzle.document.replace(this.index, this.collection, id, { a: "replaced document" }, { refresh: "wait_for" }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I replace the documents [{string}, {string}]", async function (id1, id2) { this.ids = [id1, id2]; try { this.content = await this.kuzzle.document.mReplace(this.index, this.collection, [ { _id: id1, body: { a: "replaced document" } }, { _id: id2, body: { a: "replaced document" } }, ], { refresh: "wait_for" }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I get documents [{string}, {string}]", async function (id1, id2) { this.ids = [id1, id2]; this.content = await this.kuzzle.document.mGet(this.index, this.collection, [id1, id2]); }); (0, cucumber_1.When)("I search a document with id {string}", async function (id) { try { this.content = await this.kuzzle.document.search(this.index, this.collection, { query: { match: { _id: id, }, }, }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I search documents matching {string} with from {int} and size {int}", async function (query, from, size) { this.content = await this.kuzzle.document.search(this.index, this.collection, JSON.parse(query), { from, size }); }); (0, cucumber_1.When)("I search the next documents", async function () { const nextPage = await this.content.next(); this.content = nextPage; }); (0, cucumber_1.When)("I update a document with id {string}", async function (id) { this.ids = [id]; try { this.content = await this.kuzzle.document.update(this.index, this.collection, id, { some: "update" }); } catch (err) { this.error = err; } }); (0, cucumber_1.When)("I update the document with id {string} and content {string} = {string}", async function (id, key, val) { this.content = await this.kuzzle.document.update(this.index, this.collection, id, { [key]: val }); }); (0, cucumber_1.When)("I update the documents [{string}, {string}]", async function (id1, id2) { this.ids = [id1, id2]; try { this.content = await this.kuzzle.document.mUpdate(this.index, this.collection, [ { _id: id1, body: { a: "replaced document", some: "update" } }, { _id: id2, body: { a: "replaced document", some: "update" } }, ], { refresh: "wait_for" }); } catch (err) { this.error = err; } }); (0, cucumber_1.Then)("I get an error with message {string}", function (message) { (0, should_1.default)(this.error).not.be.null(); (0, should_1.default)(this.error.message).eql(message); }); (0, cucumber_1.Then)("I must have {int} documents in the collection", async function (number) { const count = await this.kuzzle.document.count(this.index, this.collection, {}); (0, should_1.default)(count).eql(number); }); (0, cucumber_1.Then)("the document is successfully created", async function () { const document = await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); (0, should_1.default)(document).be.an.Object(); }); (0, cucumber_1.Then)("the document is successfully deleted", async function () { try { await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); throw new Error("Expected promise to be rejected"); } catch (error) { (0, should_1.default)(error.status).eql(404); } }); (0, cucumber_1.Then)(/^the document is (successfully|not) found$/, function (yesno) { (0, should_1.default)(this.error).be.null(); (0, should_1.default)(this.content.constructor.name).eql("DocumentSearchResult"); (0, should_1.default)(this.content.total).eql(yesno === "successfully" ? 1 : 0); }); (0, cucumber_1.Then)("the document is successfully replaced", async function () { const document = await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); (0, should_1.default)(document._source.a).eql("replaced document"); }); (0, cucumber_1.Then)("the document is successfully updated", async function () { const document = await this.kuzzle.document.get(this.index, this.collection, this.ids[0]); (0, should_1.default)(document._source.some).eql("update"); }); (0, cucumber_1.Then)("the document {string} should be created", async function (id) { const document = await this.kuzzle.document.get(this.index, this.collection, id); (0, should_1.default)(document).not.be.null(); }); (0, cucumber_1.Then)("the document {string} should be replaced", async function (id) { const document = await this.kuzzle.document.get(this.index, this.collection, id); (0, should_1.default)(document._source.a).eql("replaced document"); }); (0, cucumber_1.Then)("the document {string} should be updated", async function (id) { const document = await this.kuzzle.document.get(this.index, this.collection, id); (0, should_1.default)(document._source.some).eql("update"); }); (0, cucumber_1.Then)(/^the document should (not )?exist$/, function (not) { (0, should_1.default)(this.error).be.null(); if (not) { (0, should_1.default)(this.content).be.false(); } else { (0, should_1.default)(this.content).be.true(); } }); (0, cucumber_1.Then)("the documents should be retrieved", function () { (0, should_1.default)(this.content.successes.length).eql(this.ids.length); (0, should_1.default)(this.content.errors).be.empty(); const found = this.content.successes.map((r) => r._id); for (const id of this.ids) { (0, should_1.default)(found.indexOf(id)).be.greaterThan(-1); } }); (0, cucumber_1.Then)(/^The search result should have (fetched|a total of) (\d+) documents$/, function (what, number) { (0, should_1.default)(this.content.constructor.name).eql("DocumentSearchResult"); let field = "total"; switch (what) { case "a total of": field = "total"; break; case "fetched": field = "fetched"; break; } (0, should_1.default)(this.content[field]).eql(number); }); //# sourceMappingURL=document.js.map