3efb2f1f04
refs https://github.com/TryGhost/Team/issues/1236 We want to be able to use the OfferName as the name property for a Stripe Coupon - which has a maximum character length of 40.
79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
const OfferName = require('../../../../lib/domain/models/OfferName');
|
|
|
|
describe('OfferName', function () {
|
|
describe('OfferName.create factory', function () {
|
|
it('Creates an Offer description containing a string', function () {
|
|
OfferName.create('My Offer');
|
|
|
|
try {
|
|
OfferName.create();
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferName.InvalidOfferName,
|
|
'expected an InvalidOfferName error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferName.create(null);
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferName.InvalidOfferName,
|
|
'expected an InvalidOfferName error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferName.create(12);
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferName.InvalidOfferName,
|
|
'expected an InvalidOfferName error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferName.create({});
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferName.InvalidOfferName,
|
|
'expected an InvalidOfferName error'
|
|
);
|
|
}
|
|
});
|
|
|
|
it('Requires the string to be a maximum of 40 characters', function () {
|
|
const maxLengthInput = Array.from({length: 40}).map(() => 'a').join('');
|
|
|
|
should.equal(maxLengthInput.length, 40);
|
|
|
|
OfferName.create(maxLengthInput);
|
|
|
|
const tooLong = maxLengthInput + 'a';
|
|
|
|
should.equal(tooLong.length, 41);
|
|
|
|
try {
|
|
OfferName.create(tooLong);
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferName.InvalidOfferName,
|
|
'expected an InvalidOfferName error'
|
|
);
|
|
}
|
|
});
|
|
|
|
it('Trims the contents of the OfferName', function () {
|
|
const description = OfferName.create(' Trim me! ');
|
|
|
|
should.equal(description.value, 'Trim me!');
|
|
});
|
|
});
|
|
});
|
|
|