Use async/await for tests.

This commit is contained in:
mike.rode
2019-02-24 03:00:44 -06:00
parent 0fe23657de
commit 003470c455
26 changed files with 110 additions and 141 deletions

View File

@@ -5,59 +5,35 @@ import responses from './mocks/plexResponses';
import { PlexSection, User, PlexLibrary } from '../../../../server/models';
import truncate from '../../../truncate';
before(() => truncate('PlexSection'));
// before(() => truncate('PlexSection'));
describe('ImportData', () => {
// beforeEach(() => {
// User.create({
// firstName: 'Mike',
// lastName: 'Rode',
// email: 'michaelrode44@gmail.com',
// });
// });
before(() => {
User.upsert(
{
firstName: 'Mike',
lastName: 'Rode',
email: 'michaelrode44@gmail.com',
},
{ where: { email: 'micahelrode44@gmail.com' } },
);
});
describe('GET /plex/import/sections', async () => {
it('should find and store sections in the database first', (done) => {
it('should find and store sections in the database first', async () => {
nock('https://plex.mjrflix.com')
.get('/library/sections?X-Plex-Token=testPlexApiToken')
.reply(200, responses.sectionsRaw, {
'Content-Type': 'text/json',
});
chai
.request(app)
.get('/plex/import/sections')
.then((err, res) => {
PlexSection.findAll().then((sections) => {
sections.should.be.a('array');
sections.should.have.length(2);
});
done();
})
.catch(done);
});
it('should find and store sections in the database second', (done) => {
nock('https://plex.mjrflix.com')
.get('/library/sections?X-Plex-Token=testPlexApiToken')
.reply(200, responses.sectionsRaw, {
'Content-Type': 'text/json',
});
chai
.request(app)
.get('/plex/import/sections')
.then((err, res) => {
PlexSection.findAll().then((sections) => {
sections.should.be.a('array');
sections.should.have.length(2);
});
done();
})
.catch(done);
const response = await chai.request(app).get('/plex/import/sections');
response.should.have.status(200);
const sections = await PlexSection.findAll();
sections.should.be.length(2);
});
});
describe('Get /plex/import/libraries', async () => {
it('should sections', (done) => {
it('should sections', async () => {
nock('https://plex.mjrflix.com')
.get(url => url.includes('/library/sections/3'))
.reply(200, responses.getLibraryDataBySectionRaw, {
@@ -73,16 +49,9 @@ describe('ImportData', () => {
.reply(200, responses.sectionsRaw, {
'Content-Type': 'text/json',
});
chai
.request(app)
.get('/plex/import/libraries')
.then((err, res) => {
PlexLibrary.findAll().then((media) => {
media.should.be.a('array');
// console.log('mikes-media', media);
done();
});
});
const response = await chai.request(app).get('/plex/import/libraries');
const media = await PlexLibrary.findAll();
media.should.be.length(56);
});
});
});