{"size": 2487, "ext": "js", "max_stars_repo_path": "src/helpers/movieHelper.test.js", "max_stars_repo_name": "albert-dm/movie-finder", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/helpers/movieHelper.test.js", "max_issues_repo_name": "albert-dm/movie-finder", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/helpers/movieHelper.test.js", "max_forks_repo_name": "albert-dm/movie-finder", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.2195121951, "max_line_length": 75, "alphanum_fraction": 0.4949738641}
import { sortMovies } from './movieHelper';

const movies = [
  {
    Title: 'Avengers',
    imdbRating: 9
  },
  {
    Title: 'Resident Evil',
    imdbRating: 5.3
  },
  {
    Title: 'Matrix',
    imdbRating: 10
  },
  {
    Title: 'Titanic',
    imdbRating: 7.2
  },
];

describe('Testing sortMovies', () => {
  it('Should sort Title Asc.', () => {
    const filters = {attribute: 'Title', order: 'Asc.'};
    const sortedMovies = sortMovies({movies, ...filters});

    const expected = [
      {
        Title: 'Avengers',
        imdbRating: 9
      },
      {
        Title: 'Matrix',
        imdbRating: 10
      },
      {
        Title: 'Resident Evil',
        imdbRating: 5.3
      },
      {
        Title: 'Titanic',
        imdbRating: 7.2
      },
    ];

    expect(JSON.stringify(sortedMovies)).toMatch(JSON.stringify(expected));
  });
  it('Should sort Title Desc.', () => {
    const filters = {attribute: 'Title', order: 'Desc.'};
    const sortedMovies = sortMovies({movies, ...filters});

    const expected = [
      {
        Title: 'Titanic',
        imdbRating: 7.2
      },
      {
        Title: 'Resident Evil',
        imdbRating: 5.3
      },
      {
        Title: 'Matrix',
        imdbRating: 10
      },
      {
        Title: 'Avengers',
        imdbRating: 9
      },
    ];

    expect(JSON.stringify(sortedMovies)).toMatch(JSON.stringify(expected));
  });
  it('Should sort Rate Asc.', () => {
    const filters = {attribute: 'Rate', order: 'Asc.'};
    const sortedMovies = sortMovies({movies, ...filters});

    const expected = [
      {
        Title: 'Resident Evil',
        imdbRating: 5.3
      },
      {
        Title: 'Titanic',
        imdbRating: 7.2
      },
      {
        Title: 'Avengers',
        imdbRating: 9
      },      
      {
        Title: 'Matrix',
        imdbRating: 10
      },      
    ];

    expect(JSON.stringify(sortedMovies)).toMatch(JSON.stringify(expected));
  });
  it('Should sort Rate Desc.', () => {
    const filters = {attribute: 'Rate', order: 'Desc.'};
    const sortedMovies = sortMovies({movies, ...filters});

    const expected = [
      {
        Title: 'Matrix',
        imdbRating: 10
      },
      {
        Title: 'Avengers',
        imdbRating: 9
      },
      {
        Title: 'Titanic',
        imdbRating: 7.2
      },
      {
        Title: 'Resident Evil',
        imdbRating: 5.3
      },
    ];

    expect(JSON.stringify(sortedMovies)).toMatch(JSON.stringify(expected));
  });
});