Advertisement
AhmetUstun

12. Payment Package (TEST)

Jul 2nd, 2021
602
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 ('Should throw errow when the new Name is a number', () => {
  9.             expect(() => new PaymentPackage(123, 123)).to.throw('Name must be a non-empty string');
  10.         });
  11.        
  12.         it ('Should throw errow when the new Name is an array', () => {
  13.             expect(() => new PaymentPackage(['abc'], 123)).to.throw('Name must be a non-empty string');
  14.         });
  15.        
  16.         it ('Should throw errow when the new Name is empty', () => {
  17.             expect(() => new PaymentPackage('', 123)).to.throw('Name must be a non-empty string');
  18.         });
  19.        
  20.         it ('Should return the new Name if the input is good', () => {
  21.             expect(() => new PaymentPackage('abc', 123)).not.to.throw('Name must be a non-empty string');
  22.         });
  23.     });
  24.  
  25.     describe('Tests for the Value', () => {
  26.        
  27.         it ('Should throw errow when the new Value is a string', () => {
  28.             expect(() => new PaymentPackage('abc', 'abc')).to.throw('Value must be a non-negative number');
  29.         });
  30.        
  31.         it ('Should throw errow when the new Value is an array', () => {
  32.             expect(() => new PaymentPackage('abc', [123])).to.throw('Value must be a non-negative number');
  33.         });
  34.        
  35.         it ('Should throw errow when the new Value is negative', () => {
  36.             expect(() => new PaymentPackage('abc', -123)).to.throw('Value must be a non-negative number');
  37.         });
  38.        
  39.         it ('Should return the new Value if the input is good', () => {
  40.             expect(() => new PaymentPackage('abc', 123)).not.to.throw('Value must be a non-negative number');
  41.         });
  42.     });
  43.  
  44.     describe('Tests for the VAT', () => {
  45.        
  46.         it ('Should throw errow when the new VAT is a string', () => {
  47.             let flagClass = new PaymentPackage('abc', 123);
  48.             expect(() => flagClass.VAT = 'abc').to.throw('VAT must be a non-negative number');
  49.         });
  50.        
  51.         it ('Should throw errow when the new VAT is an array', () => {
  52.             let flagClass = new PaymentPackage('abc', 123);
  53.             expect(() => flagClass.VAT = [123]).to.throw('VAT must be a non-negative number');
  54.         });
  55.        
  56.         it ('Should throw errow when the new VAT is negative', () => {
  57.             let flagClass = new PaymentPackage('abc', 123);
  58.             expect(() => flagClass.VAT = -123).to.throw('VAT must be a non-negative number');
  59.         });
  60.        
  61.         it ('Should return the new VAT if the input is good', () => {
  62.             let flagClass = new PaymentPackage('abc', 123);
  63.             expect(() => flagClass.VAT = 123).not.to.throw('VAT must be a non-negative number');
  64.         });
  65.     });
  66.  
  67.     describe('Tests for the Active', () => {
  68.        
  69.         it ('Should throw errow when the new Active is a string', () => {
  70.             let flagClass = new PaymentPackage('abc', 123);
  71.             expect(() => flagClass.active = 'abc').to.throw('Active status must be a boolean');
  72.         });
  73.        
  74.         it ('Should throw errow when the new Active is an array', () => {
  75.             let flagClass = new PaymentPackage('abc', 123);
  76.             expect(() => flagClass.active = [123]).to.throw('Active status must be a boolean');
  77.         });
  78.        
  79.         it ('Should throw errow when the new Active is negative', () => {
  80.             let flagClass = new PaymentPackage('abc', 123);
  81.             expect(() => flagClass.active = -123).to.throw('Active status must be a boolean');
  82.         });
  83.        
  84.         it ('Should return the new Active if the input is good', () => {
  85.             let flagClass = new PaymentPackage('abc', 123);
  86.             expect(() => flagClass.active = true).not.to.throw('Active status must be a boolean');
  87.         });
  88.     });
  89.  
  90.     describe('Tests for toString Method', () => {
  91.        
  92.         it ('Should return a string as all the input is correct - 1', () => {
  93.             let flagClass = new PaymentPackage('abc', 123);
  94.             let output = [
  95.                 `Package: abc`,
  96.                 `- Value (excl. VAT): 123`,
  97.                 `- Value (VAT 20%): 147.6`
  98.             ]
  99.             expect(flagClass.toString()).to.equal(output.join('\n'));
  100.         });
  101.  
  102.         it ('Should return a string as all the input is correct - 2', () => {
  103.             let flagClass = new PaymentPackage('abc', 123);
  104.             flagClass.VAT = 30;
  105.             let output = [
  106.                 `Package: abc`,
  107.                 `- Value (excl. VAT): 123`,
  108.                 `- Value (VAT 30%): 159.9`
  109.             ]
  110.             expect(flagClass.toString()).to.equal(output.join('\n'));
  111.         });
  112.  
  113.         it ('Should return a string as all the input is correct - 3', () => {
  114.             let flagClass = new PaymentPackage('abc', 123);
  115.             flagClass.active = false;
  116.             let output = [
  117.                 `Package: abc (inactive)`,
  118.                 `- Value (excl. VAT): 123`,
  119.                 `- Value (VAT 20%): 147.6`
  120.             ]
  121.             expect(flagClass.toString()).to.equal(output.join('\n'));
  122.         });
  123.  
  124.         it ('Should return a string as all the input is correct - 4', () => {
  125.             let flagClass = new PaymentPackage('abc', 123);
  126.             flagClass.VAT = 30;
  127.             flagClass.active = false;
  128.             let output = [
  129.                 `Package: abc (inactive)`,
  130.                 `- Value (excl. VAT): 123`,
  131.                 `- Value (VAT 30%): 159.9`
  132.             ]
  133.             expect(flagClass.toString()).to.equal(output.join('\n'));
  134.         });
  135.     });  
  136. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement