Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2021
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const PaymentPackage = require('../12. Payment Package');
  2. const { expect } = require('chai');
  3.  
  4. describe('Tests for PaymentPackage Class', () => {
  5.  
  6.     describe('Tests for the Name', () => {
  7.  
  8.         it('constructor', () => {
  9.             let instance = new PaymentPackage('Name', 100);
  10.  
  11.             assert.equal(instance._name, 'Name', '1');
  12.             assert.equal(instance._value, 100, '3');
  13.             assert.equal(instance._VAT, 20, '4');
  14.             assert.equal(instance._active, true, '5');
  15.         });
  16.  
  17.         it('Should throw errow when the new Name is a number', () => {
  18.             expect(() => new PaymentPackage(123, 123)).to.throw('Name must be a non-empty string');
  19.         });
  20.  
  21.         it('Should throw errow when the new Name is an array', () => {
  22.             expect(() => new PaymentPackage(['abc'], 123)).to.throw('Name must be a non-empty string');
  23.         });
  24.  
  25.         it('Should throw errow when the new Name is empty', () => {
  26.             expect(() => new PaymentPackage('', 123)).to.throw('Name must be a non-empty string');
  27.         });
  28.  
  29.         it('Should return the new Name if the input is good', () => {
  30.             expect(() => new PaymentPackage('abc', 123)).not.to.throw('Name must be a non-empty string');
  31.         });
  32.     });
  33.  
  34.     describe('Tests for the Value', () => {
  35.  
  36.         it('Should throw errow when the new Value is a string', () => {
  37.             expect(() => new PaymentPackage('abc', 'abc')).to.throw('Value must be a non-negative number');
  38.         });
  39.  
  40.         it('Should throw errow when the new Value is an array', () => {
  41.             expect(() => new PaymentPackage('abc', [123])).to.throw('Value must be a non-negative number');
  42.         });
  43.  
  44.         it('Should throw errow when the new Value is negative', () => {
  45.             expect(() => new PaymentPackage('abc', -123)).to.throw('Value must be a non-negative number');
  46.         });
  47.  
  48.         it('Should return the new Value if the input is good', () => {
  49.             expect(() => new PaymentPackage('abc', 123)).not.to.throw('Value must be a non-negative number');
  50.         });
  51.  
  52.         it('Set value to null', () => {
  53.             let instance = new PaymentPackage('Name', 100);
  54.             assert.doesNotThrow(() => { instance.value = 0 })
  55.         });
  56.     });
  57.  
  58.     describe('Tests for the VAT', () => {
  59.  
  60.         it('Should throw errow when the new VAT is a string', () => {
  61.             let flagClass = new PaymentPackage('abc', 123);
  62.             expect(() => flagClass.VAT = 'abc').to.throw('VAT must be a non-negative number');
  63.         });
  64.  
  65.         it('Should throw errow when the new VAT is an array', () => {
  66.             let flagClass = new PaymentPackage('abc', 123);
  67.             expect(() => flagClass.VAT = [123]).to.throw('VAT must be a non-negative number');
  68.         });
  69.  
  70.         it('Should throw errow when the new VAT is negative', () => {
  71.             let flagClass = new PaymentPackage('abc', 123);
  72.             expect(() => flagClass.VAT = -123).to.throw('VAT must be a non-negative number');
  73.         });
  74.  
  75.         it('Should return the new VAT if the input is good', () => {
  76.             let flagClass = new PaymentPackage('abc', 123);
  77.             expect(() => flagClass.VAT = 123).not.to.throw('VAT must be a non-negative number');
  78.         });
  79.     });
  80.  
  81.     describe('Tests for the Active', () => {
  82.  
  83.         it('Should throw errow when the new Active is a string', () => {
  84.             let flagClass = new PaymentPackage('abc', 123);
  85.             expect(() => flagClass.active = 'abc').to.throw('Active status must be a boolean');
  86.         });
  87.  
  88.         it('Should throw errow when the new Active is an array', () => {
  89.             let flagClass = new PaymentPackage('abc', 123);
  90.             expect(() => flagClass.active = [123]).to.throw('Active status must be a boolean');
  91.         });
  92.  
  93.         it('Should throw errow when the new Active is negative', () => {
  94.             let flagClass = new PaymentPackage('abc', 123);
  95.             expect(() => flagClass.active = -123).to.throw('Active status must be a boolean');
  96.         });
  97.  
  98.         it('Should return the new Active if the input is good', () => {
  99.             let flagClass = new PaymentPackage('abc', 123);
  100.             expect(() => flagClass.active = true).not.to.throw('Active status must be a boolean');
  101.         });
  102.     });
  103.  
  104.     describe('Tests for toString Method', () => {
  105.  
  106.         it('Should return a string as all the input is correct - 1', () => {
  107.             let flagClass = new PaymentPackage('abc', 123);
  108.             let output = [
  109.                 `Package: abc`,
  110.                 `- Value (excl. VAT): 123`,
  111.                 `- Value (VAT 20%): 147.6`
  112.             ]
  113.             expect(flagClass.toString()).to.equal(output.join('\n'));
  114.         });
  115.  
  116.         it('Should return a string as all the input is correct - 2', () => {
  117.             let flagClass = new PaymentPackage('abc', 123);
  118.             flagClass.VAT = 30;
  119.             let output = [
  120.                 `Package: abc`,
  121.                 `- Value (excl. VAT): 123`,
  122.                 `- Value (VAT 30%): 159.9`
  123.             ]
  124.             expect(flagClass.toString()).to.equal(output.join('\n'));
  125.         });
  126.  
  127.         it('Should return a string as all the input is correct - 3', () => {
  128.             let flagClass = new PaymentPackage('abc', 123);
  129.             flagClass.active = false;
  130.             let output = [
  131.                 `Package: abc (inactive)`,
  132.                 `- Value (excl. VAT): 123`,
  133.                 `- Value (VAT 20%): 147.6`
  134.             ]
  135.             expect(flagClass.toString()).to.equal(output.join('\n'));
  136.         });
  137.  
  138.         it('Should return a string as all the input is correct - 4', () => {
  139.             let flagClass = new PaymentPackage('abc', 123);
  140.             flagClass.VAT = 30;
  141.             flagClass.active = false;
  142.             let output = [
  143.                 `Package: abc (inactive)`,
  144.                 `- Value (excl. VAT): 123`,
  145.                 `- Value (VAT 30%): 159.9`
  146.             ]
  147.             expect(flagClass.toString()).to.equal(output.join('\n'));
  148.         });
  149.     });
  150. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement