Skip to content

Commit

Permalink
mss tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarlsson committed Jan 23, 2018
1 parent ab8ab22 commit 6c26fa7
Showing 1 changed file with 104 additions and 43 deletions.
147 changes: 104 additions & 43 deletions src/mss.spec.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,106 @@
// const getScriptsByGenre = require('./genre/getScriptsByGenre');
// const getScriptByTitle = require('./title/getScriptByTitle');
// const cleanArr = require('./helper/cleanArr');
// const handleError = require('./helper/handleError');
//
// const setDefaults = options => {
// options.genre = options.genre || 'Action';
// options.dest = options.dest || 'scripts';
// options.total = options.total || 10;
//
// return options;
// };
//
// const mss = async options => {
// try {
// let filePaths;
// const { genre, title } = options;
// options.dest = options.dest || 'scripts';
// options.total = options.total || 10;
//
// if (genre) {
// filePaths = await getScriptsByGenre(options);
// filePaths = cleanArr(filePaths);
// } else if (title) {
// filePaths = await getScriptByTitle(options);
// } else {
// setDefaults(options);
// filePaths = await getScriptsByGenre(options);
// filePaths = cleanArr(filePaths);
// }
// return filePaths;
// } catch (e) {
// handleError(e);
// }
// };
//
// module.exports = mss;

// const mss = require('./mss');

describe('mss', () => {
it('should return an array of filePaths ', () => {
// expect(mss(title)).toBe(expectedResult);
const mss = require('./mss');
const fs = require('fs');
const fetchMock = require('fetch-mock');
const mocksUrls = require('./genre/helper/__mocks__/data/mock-urls.json');

jest.unmock('./getScript/getScript');
jest.mock('./getScript/helper/writeToFile');
jest.mock('./getScript/helper/isInvalidScript');
jest.mock('./genre/helper/shouldRandomlySave');
jest.mock('./genre/helper/fileSystem');

const mockData = fs.readFileSync(
'src/genre/helper/__mocks__/data/mock_genre_data.xml',
{
encoding: 'utf-8',
}
);

const mockRawData = fs.readFileSync(
'src/genre/helper/__mocks__/data/mock_raw_data_1.txt',
{
encoding: 'utf-8',
}
);

describe('Movie Script Scraper', () => {
beforeEach(() => {
fetchMock.reset();
});

it('should return an array of filePaths from newly created scripts - genre', () => {
const genre = 'Action';
const genreUrl = `http://www.imsdb.com/feeds/genre.php?genre=${genre}`;
fetchMock.mock(genreUrl, mockData);
mocksUrls.forEach((url, i) => {
fetchMock.mock(mocksUrls[i], mockRawData);
});

const options = {
genre: 'Action',
total: 1,
dest: 'scripts',
};

const expectedResult = [
'scripts/hellboy.txt',
'scripts/frozen.txt',
'scripts/x-men.txt',
'scripts/american-sniper.txt',
];

mss(options)
.then(result => {
expect(result).toMatchObject(expectedResult);
})
.catch(e => {
console.error(e);
});
});

it('should return an array of filePaths from newly created scripts - title', () => {
// const url = 'http://www.imsdb.com/scripts/Frozen.html';
// fetchMock.mock(url, mockData);

const options = {
title: 'frozen',
dest: 'scripts',
};

const expectedResult = 'scripts/frozen.txt';

mss(options)
.then(result => {
expect(result).toBe(expectedResult);
})
.catch(e => {
console.error(e);
});
});

it('should return an array of filePaths from newly created scripts - default', () => {
// const genre = 'Action';
// const genreUrl = `http://www.imsdb.com/feeds/genre.php?genre=${genre}`;
// fetchMock.mock(genreUrl, mockData);
// mocksUrls.forEach((url, i) => {
// fetchMock.mock(mocksUrls[i], mockRawData);
// });

const options = {};

const expectedResult = [
'scripts/hellboy.txt',
'scripts/frozen.txt',
'scripts/x-men.txt',
'scripts/american-sniper.txt',
];

mss(options)
.then(result => {
expect(result).toMatchObject(expectedResult);
})
.catch(e => {
console.error(e);
});
});
});

0 comments on commit 6c26fa7

Please sign in to comment.