simeonshopov

Payment Package

Jun 18th, 2021
790
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('PaymentPackageClass', () => {
  2.  
  3.   describe('Test name property', () => {
  4.     it('Throw an error for empty string', () => {
  5.       try { new PaymentPackage('', 123); } catch (err) { expect(err.message).to.equal('Name must be a non-empty string'); }
  6.     });
  7.     it('Throw an error for invalid type for name property', () => {
  8.       try { new PaymentPackage(true, 123); } catch (err) { expect(err.message).to.equal('Name must be a non-empty string'); }
  9.     });
  10.     it('Creates an object with proper name', () => { const obj = new PaymentPackage('Simo', 123); expect(obj.name).to.equal('Simo'); });
  11.     it('Throw an error for no inputs', () => { try { new PaymentPackage(); } catch (err) { expect(err.message).to.equal('Name must be a non-empty string'); } });
  12.     it('Return right changed name', () => {
  13.       const obj = new PaymentPackage('Simo', 123);
  14.       obj.name = 'Maris';
  15.       expect(obj.name).to.equal('Maris');
  16.     });
  17.     it('Throw an error when changing name', () => {
  18.       const obj = new PaymentPackage('Simo', 1);
  19.       try { obj.name = null; }
  20.       catch (err) { expect(err.message).to.equal('Name must be a non-empty string'); }
  21.     });
  22.   });
  23.  
  24.   describe('Test value property', () => {
  25.     it('Throw an error for non number property', () => {
  26.       try { new PaymentPackage('Simo', 'Miro'); }
  27.       catch (err) { expect(err.message).to.equal('Value must be a non-negative number'); }
  28.     });
  29.     it('Throw an error for negative number', () => {
  30.       try { new PaymentPackage('Simo', -5); }
  31.       catch (err) { expect(err.message).to.equal('Value must be a non-negative number'); }
  32.     });
  33.     it('Create obj normally', () => { const obj = new PaymentPackage('Simo', 1); expect(obj.value).to.equal(1); });
  34.     it('Throw an error for changed value', () => {
  35.       const obj = new PaymentPackage('Simo', 1);
  36.       try { obj.value = -4; } catch (err) { expect(err.message).to.equal('Value must be a non-negative number'); }
  37.     });
  38.     it('Returns 0 value', () => {
  39.       const obj = new PaymentPackage('Simo', 0);
  40.       expect(obj.value).to.equal(0);
  41.     });
  42.   });
  43.  
  44.   describe('Test VAT property', () => {
  45.     it('Return default VAT', () => { const obj = new PaymentPackage('Simo', 1); expect(obj.VAT).to.equal(20); });
  46.     it('Throw an error for invalid inputs', () => {
  47.       try { const obj = new PaymentPackage('Simo', 1); obj.VAT = 'asd'; }
  48.       catch (err) { expect(err.message).to.equal('VAT must be a non-negative number'); }
  49.     });
  50.     it('Throw an error for negative number', () => {
  51.       try { const obj = new PaymentPackage('Simo', 1); obj.VAT = -1; }
  52.       catch (err) { expect(err.message).to.equal('VAT must be a non-negative number'); }
  53.     });
  54.     it ('Return 0', () => {
  55.       const obj = new PaymentPackage('Simo', 1);
  56.       obj.VAT = 0;
  57.       expect(obj.VAT).to.equal(0);
  58.     });
  59.   });
  60.  
  61.   describe('Test active property', () => {
  62.     it('Return default active status', () => { const obj = new PaymentPackage('Simo', 1); expect(obj.active).to.be.true; });
  63.     it('Throw an error for invalid type', () => {
  64.       try { const obj = new PaymentPackage('Simo', 1); obj.active = 'ad'; }
  65.       catch (err) { expect(err.message).to.equal('Active status must be a boolean'); }
  66.     });
  67.     it('Throw an error for invalid type null', () => {
  68.       try { const obj = new PaymentPackage('Simo', 1); obj.active = null; }
  69.       catch (err) { expect(err.message).to.equal('Active status must be a boolean'); }
  70.     });
  71.   });
  72.  
  73.   describe('Test toString', () => {
  74.     it('Return a string representation', () => {
  75.       const obj = new PaymentPackage('HR Services', 1500);
  76.       expect(obj.toString()).to.equal('Package: HR Services\n- Value (excl. VAT): 1500\n- Value (VAT 20%): 1800');
  77.     });
  78.     it('Append inactive', () => {
  79.       const obj = new PaymentPackage('Consultation', 800);
  80.       obj.active = false;
  81.       expect(obj.toString()).to.equal('Package: Consultation (inactive)\n- Value (excl. VAT): 800\n- Value (VAT 20%): 960');
  82.     });
  83.   });
  84.  
  85.   describe('Test have full properties', () => {
  86.     it('return all properties', () => {
  87.       const obj = new PaymentPackage('Simo', 1);
  88.       assert.equal(obj._name, 'Simo');
  89.       assert.equal(obj._value, 1);
  90.       assert.equal(obj._VAT, 20);
  91.       assert.equal(obj._active, true);
  92.       expect(obj instanceof PaymentPackage).to.be.true;
  93.       expect(obj).to.respondTo('toString');
  94.     });
  95.   });
  96.  
  97. });
RAW Paste Data