2021-11-04 20:52:20 +03:00
|
|
|
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');
|
2022-08-09 12:09:27 +03:00
|
|
|
OfferDuration.create('trial');
|
2021-11-04 20:52:20 +03:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|