kstoyanov

7.Payment Package-unit

Oct 27th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Test PaymentPackage class', () => {
  2.     it('Has initial values', () => {
  3.         expect(PaymentPackage.prototype.hasOwnProperty('name')).to.be.equal(true);
  4.         expect(PaymentPackage.prototype.hasOwnProperty('value')).to.be.equal(true);
  5.         expect(PaymentPackage.prototype.hasOwnProperty('VAT')).to.be.equal(true);
  6.         expect(PaymentPackage.prototype.hasOwnProperty('active')).to.be.equal(true);
  7.         expect(PaymentPackage.prototype.hasOwnProperty('toString')).to.be.equal(true);
  8.     });
  9.  
  10.     it('Test with invalid params', () => {
  11.         expect(() => new PaymentPackage()).to.throw();
  12.         expect(() => new PaymentPackage(3, 6, 6)).to.throw();
  13.         expect(() => new PaymentPackage({}, 'str', 3)).to.throw();
  14.     });
  15.  
  16.     it('Test Default value in obj', () => {
  17.         const payment = new PaymentPackage('test', 20);
  18.  
  19.         expect(payment.name).to.not.be.undefined;
  20.         expect(payment.value).to.not.be.undefined;
  21.         expect(payment.VAT).to.not.be.undefined;
  22.         expect(payment.active).to.not.be.undefined;
  23.         expect(payment.toString()).to.not.be.undefined;
  24.  
  25.         expect(payment.VAT).to.be.equal(20);
  26.         expect(payment.active).to.be.equal(true);
  27.     });
  28.  
  29.     describe('Test name', () => {
  30.         it('With no param should throw error', () => {
  31.             expect(() => new PaymentPackage()).to.throw();
  32.         });
  33.  
  34.         it('If it is not string should throw error', () => {
  35.             expect(() => new PaymentPackage(3, 3)).to.throw();
  36.         });
  37.  
  38.         it('If it is empty string should throw error', () => {
  39.             expect(() => new PaymentPackage('', 3)).to.throw();
  40.         });
  41.  
  42.         it('If it is not string should throw error', () => {
  43.             expect(() => new PaymentPackage({}, 3)).to.throw();
  44.         });
  45.  
  46.         it('If it is valid type should not throw error', () => {
  47.             expect(() => new PaymentPackage('test', 3)).to.not.throw();
  48.         });
  49.     });
  50.  
  51.     describe('Test value param', () => {
  52.         it('If it is not number should throw error', () => {
  53.             expect(() => new PaymentPackage('test', '')).to.throw();
  54.         });
  55.  
  56.         it('If it is not number should throw error', () => {
  57.             expect(() => new PaymentPackage('test', {})).to.throw();
  58.         });
  59.  
  60.         it('Without param should throw error', () => {
  61.             expect(() => new PaymentPackage('test')).to.throw();
  62.         });
  63.  
  64.         it('If it is a negative number should throw error', () => {
  65.             expect(() => new PaymentPackage('test', -5)).to.throw();
  66.         });
  67.  
  68.         it('With valid param should not throw error', () => {
  69.             expect(() => new PaymentPackage('test', 5)).to.not.throw();
  70.         });
  71.     });
  72.  
  73.     describe('Test instance of a class', () => {
  74.         const payment = new PaymentPackage('test', 2);
  75.         payment.name = 'test';
  76.  
  77.         it('Test name', () => {
  78.             expect(payment.name).to.be.equal('test');
  79.             expect(() => payment.name = 3).to.throw();
  80.             expect(() => payment.name = {}).to.throw();
  81.             expect(() => payment.name = 'newName').to.not.throw();
  82.             expect(() => payment.name = '').to.throw();
  83.             expect(() => payment.name = null).to.throw();
  84.             expect(() => payment.name = undefined).to.throw();
  85.         });
  86.  
  87.         it('Test vat', () => {
  88.             expect(() => payment.VAT = -3).to.throw();
  89.             expect(() => payment.VAT = {}).to.throw();
  90.             expect(() => payment.VAT = 'newName').to.throw();
  91.             expect(() => payment.VAT = '').to.throw();
  92.             expect(() => payment.VAT = null).to.throw();
  93.             expect(() => payment.VAT = undefined).to.throw();
  94.         });
  95.  
  96.         it('Test value', () => {
  97.             expect(payment.value).to.be.equal(2);
  98.             expect(() => payment.value = 3).to.not.throw();
  99.             expect(() => payment.value = {}).to.throw();
  100.             expect(() => payment.value = -6).to.throw();
  101.             expect(() => payment.value = 'str').to.throw();
  102.             expect(() => payment.value = null).to.throw();
  103.             expect(() => payment.value = undefined).to.throw();
  104.         });
  105.  
  106.         it('Test active param', () => {
  107.             expect(payment.active).to.be.equal(true);
  108.             expect(() => payment.active = 3).to.throw();
  109.             expect(() => payment.active = {}).to.throw();
  110.             expect(() => payment.active = -6).to.throw();
  111.             expect(() => payment.active = 'str').to.throw();
  112.             expect(() => payment.active = false).to.not.throw();
  113.             expect(() => payment.active = null).to.throw();
  114.             expect(() => payment.active = undefined).to.throw();
  115.         });
  116.  
  117.         it('Test toString', () => {
  118.             const pay = new PaymentPackage('test', 2);
  119.  
  120.             pay.active = true;
  121.             expect(pay.toString()).to.be.equal('Package: test\n- Value (excl. VAT): 2\n- Value (VAT 20%): 2.4');
  122.  
  123.             pay.active = false;
  124.             expect(pay.toString()).to.be.equal('Package: test (inactive)\n- Value (excl. VAT): 2\n- Value (VAT 20%): 2.4');
  125.         });
  126.     });
  127. });
Advertisement
Add Comment
Please, Sign In to add comment