smart-types-ts
Version:
A collection of _Smart Types_ and _Smart Constructors_ which enable you to be more strict when defining your application's important types/interfaces.
68 lines (67 loc) • 2.79 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const e = __importStar(require("fp-ts/lib/Either"));
const mkSmartObject_1 = require("./mkSmartObject");
const emailAddress_1 = require("./string/emailAddress");
const stringWithLength_1 = require("./string/stringWithLength");
const url_1 = require("./string/url");
describe("mkSmartObject", () => {
it("fails when the input is invalid", () => {
const mkPerson = mkSmartObject_1.mkSmartObject({
email: emailAddress_1.mkEmailAddress,
name: mkSmartObject_1.mkSmartObject({
display: stringWithLength_1.mkStringWithLength(1, 30),
full: stringWithLength_1.mkStringWithLength(1, 100)
}),
profilePic: url_1.mkURL
});
chai_1.assert.deepStrictEqual(mkPerson({
email: "bad-email",
name: { display: "", full: "" },
profilePic: "bad-url"
}), e.left({
email: "Not a valid email address",
name: {
display: "Length not between 1-30",
full: "Length not between 1-100"
},
profilePic: "Not a valid URL"
}));
});
it("succeeds when the input is valid", () => {
const mkPerson = mkSmartObject_1.mkSmartObject({
email: emailAddress_1.mkEmailAddress,
name: mkSmartObject_1.mkSmartObject({
display: stringWithLength_1.mkStringWithLength(1, 30),
full: stringWithLength_1.mkStringWithLength(1, 100)
}),
profilePic: url_1.mkURL
});
const input = {
email: "test@example.com",
name: { display: "Jane", full: "Jane Doe" },
profilePic: "https://www.example.come/images/1"
};
chai_1.assert.deepStrictEqual(mkPerson(input), e.right(input));
});
});