Advertisement
bebo231312312321

Untitled

Jun 5th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { expect } = require('chai');
  2. const { PaymentPackage } = require('./12.paymentPackage');
  3.  
  4. describe('PaymentPackage', () => {
  5.   describe('valid', () => {
  6.     it('must not throw when valid', () => {
  7.       expect(() => new PaymentPackage('something', 1)).not.to.throw(Error);
  8.     });
  9.   });
  10.  
  11.   describe('name', () => {
  12.     it('must throw err when it is a number', () => {
  13.       expect(() => new PaymentPackage(5, 1)).to.throw(Error);
  14.     });
  15.  
  16.     it('must throw err when it is a an empty string', () => {
  17.       expect(() => new PaymentPackage('', 1)).to.throw(Error);
  18.     });
  19.  
  20.     it('must throw err for array and object', () => {
  21.       expect(() => new PaymentPackage([], 1)).to.throw(Error);
  22.     });
  23.   });
  24.  
  25.   describe('value', () => {
  26.     it('must throw err when it is a negative number', () => {
  27.       expect(() => new PaymentPackage('', -1)).to.throw(Error);
  28.     });
  29.  
  30.     it('must throw err when it is a string', () => {
  31.       expect(() => new PaymentPackage('something', 'test')).to.throw(Error);
  32.     });
  33.  
  34.     it('should 0 value be valid', () => {
  35.       expect(new PaymentPackage('test', 0).value).to.equal(0);
  36.     });
  37.   });
  38.  
  39.   describe('VAT', () => {
  40.     it('must be a non negative number', () => {
  41.       expect(() => (new PaymentPackage('test', 1).VAT = -1)).to.throw(Error);
  42.     });
  43.  
  44.     it('must be a number', () => {
  45.       expect(typeof new PaymentPackage('something', 1).VAT).to.equal('number');
  46.     });
  47.   });
  48.  
  49.   describe('active', () => {
  50.     it('must be boolean', () => {
  51.       expect(typeof new PaymentPackage('test', 1).active).to.equal('boolean');
  52.     });
  53.  
  54.     it('must throw an error when it is a string', () => {
  55.       expect(() => (new PaymentPackage('test', 1).active = 'mambojambo')).to.throw(Error);
  56.     });
  57.  
  58.     it('must throw an error when it s a number', () => {
  59.       expect(() => (new PaymentPackage('test', 1).active = 1)).to.throw(Error);
  60.     });
  61.   });
  62.  
  63.   describe('toString()', () => {
  64.     it('must return a string', () => {
  65.       const result = new PaymentPackage('HR Services', 1500);
  66.       expect(result.toString()).to.equal(
  67.         'Package: HR Services\n- Value (excl. VAT): 1500\n- Value (VAT 20%): 1800'
  68.       );
  69.     });
  70.  
  71.     it('appends the label "inactive" to the printed name if the package is not active', () => {
  72.       const result = new PaymentPackage('HR Services', 1500);
  73.       result.active = false;
  74.       expect(result.toString()).to.equal(
  75.         'Package: HR Services (inactive)\n- Value (excl. VAT): 1500\n- Value (VAT 20%): 1800'
  76.       );
  77.     });
  78.   });
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement