mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
66970e5002
refs https://github.com/TryGhost/Team/issues/1726 - updates offer setup to allow new `trial` as discount type, was prev only `fixed` and `percent` - updates offer setup to allow `amount` as free trial days value - updates offer setup to allow `trial` as discount duration value for trial offers, was prev only `once`/`forever`/`repeating`
73 lines
2.3 KiB
JavaScript
73 lines
2.3 KiB
JavaScript
const OfferDuration = require('../../../../lib/domain/models/OfferDuration');
|
|
|
|
describe('OfferDuration', function () {
|
|
describe('OfferDuration.create factory', function () {
|
|
it('Will only allow creating a once, repeating or forever duration', function () {
|
|
OfferDuration.create('once');
|
|
OfferDuration.create('forever');
|
|
OfferDuration.create('trial');
|
|
OfferDuration.create('repeating', 2);
|
|
|
|
try {
|
|
OfferDuration.create();
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferDuration.InvalidOfferDuration,
|
|
'expected an InvalidOfferDuration error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferDuration.create('other');
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferDuration.InvalidOfferDuration,
|
|
'expected an InvalidOfferDuration error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferDuration.create('repeating');
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferDuration.InvalidOfferDuration,
|
|
'expected an InvalidOfferDuration error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferDuration.create('repeating', 1.5);
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferDuration.InvalidOfferDuration,
|
|
'expected an InvalidOfferDuration error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferDuration.create('repeating', -12);
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferDuration.InvalidOfferDuration,
|
|
'expected an InvalidOfferDuration error'
|
|
);
|
|
}
|
|
|
|
try {
|
|
OfferDuration.create('repeating', '2');
|
|
should.fail();
|
|
} catch (err) {
|
|
should.ok(
|
|
err instanceof OfferDuration.InvalidOfferDuration,
|
|
'expected an InvalidOfferDuration error'
|
|
);
|
|
}
|
|
});
|
|
});
|
|
});
|