daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Jun 30th, 2018 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { expect } = require('chai');
  2. const {
  3.   getYearOfBirth,
  4.   isOver40,
  5.   getUserAge,
  6.   createProduct,
  7.   addPriceToProduct,
  8.   createNorthcoder,
  9.   createUserString,
  10.   getAlbumProperties,
  11.   getAlbumValues,
  12.   countKeys,
  13.   addBandName,
  14.   deletePassword,
  15.   deleteManyPasswords,
  16.   countTheObjects
  17.  
  18. } = require('../src/objects');
  19.  
  20. describe('getYearOfBirth', function () {
  21.   it('returns the year of birth of a user with a yearOfBirth property', function () {
  22.     expect(getYearOfBirth({ yearOfBirth: 1950 })).to.equal(1950);
  23.   });
  24. });
  25.  
  26. describe('isOver40', function () {
  27.   it('returns true if the user is over 40', function () {
  28.     expect(isOver40({age: 55})).to.be.true;
  29.     expect(isOver40({age: 41})).to.be.true;
  30.     expect(isOver40({age: 107})).to.be.true;
  31.     expect(isOver40({age: 999})).to.be.true;
  32.   });
  33.   it('returns false if the user is 40 or younger', function () {
  34.     expect(isOver40({age: 40})).to.be.false;
  35.     expect(isOver40({age: 4})).to.be.false;
  36.     expect(isOver40({age: 10})).to.be.false;
  37.     expect(isOver40({age: 29})).to.be.false;
  38.   });
  39. });
  40.  
  41. describe('getUserAge', () => {
  42.   it('returns the age of the passed user based on its yearOfBirth property', () => {
  43.     const currentYear = new Date().getFullYear();
  44.     const user = {
  45.       yearOfBirth: 1989
  46.     };
  47.     expect(getUserAge(user)).to.equal(currentYear - 1989);
  48.   });
  49. });
  50.  
  51. describe('createProduct', function () {
  52.   it('should create the expected product', function () {
  53.     expect(createProduct()).to.haveOwnProperty('type');
  54.     expect(createProduct()).to.haveOwnProperty('price');
  55.     expect(createProduct().price).to.be.a('number');
  56.     expect(createProduct().type).to.be.a('string');
  57.   });
  58. });
  59.  
  60. describe('addPriceToProduct', () => {
  61.   it('adds a price property to the passed product set to the passed price', () => {
  62.     const product = {
  63.       type: 'Tofu slices'
  64.     };
  65.     const newProduct = addPriceToProduct(product, 1.25);
  66.     expect(newProduct.price).to.equal(1.25);
  67.   });
  68. });
  69.  
  70. describe('createNorthcoder', () => {
  71.   it('returns an object with a \'name\' property set to the passed name argument', () => {
  72.     const northcoder = createNorthcoder('Mauro');
  73.     expect(northcoder).to.haveOwnProperty('name');
  74.     expect(northcoder.name).to.equal('Mauro');
  75.   });
  76.   it('returns an object with an \'age\' property set to the user\'s age in the year 2017 according to the passed yearOfBirth argument', () => {
  77.     const northcoder = createNorthcoder('Mauro', 1989);
  78.     expect(northcoder).to.haveOwnProperty('age');
  79.     expect(northcoder.age).to.equal(28);
  80.   });
  81.   it('returns an object with a \'language\' property set to JavaScript', () => {
  82.     const northcoder = createNorthcoder('Mauro', 1989);
  83.     expect(northcoder).to.haveOwnProperty('language');
  84.     expect(northcoder.language).to.equal('JavaScript');
  85.   });
  86. });
  87.  
  88. describe('createUserString', () => {
  89.   it('returns a string containing "name : <user\'s name>"', () => {
  90.     const mitchObj = { name: 'Mitch', age: 27, language: 'Javascript' };
  91.     const actual = createUserString(mitchObj);
  92.     expect(actual.includes('name: Mitch')).to.be.true;
  93.   });
  94.   it('returns a string containing "age : <user\'s age>"', () => {
  95.     const mitchObj = { name: 'Mitch', age: 27, language: 'Javascript' };
  96.     const actual = createUserString(mitchObj);
  97.     expect(actual.includes('age: 27')).to.be.true;
  98.   });
  99.   it('returns a string containing "language : <user\'s language>"', () => {
  100.     const mitchObj = { name: 'Mitch', age: 27, language: 'Javascript' };
  101.     const actual = createUserString(mitchObj);
  102.     expect(actual.includes('language: Javascript')).to.be.true;
  103.   });
  104.   it('returns a whole string with all of the user\'s details', () => {
  105.     const mitchObj = { name: 'Mitch', age: 27, language: 'Javascript' };
  106.     const actual = createUserString(mitchObj);
  107.     expect(actual.includes('name: Mitch, age: 27, language: Javascript')).to.be.true;
  108.   });
  109. });
  110.  
  111. describe('getAlbumProperties', () => {
  112.   it('returns an array of the album\'s keys', () => {
  113.     const input = { title: 'Pablo Honey', yearReleased: 1993, producer: 'Nigel Godrich' };
  114.     const actual = getAlbumProperties(input);
  115.     const expected = ['title', 'yearReleased', 'producer'];
  116.     expect(actual).to.eql(expected);
  117.   });
  118. });
  119.  
  120. describe('getAlbumValues', () => {
  121.   it('returns an array of the album\'s values', () => {
  122.     const input = { title: 'Pablo Honey', yearReleased: 1993, producer: 'Nigel Godrich' };
  123.     const actual = getAlbumValues(input);
  124.     const expected = ['Pablo Honey', 1993, 'Nigel Godrich'];
  125.     expect(actual).to.eql(expected);
  126.   });
  127. });
  128.  
  129. describe('countKeys', function () {
  130.   it('counts the keys on an object', function () {
  131.     expect(countKeys({})).to.equal(0);
  132.     expect(countKeys({ a: 6 })).to.equal(1);
  133.     expect(countKeys({ a: 1, b: 2 })).to.equal(2);
  134.     expect(countKeys({ a: 1, b: 2, c: 4, d: 7 })).to.equal(4);
  135.   });
  136. });
  137.  
  138. describe('addBandName', () => {
  139.   it('adds a "bandName" property with a value of "Rad iohead" to a single object in an array', () => {
  140.     const input = [
  141.       {
  142.         title: 'Pablo Honey',
  143.         yearReleased: 1993,
  144.         producer: 'Nigel Godrich'
  145.       }];
  146.     const actual = addBandName(input);
  147.     const expected = [
  148.       {
  149.         bandName: 'Radiohead',
  150.         title: 'Pablo Honey',
  151.         yearReleased: 1993,
  152.         producer: 'Nigel Godrich'
  153.       }];
  154.     expect(actual).to.eql(expected);
  155.   });
  156.   it('adds a "bandName" property with a value of "Radiohead" to several objects in an array', () => {
  157.     const input = [
  158.       {
  159.         title: 'Pablo Honey',
  160.         yearReleased: 1993,
  161.         producer: 'Nigel Godrich',
  162.       },
  163.       {
  164.         title: 'The Bends',
  165.         yearReleased: 1995,
  166.         producer: 'Nigel Godrich'
  167.       }];
  168.     const actual = addBandName(input);
  169.     const expected = [
  170.       {
  171.         title: 'Pablo Honey',
  172.         bandName: 'Radiohead',
  173.         yearReleased: 1993,
  174.         producer: 'Nigel Godrich',
  175.       },
  176.       {
  177.         title: 'The Bends',
  178.         bandName: 'Radiohead',
  179.         yearReleased: 1995,
  180.         producer: 'Nigel Godrich'
  181.       }];
  182.     expect(actual).to.eql(expected);
  183.   });
  184. });
  185.  
  186. describe('deletePassword', function () {
  187.   it('deletes the password key/value pair from a user object', function () {
  188.     expect(deletePassword({ name: 'foo', password: 'cat' })).to.eql(
  189.       { name: 'foo' }
  190.     );
  191.     expect(deletePassword({ name: 'bar', password: 'secretsecret' })).to.eql(
  192.       { name: 'bar' }
  193.     );
  194.     expect(deletePassword({ name: 'claire', username: 'claire1988', password: 'pineapple' })).to.eql(
  195.       { name: 'claire', username: 'claire1988' }
  196.     );
  197.   });
  198. });
  199.  
  200. describe('deleteManyPasswords', function () {
  201.   it('deletes the password key value pair on every object in an array of createUserString', function () {
  202.     expect(deleteManyPasswords([
  203.       { name: 'Barry', password: 'ilovetea' },
  204.       { name: 'Sandeep', password: 'ilovecoffee' },
  205.       { name: 'Kavita', password: 'ilovepie' }
  206.     ])).to.eql([
  207.       {name: 'Barry'},
  208.       {name: 'Sandeep'},
  209.       {name: 'Kavita'}
  210.     ]);
  211.     expect(deleteManyPasswords([
  212.       { name: 'Carmen', password: 'ilovetea' },
  213.       { name: 'Lisa', password: 'ilovepie' }
  214.     ])).to.eql([
  215.       {name: 'Carmen'},
  216.       {name: 'Lisa'}
  217.     ]);
  218.   });
  219. });
  220.  
  221. describe('countTheObjects', function () {
  222.   it('returns the count of objects inside an array of random data types', function () {
  223.     expect(countTheObjects([])).to.equal(0);
  224.     expect(countTheObjects([1, 3, 4, 5])).to.equal(0);
  225.     expect(countTheObjects([1, 3, 4, 5, 'foo'])).to.equal(0);
  226.     expect(countTheObjects([1, 3, 4, 5, {}, {}, {}, 'foo'])).to.equal(3);
  227.     expect(countTheObjects([1, [], 3, 4, 5, {}, {}, {}, 'foo'])).to.equal(3);
  228.     expect(countTheObjects([1, [], null, 3, 4, 5, {}, {}, {}, 'foo'])).to.equal(3);
  229.     expect(countTheObjects([1, {}, [], null, null, 'foo', 3, 4, 5, {}, {}, {}, 'foo'])).to.equal(4);
  230.   });
  231. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top