Advertisement
viligen

paymentPackage

Jun 12th, 2022
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { it, describe } = require('mocha');
  2.  
  3. const { assert, expect } = require('chai');
  4.  
  5. let PaymentPackage = require('./task.js');
  6.  
  7. describe('Tests paymentpackage', function () {
  8.     describe('constructor /getters, setters/', function () {
  9.         it('assert an instance with valid params', function () {
  10.             let pp = new PaymentPackage('test', 0);
  11.             assert.equal(pp.name, 'test');
  12.             assert.equal(pp.value, 0);
  13.             assert.equal(pp.VAT, 20);
  14.             assert.isTrue(pp.active);
  15.         });
  16.         it('assert an instance with valid params, resetting values', function () {
  17.             let pp = new PaymentPackage('test', 0);
  18.             pp.name = 'new test';
  19.             pp.value = 30;
  20.             pp.VAT = 10;
  21.             pp.active = false;
  22.             assert.equal(pp.name, 'new test');
  23.             assert.equal(pp.value, 30);
  24.             assert.equal(pp.VAT, 10);
  25.             assert.isFalse(pp.active);
  26.         });
  27.  
  28.         it('assert an instance with invalid params', function () {
  29.             assert.Throw(
  30.                 () => new PaymentPackage('', 0),
  31.                 'Name must be a non-empty string'
  32.             );
  33.  
  34.             assert.Throw(
  35.                 () => new PaymentPackage(9, 0),
  36.                 'Name must be a non-empty string'
  37.             );
  38.             assert.Throw(
  39.                 () => new PaymentPackage('9', -6),
  40.                 'Value must be a non-negative number'
  41.             );
  42.             assert.Throw(
  43.                 () => new PaymentPackage('9', '6'),
  44.                 'Value must be a non-negative number'
  45.             );
  46.         });
  47.  
  48.         it('assert when resetting with invalid values', function () {
  49.             let pp = new PaymentPackage('test', 0);
  50.             assert.Throw(
  51.                 () => pp.name = '',
  52.                 'Name must be a non-empty string'
  53.             );
  54.  
  55.             assert.Throw(
  56.                 () => (pp.name = 7),
  57.                 'Name must be a non-empty string'
  58.             );
  59.             assert.Throw(
  60.                 () => (pp.value = '7'),
  61.                 'Value must be a non-negative number'
  62.             );
  63.             assert.Throw(
  64.                 () => (pp.value = -7),
  65.                 'Value must be a non-negative number'
  66.             );
  67.             assert.Throw(
  68.                 () => (pp.VAT = '7'),
  69.                 'VAT must be a non-negative number'
  70.             );
  71.             assert.Throw(
  72.                 () => (pp.VAT = -7),
  73.                 'VAT must be a non-negative number'
  74.             );
  75.  
  76.             assert.Throw(
  77.                 () => (pp.active = -7),
  78.                 'Active status must be a boolean'
  79.             );
  80.             assert.Throw(
  81.                 () => (pp.active = 'true'),
  82.                 'Active status must be a boolean'
  83.             );
  84.         });
  85.     });
  86.     describe('toString', function () {
  87.        
  88.         it('assert output string', function () {
  89.             let pp = new PaymentPackage('test', 0);
  90.             assert.equal(
  91.                 pp.toString(),
  92.                 `Package: test\n- Value (excl. VAT): 0\n- Value (VAT 20%): 0`
  93.             );
  94.         });
  95.        
  96.         it('assert output string', function () {
  97.             let pp = new PaymentPackage('test', 0);
  98.             pp.active = false
  99.             assert.equal(
  100.                 pp.toString(),
  101.                 `Package: test (inactive)\n- Value (excl. VAT): 0\n- Value (VAT 20%): 0`
  102.             );
  103.         });
  104.         it('assert output string', function () {
  105.             let pp = new PaymentPackage('test', 70);
  106.             pp.active = false;
  107.             assert.equal(
  108.                 pp.toString(),
  109.                 `Package: test (inactive)\n- Value (excl. VAT): 70\n- Value (VAT 20%): 84`
  110.             );
  111.         });
  112.     });
  113. });
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement