einvoicing
Version:
A JavaScript library for creating and parsing electronic invoices compliant with the eInvoicing Directive, EN 16931, and popular extensions
66 lines • 2.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var EntityId_1 = require("./EntityId");
var HashError_1 = require("../error/HashError");
var TestId = /** @class */ (function (_super) {
tslib_1.__extends(TestId, _super);
function TestId() {
return _super !== null && _super.apply(this, arguments) || this;
}
return TestId;
}(EntityId_1.EntityId));
var Test2Id = /** @class */ (function (_super) {
tslib_1.__extends(Test2Id, _super);
function Test2Id() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Test2Id;
}(EntityId_1.EntityId));
describe('ValueObject', function () {
test('base', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var id, id2, id3, id4;
return tslib_1.__generator(this, function (_a) {
id = new TestId(1);
id2 = new EntityId_1.EntityId('1');
id3 = new TestId(1);
expect(id).toEqual(id3);
expect(id).not.toEqual(id2);
id4 = new Test2Id('9KdMR', true);
expect(id4.toPrimitive()).toEqual('123');
return [2 /*return*/];
});
}); });
test('fromHash', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
expect.assertions(4);
expect((new Test2Id(undefined, true)).toPrimitive()).toEqual(null);
expect((new Test2Id(null, true)).toPrimitive()).toEqual(null);
try {
new Test2Id('123', true);
}
catch (err) {
expect(err).toBeInstanceOf(HashError_1.HashError);
expect(err.message).toEqual('Invalid hash 123');
}
return [2 /*return*/];
});
}); });
test('toHash', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var id, id2, id3;
return tslib_1.__generator(this, function (_a) {
id = new Test2Id('123');
expect(id.toHash()).toEqual('9KdMR');
expect(id.fromHash('VLoxm').toPrimitive()).toEqual('1');
expect(id.toPrimitive()).toEqual('1');
expect(id.toString()).toEqual('090bb5d1-267b-5967-84c8-95bc1bda380f');
id2 = new TestId(123);
expect(id2.toHash()).toEqual('BJejP');
expect(id2.fromHash('BJejP').toPrimitive()).toEqual(123);
id3 = new Test2Id();
expect(function () { return id3.toHash(); }).toThrow('Cannot hash an empty recordId');
return [2 /*return*/];
});
}); });
});
//# sourceMappingURL=EntityId.spec.js.map