Skip to content

Commit

Permalink
test: add test for triggerEvents flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Juiced66 committed Sep 23, 2024
1 parent 591274d commit ef2def2
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/kuzzle/query.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint no-undef: 0 */
const { DocumentController } = require("../../src/controllers/Document");

const should = require("should"),
sinon = require("sinon"),
Expand Down Expand Up @@ -356,4 +357,60 @@ describe("Kuzzle query management", () => {
.be.calledWith(response);
});
});

describe("triggerEvents option handling", () => {
const index = "index";
const collection = "collection";
const documentContent = { foo: "bar" };
const documentId = "test";

beforeEach(() => {
kuzzle.query = sinon
.stub()
.resolves({ result: { _id: documentId, _source: documentContent } });
kuzzle.document = new DocumentController(kuzzle);
});

it("should include triggerEvents: true in the request parameters when triggerEvents option is used", async () => {
const options = { triggerEvents: true };

kuzzle.document
.create(index, collection, documentContent, documentId, options)
.then((r) => console.log({ r }));

should(kuzzle.query.calledOnce).be.true();

const [request] = kuzzle.query.firstCall.args;
// Assert that triggerEvents is set to true in the request
should(request.triggerEvents).be.true();

should(request.index).be.equal(index);
should(request.collection).be.equal(collection);
should(request.body).be.deepEqual(documentContent);
should(request._id).be.equal(documentId);
});

it("should not include triggerEvents in the request parameters when triggerEvents option is not used", async () => {
const options = {};

await kuzzle.document.create(
index,
collection,
documentContent,
documentId,
options
);

should(kuzzle.query.calledOnce).be.true();

const [request] = kuzzle.query.firstCall.args;

should(request.triggerEvents).be.undefined();

should(request.index).be.equal(index);
should(request.collection).be.equal(collection);
should(request.body).be.deepEqual(documentContent);
should(request._id).be.equal(documentId);
});
});
});

0 comments on commit ef2def2

Please sign in to comment.