Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { it, describe } = require('mocha');
- const { assert, expect } = require('chai');
- let PaymentPackage = require('./task.js');
- describe('Tests paymentpackage', function () {
- describe('constructor /getters, setters/', function () {
- it('assert an instance with valid params', function () {
- let pp = new PaymentPackage('test', 0);
- assert.equal(pp.name, 'test');
- assert.equal(pp.value, 0);
- assert.equal(pp.VAT, 20);
- assert.isTrue(pp.active);
- });
- it('assert an instance with valid params, resetting values', function () {
- let pp = new PaymentPackage('test', 0);
- pp.name = 'new test';
- pp.value = 30;
- pp.VAT = 10;
- pp.active = false;
- assert.equal(pp.name, 'new test');
- assert.equal(pp.value, 30);
- assert.equal(pp.VAT, 10);
- assert.isFalse(pp.active);
- });
- it('assert an instance with invalid params', function () {
- assert.Throw(
- () => new PaymentPackage('', 0),
- 'Name must be a non-empty string'
- );
- assert.Throw(
- () => new PaymentPackage(9, 0),
- 'Name must be a non-empty string'
- );
- assert.Throw(
- () => new PaymentPackage('9', -6),
- 'Value must be a non-negative number'
- );
- assert.Throw(
- () => new PaymentPackage('9', '6'),
- 'Value must be a non-negative number'
- );
- });
- it('assert when resetting with invalid values', function () {
- let pp = new PaymentPackage('test', 0);
- assert.Throw(
- () => pp.name = '',
- 'Name must be a non-empty string'
- );
- assert.Throw(
- () => (pp.name = 7),
- 'Name must be a non-empty string'
- );
- assert.Throw(
- () => (pp.value = '7'),
- 'Value must be a non-negative number'
- );
- assert.Throw(
- () => (pp.value = -7),
- 'Value must be a non-negative number'
- );
- assert.Throw(
- () => (pp.VAT = '7'),
- 'VAT must be a non-negative number'
- );
- assert.Throw(
- () => (pp.VAT = -7),
- 'VAT must be a non-negative number'
- );
- assert.Throw(
- () => (pp.active = -7),
- 'Active status must be a boolean'
- );
- assert.Throw(
- () => (pp.active = 'true'),
- 'Active status must be a boolean'
- );
- });
- });
- describe('toString', function () {
- it('assert output string', function () {
- let pp = new PaymentPackage('test', 0);
- assert.equal(
- pp.toString(),
- `Package: test\n- Value (excl. VAT): 0\n- Value (VAT 20%): 0`
- );
- });
- it('assert output string', function () {
- let pp = new PaymentPackage('test', 0);
- pp.active = false
- assert.equal(
- pp.toString(),
- `Package: test (inactive)\n- Value (excl. VAT): 0\n- Value (VAT 20%): 0`
- );
- });
- it('assert output string', function () {
- let pp = new PaymentPackage('test', 70);
- pp.active = false;
- assert.equal(
- pp.toString(),
- `Package: test (inactive)\n- Value (excl. VAT): 70\n- Value (VAT 20%): 84`
- );
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement