@imranbarbhuiya/mongoose-fuzzy-searching
Version:
Mongoose fuzzy searching plugin
70 lines (69 loc) • 3.39 kB
JavaScript
;
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fields_1 = require("./fields");
var schema_1 = require("./schema");
jest.mock("./fields");
describe("setTransformers", function () {
var fields = [
"firstName",
{ keys: ["en", "it"], name: "description" },
{ name: "lastName", weight: 10 },
];
beforeEach(function () {
jest.clearAllMocks();
});
it("should call `removeFuzzyElements` when no options given", function () {
var _a, _b;
var _c = (0, schema_1.setTransformers)(fields), toJSON = _c.toJSON, toObject = _c.toObject;
(_a = toJSON.transform) === null || _a === void 0 ? void 0 : _a.apply(null, [{}, {}, {}]);
(_b = toObject.transform) === null || _b === void 0 ? void 0 : _b.apply(null, [{}, {}, {}]);
expect(fields_1.removeFuzzyElements).toHaveBeenCalledTimes(2);
});
it.each(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n overridedOption\n ", "\n ", "\n "], ["\n overridedOption\n ", "\n ", "\n "])), "toObject", "toJSON")("should call `removeFuzzyElements` and `$overridedOption` tranform function", function (_a) {
var _b;
var _c, _d;
var overridedOption = _a.overridedOption;
var existedOptions = {
getters: true,
virtuals: true,
transform: jest.fn(),
};
var options = (_b = {},
_b[overridedOption] = existedOptions,
_b);
var _e = (0, schema_1.setTransformers)(fields, options), toJSON = _e.toJSON, toObject = _e.toObject;
(_c = toJSON.transform) === null || _c === void 0 ? void 0 : _c.apply(null, [{}, {}, {}]);
(_d = toObject.transform) === null || _d === void 0 ? void 0 : _d.apply(null, [{}, {}, {}]);
expect(fields_1.removeFuzzyElements).toHaveBeenCalledTimes(2);
expect(existedOptions.transform).toHaveBeenCalledTimes(1);
expect(existedOptions.transform).toHaveBeenCalledWith({}, {}, {});
});
it("should call `removeFuzzyElements` and both overridden options", function () {
var _a, _b;
var existedToJSON = {
transform: jest.fn(),
};
var existedToObject = {
getters: true,
virtuals: true,
transform: jest.fn(),
};
var options = {
"toJSON": existedToJSON,
"toObject": existedToObject,
};
var _c = (0, schema_1.setTransformers)(fields, options), toJSON = _c.toJSON, toObject = _c.toObject;
(_a = toJSON.transform) === null || _a === void 0 ? void 0 : _a.apply(null, [{}, {}, {}]);
(_b = toObject.transform) === null || _b === void 0 ? void 0 : _b.apply(null, [{}, {}, {}]);
expect(fields_1.removeFuzzyElements).toHaveBeenCalledTimes(2);
expect(existedToJSON.transform).toHaveBeenCalledTimes(1);
expect(existedToJSON.transform).toHaveBeenCalledWith({}, {}, {});
expect(existedToObject.transform).toHaveBeenCalledTimes(1);
expect(existedToObject.transform).toHaveBeenCalledWith({}, {}, {});
});
});
var templateObject_1;