kuzzle-sdk
Version:
Official Javascript SDK for Kuzzle
116 lines • 4.58 kB
JavaScript
"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)("has specifications", async function () {
await this.kuzzle.collection.updateSpecifications(this.index, this.collection, { strict: true });
});
(0, cucumber_1.Given)("it has a collection {string}", async function (collection) {
await this.kuzzle.collection.create(this.index, collection, {});
this.collection = collection;
});
(0, cucumber_1.Given)("I truncate the collection {string}", async function (collection) {
await this.kuzzle.collection.truncate(this.index, collection, {
refresh: "wait_for",
});
});
(0, cucumber_1.When)("I check if the collection {string} exists", async function (collection) {
try {
this.content = await this.kuzzle.collection.exists(this.index, collection);
}
catch (error) {
this.error = error;
}
});
(0, cucumber_1.When)(/^I create a collection '(.*?)'( with a mapping)?$/, async function (collection, withMapping) {
const mapping = withMapping
? { properties: { gordon: { type: "keyword" } } }
: undefined;
try {
this.content = await this.kuzzle.collection.create(this.index, collection, mapping);
}
catch (error) {
this.error = error;
}
});
(0, cucumber_1.When)("I delete the specifications of {string}", async function (collection) {
try {
await this.kuzzle.collection.deleteSpecifications(this.index, collection);
}
catch (error) {
this.error = error;
}
});
(0, cucumber_1.When)("I list the collections of {string}", async function (index) {
try {
const content = await this.kuzzle.collection.list(index);
this.content = content;
this.total = content.collections.length;
}
catch (error) {
this.error = error;
}
});
(0, cucumber_1.When)("I update the mapping of collection {string}", async function (collection) {
try {
this.content = await this.kuzzle.collection.updateMapping(this.index, collection, {
properties: {
gordon: { type: "keyword" },
},
});
}
catch (err) {
this.error = err;
}
});
(0, cucumber_1.When)("I update the specifications of the collection {string}", async function (collection) {
try {
this.content = await this.kuzzle.collection.updateSpecifications(this.index, collection, { strict: false });
}
catch (err) {
this.error = err;
}
});
(0, cucumber_1.When)("I validate the specifications of {string}", async function (collection) {
this.content = await this.kuzzle.collection.validateSpecifications(this.index, collection, { strict: true });
});
(0, cucumber_1.Then)("the collection {string} should be empty", async function (collection) {
const result = await this.kuzzle.document.search(this.index, collection, {});
(0, should_1.default)(result.total).eql(0);
});
(0, cucumber_1.Then)(/^the collection(?: '(.*?)')? should exist$/, async function (collection) {
const c = collection || this.collection;
const exists = await this.kuzzle.collection.exists(this.index, c);
(0, should_1.default)(exists).be.true();
});
(0, cucumber_1.Then)("the mapping of {string} should be updated", async function (collection) {
const mappings = await this.kuzzle.collection.getMapping(this.index, collection);
(0, should_1.default)(mappings).eql({
dynamic: "true",
properties: {
gordon: { type: "keyword" },
},
});
});
(0, cucumber_1.Then)("the specifications of {string} should be updated", async function (collection) {
const specifications = await this.kuzzle.collection.getSpecifications(this.index, collection);
(0, should_1.default)(specifications.validation).eql({ strict: false });
});
(0, cucumber_1.Then)("the specifications of {string} must not exist", async function (collection) {
try {
await this.kuzzle.collection.getSpecifications(this.index, collection);
throw new Error("Expected promise to be rejected");
}
catch (error) {
(0, should_1.default)(error.status).eql(404);
}
});
(0, cucumber_1.Then)("they should be validated", function () {
(0, should_1.default)(this.content).eql({
valid: true,
});
});
//# sourceMappingURL=collection.js.map