Advertisement
kstoyanov

02. Christmas Movies-Exam - 10 December 2019

Oct 22nd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Christmas movie functionality', () => {
  2.   let movies;
  3.   let expectedResult;
  4.   let actualResult;
  5.   let throwFunc;
  6.  
  7.   beforeEach(() => {
  8.     movies = new ChristmasMovies();
  9.     expectedResult = '';
  10.     actualResult = '';
  11.   });
  12.  
  13.   describe('constructor functionality', () => {
  14.     it('create movies object with corect properties', () => {
  15.       expect(movies).to.have.own.property('movieCollection');
  16.       expect(movies).to.have.own.property('watched');
  17.       expect(movies).to.have.own.property('actors');
  18.     });
  19.  
  20.     it('movecollection property is an array', () => {
  21.       assert.deepEqual([], movies.movieCollection);
  22.       assert.deepEqual({}, movies.watched);
  23.       assert.deepEqual([], movies.actors);
  24.     });
  25.  
  26.     it('all properties are initially an empty objects', () => {
  27.       expect(movies.movieCollection.length).to.be.equal(0);
  28.       expect(Object.keys(movies.watched).length).to.be.equal(0);
  29.       expect(movies.actors.length).to.be.equal(0);
  30.     });
  31.   });
  32.  
  33.   describe('buyMovie method, functionality', () => {
  34.     it('throws a new error, if the person allready own the given movie', () => {
  35.       movies.buyMovie('Last Christmas', ['Emilia Clarke', 'Henry Golding']);
  36.       throwFunc = () => movies.buyMovie('Last Christmas', ['Emilia Clarke', 'Henry Golding']);
  37.       assert.throws(throwFunc, 'You already own Last Christmas in your collection!');
  38.     });
  39.  
  40.     it('adds a bought movie to movies collection', () => {
  41.       movies.buyMovie('Last Christmas', ['Emilia Clarke', 'Henry Golding']);
  42.       actualResult = movies.movieCollection[0].name;
  43.       expectedResult = 'Last Christmas';
  44.  
  45.       assert.equal(expectedResult, actualResult);
  46.     });
  47.  
  48.     it('adds a bought movie to movies collection', () => {
  49.       movies.buyMovie('Last Christmas', ['Emilia Clarke', 'Henry Golding']);
  50.       movies.buyMovie('Past Christmas', ['Emily Clarkerson', 'Henry Golding']);
  51.       actualResult = movies.movieCollection.length;
  52.       expectedResult = 2;
  53.  
  54.       assert.equal(expectedResult, actualResult);
  55.     });
  56.  
  57.     it('return proper message if movie is added successfully', () => {
  58.       actualResult = movies.buyMovie('Last Christmas', ['Emilia Clarke', 'Henry Golding', 'Emilia Clarke']);
  59.       expectedResult = `You just got Last Christmas to your collection in which ${['Emilia Clarke', 'Henry Golding'].join(', ')} are taking part!`;
  60.  
  61.       assert.equal(expectedResult, actualResult);
  62.     });
  63.   });
  64.  
  65.   describe('discardMovie method, functionality', () => {
  66.     it('throws a new error, if there is no such a movie in collection', () => {
  67.       throwFunc = () => movies.discardMovie('StarWars');
  68.       assert.throws(throwFunc, 'StarWars is not at your collection!');
  69.     });
  70.  
  71.     it('throws a new error in movie is not watched yet', () => {
  72.       movies.buyMovie('StarWars', ['Luck', 'Lea', 'Han']);
  73.       throwFunc = () => movies.discardMovie('StarWars');
  74.  
  75.       assert.throws(throwFunc, 'StarWars is not watched!');
  76.     });
  77.  
  78.     it('returns proper message', () => {
  79.       movies.buyMovie('StarWars', ['Luck', 'Lea', 'Han']);
  80.       movies.watchMovie('StarWars');
  81.       actualResult = movies.discardMovie('StarWars');
  82.       expectedResult = 'You just threw away StarWars!';
  83.  
  84.       assert.equal(expectedResult, actualResult);
  85.     });
  86.   });
  87.  
  88.   describe('watchMovie method, functionality', () => {
  89.     it('throws a new error, if there is no such a movie in collection', () => {
  90.       throwFunc = () => movies.watchMovie('StarWars');
  91.       assert.throws(throwFunc, 'No such movie in your collection!');
  92.     });
  93.  
  94.     it('adds new movie in watched movies list', () => {
  95.       movies.buyMovie('StarWars', ['Luck', 'Lea', 'Han']);
  96.       movies.watchMovie('StarWars');
  97.       actualResult = movies.watched.StarWars;
  98.       expectedResult = 1;
  99.  
  100.       assert.equal(expectedResult, actualResult);
  101.     });
  102.  
  103.     it('adds new movie in watched movies list', () => {
  104.       movies.buyMovie('StarWars', ['Luck', 'Lea', 'Han']);
  105.       movies.watchMovie('StarWars');
  106.       movies.watchMovie('StarWars');
  107.       movies.watchMovie('StarWars');
  108.       actualResult = movies.watched.StarWars;
  109.       expectedResult = 3;
  110.  
  111.       assert.equal(expectedResult, actualResult);
  112.     });
  113.   });
  114.  
  115.   describe('favouriteMovie method, functionality', () => {
  116.     it('throws a new error, if there is no favorites movie', () => {
  117.       movies.buyMovie('StarWars', ['Luck', 'Lea', 'Han']);
  118.       throwFunc = () => movies.favouriteMovie();
  119.       assert.throws(throwFunc, 'You have not watched a movie yet this year!');
  120.     });
  121.  
  122.     it('return proper message, if tehre is favorite movie', () => {
  123.       movies.buyMovie('StarWars IV', ['Luck', 'Lea', 'Han']);
  124.       movies.buyMovie('StarWars V', ['Luck', 'Lea', 'Han']);
  125.       movies.watchMovie('StarWars IV');
  126.       movies.watchMovie('StarWars V');
  127.       movies.buyMovie('StarWars VI', ['Luck', 'Lea', 'Han']);
  128.       movies.watchMovie('StarWars IV');
  129.       movies.watchMovie('StarWars V');
  130.       movies.watchMovie('StarWars VI');
  131.       movies.watchMovie('StarWars VI');
  132.       movies.watchMovie('StarWars VI');
  133.  
  134.       actualResult = movies.favouriteMovie();
  135.       expectedResult = 'Your favourite movie is StarWars VI and you have watched it 3 times!';
  136.  
  137.       assert.equal(expectedResult, actualResult);
  138.     });
  139.   });
  140.  
  141.   describe('mostStarredActor method, functionality', () => {
  142.     it('throws a new error, if there is no watched movies yet', () => {
  143.       throwFunc = () => movies.mostStarredActor();
  144.       assert.throws(throwFunc, 'You have not watched a movie yet this year!');
  145.     });
  146.  
  147.     it('returns proper message if there is a Movie Star', () => {
  148.       movies.buyMovie('StarWars VI', ['Luck', 'Lea', 'Han']);
  149.       movies.buyMovie('StarWars VII', ['Luck', 'Lea', 'Han', 'Rei']);
  150.       actualResult = movies.mostStarredActor();
  151.       expectedResult = 'The most starred actor is Luck and starred in 2 movies!';
  152.  
  153.       assert.equal(expectedResult, actualResult);
  154.     });
  155.   });
  156. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement