Skip to content

Commit 3a55318

Browse files
committed
test(documents): add tests for empty document validation
- add test for empty array input - add test for empty string input - add test for null input - add test for undefined input
1 parent bd71a54 commit 3a55318

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/Typesense/Documents.spec.js

+59
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,65 @@ describe("Documents", function () {
436436
});
437437

438438
describe(".import", function () {
439+
context("when an empty array of documents is passed", function () {
440+
it("throws RequestMalformed error", function (done) {
441+
documents
442+
.import([])
443+
.then(() => {
444+
done(new Error("Expected import to throw RequestMalformed error"));
445+
})
446+
.catch((error) => {
447+
expect(error.constructor.name).to.eq("RequestMalformed");
448+
expect(error.message).to.eq("No documents provided");
449+
done();
450+
});
451+
});
452+
});
453+
454+
context("when an empty string is passed", function () {
455+
it("throws RequestMalformed error", function (done) {
456+
documents
457+
.import("")
458+
.then(() => {
459+
done(new Error("Expected import to throw RequestMalformed error"));
460+
})
461+
.catch((error) => {
462+
expect(error.constructor.name).to.eq("RequestMalformed");
463+
expect(error.message).to.eq("No documents provided");
464+
done();
465+
});
466+
});
467+
});
468+
469+
context("when null is passed as JSONL string", function () {
470+
it("throws RequestMalformed error", function (done) {
471+
documents
472+
.import(null)
473+
.then(() => {
474+
done(new Error("Expected import to throw RequestMalformed error"));
475+
})
476+
.catch((error) => {
477+
expect(error.constructor.name).to.eq("RequestMalformed");
478+
expect(error.message).to.eq("No documents provided");
479+
done();
480+
});
481+
});
482+
});
483+
484+
context("when undefined is passed as JSONL string", function () {
485+
it("throws RequestMalformed error", function (done) {
486+
documents
487+
.import(undefined)
488+
.then(() => {
489+
done(new Error("Expected import to throw RequestMalformed error"));
490+
})
491+
.catch((error) => {
492+
expect(error.constructor.name).to.eq("RequestMalformed");
493+
expect(error.message).to.eq("No documents provided");
494+
done();
495+
});
496+
});
497+
});
439498
context("when a query paramater is passed", function () {
440499
it("passes the query parameter to the API", function (done) {
441500
mockAxios

0 commit comments

Comments
 (0)