Add more async

This commit is contained in:
Jonathan Cremin 2018-04-30 22:20:01 +01:00
parent 7be2b7b97a
commit 8ea8b4d279
14 changed files with 108 additions and 300 deletions

View file

@ -4,8 +4,8 @@ import models from '../models';
import debugname from 'debug';
const debug = debugname('match.audio:db');
co(function *sync() {
co(async function sync() {
debug('Syncing schema');
yield models.sequelize.sync();
await models.sequelize.sync();
debug('Schema synced');
});

View file

@ -2,8 +2,8 @@ import 'should';
import lookup from '../lib/lookup';
describe('Search with url', function(){
it('should find album by url', function* (){
const result = yield lookup('https://play.google.com/music/listen#/album/Bz6wrjczddcj5hurijsv6ohdoay');
it('should find album by url', async function (){
const result = await lookup('https://play.google.com/music/listen#/album/Bz6wrjczddcj5hurijsv6ohdoay');
result.name.should.equal('Phase 5');
});
});

View file

@ -3,30 +3,30 @@ import * as amazon from '../../lib/services/amazon';
describe('Amazon', function () {
describe('lookupId', function () {
it('should find album by ID', function* () {
const result = yield amazon.lookupId('B00V8I134A', 'album');
it('should find album by ID', async function () {
const result = await amazon.lookupId('B00V8I134A', 'album');
result.name.should.equal('In Colour [Explicit]');
});
it('should find track by ID', function* (){
const result = yield amazon.lookupId('B00V8I1CKU', 'track');
it('should find track by ID', async function () {
const result = await amazon.lookupId('B00V8I1CKU', 'track');
result.name.should.equal('Sleep Sound');
});
});
describe('search', function(){
it('should find album by search', function* () {
const result = yield amazon.search({type: 'album', artist: {name: 'Jamie xx'}, name: 'In Colour'});
it('should find album by search', async function () {
const result = await amazon.search({type: 'album', artist: {name: 'Jamie xx'}, name: 'In Colour'});
result.name.should.equal('In Colour [Explicit]');
});
it('should find track by search', function* (){
const result = yield amazon.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'In Colour', name: 'Loud Places'});
it('should find track by search', async function () {
const result = await amazon.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'In Colour', name: 'Loud Places'});
result.name.should.equal('Loud Places');
});
it('should find awkward track by search', function* (){
const result = yield amazon.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'In Colour (Remixes)', name: 'Loud Places [Tessela Remix]'});
it('should find awkward track by search', async function () {
const result = await amazon.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'In Colour (Remixes)', name: 'Loud Places [Tessela Remix]'});
result.name.should.equal('Loud Places [Tessela Remix]');
});
});

View file

@ -1,45 +1,45 @@
import 'should';
import * as deezer from '../../lib/services/deezer';
describe('Deezer', function(){
describe('lookupId', function(){
it('should find album by ID', function* (){
const result = yield deezer.lookupId('302127', 'album');
describe('Deezer', () => {
describe('lookupId', () => {
it('should find album by ID', async function test() {
const result = await deezer.lookupId('302127', 'album');
result.name.should.equal('Discovery');
});
it('should find track by ID', function* (){
const result = yield deezer.lookupId('3135554', 'track');
it('should find track by ID', async function (){
const result = await deezer.lookupId('3135554', 'track');
result.name.should.equal('Aerodynamic');
});
});
describe('search', function(){
it('should find album by search', function* (){
const result = yield deezer.search({type: 'album', artist: {name: 'Jamie xx'}, name: 'In Colour'});
describe('search', () => {
it('should find album by search', async function (){
const result = await deezer.search({type: 'album', artist: {name: 'Jamie xx'}, name: 'In Colour'});
result.name.should.startWith('In Colour');
});
it('should find album with various artists by search', function* (){
const result = yield deezer.search({type: 'album', artist: {name: 'Various Artists'}, name: 'The Trevor Nelson Collection'});
it('should find album with various artists by search', async function (){
const result = await deezer.search({type: 'album', artist: {name: 'Various Artists'}, name: 'The Trevor Nelson Collection'});
result.name.should.equal('The Trevor Nelson Collection 3');
});
it('should find track by search', function* (){
const result = yield deezer.search({type: 'track', artist: {name: 'Deftones'}, albumName: 'Deftones', name: 'Hexagram'});
it('should find track by search', async function (){
const result = await deezer.search({type: 'track', artist: {name: 'Deftones'}, albumName: 'Deftones', name: 'Hexagram'});
result.name.should.equal('Hexagram');
});
});
describe('lookupUrl', function(){
describe('parseUrl', function(){
it('should parse album url into ID', function* (){
const result = yield deezer.parseUrl('http://www.deezer.com/album/302127');
describe('lookupUrl', () => {
describe('parseUrl', () => {
it('should parse album url into ID', async function (){
const result = await deezer.parseUrl('http://www.deezer.com/album/302127');
result.id.should.equal(302127);
});
it('should parse track url into ID', function* (){
const result = yield deezer.parseUrl('http://www.deezer.com/track/3135554');
it('should parse track url into ID', async function (){
const result = await deezer.parseUrl('http://www.deezer.com/track/3135554');
result.id.should.equal(3135554);
});
});

View file

@ -1,49 +1,49 @@
import 'should';
import * as google from '../../lib/services/google';
describe('Google Play Music', function(){
describe('lookupId', function(){
it('should find album by ID', function* (){
const result = yield google.lookupId('Byp6lvzimyf74wxi5634ul4tgam', 'album');
describe('Google Play Music', () => {
describe('lookupId', () => {
it('should find album by ID', async function (){
const result = await google.lookupId('Byp6lvzimyf74wxi5634ul4tgam', 'album');
result.name.should.equal('Listen');
});
it('should find track by ID', function* (){
const result = yield google.lookupId('Tjosptub24g2dft37lforqnudpe', 'track');
it('should find track by ID', async function (){
const result = await google.lookupId('Tjosptub24g2dft37lforqnudpe', 'track');
result.name.should.equal('Cherub Rock');
});
});
describe('search', function(){
it('should find album by search', function* (){
const result = yield google.search({type: 'album', artist: {name: 'Jamie xx'}, name: 'In Colour'});
describe('search', () => {
it('should find album by search', async function (){
const result = await google.search({type: 'album', artist: {name: 'Jamie xx'}, name: 'In Colour'});
result.name.should.equal('In Colour');
});
it('should find track by search', function* (){
const result = yield google.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'In Colour', name: 'Loud Places'});
it('should find track by search', async function (){
const result = await google.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'In Colour', name: 'Loud Places'});
result.name.should.equal('Loud Places');
});
it('should find awkward track by search', function* (){
const result = yield google.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'Loud Places (Remixes)', name: 'Loud Places [Tessela Remix]'});
it('should find awkward track by search', async function (){
const result = await google.search({type: 'track', artist: {name: 'Jamie xx'}, albumName: 'Loud Places (Remixes)', name: 'Loud Places [Tessela Remix]'});
result.name.should.equal('Loud Places [Tessela Remix]');
});
});
describe('lookupUrl', function(){
it('should parse regular url into album ID', function* (){
const result = yield google.parseUrl('https://play.google.com/music/listen#/album/Byp6lvzimyf74wxi5634ul4tgam/Jamie+xx/In+Colour');
describe('lookupUrl', () => {
it('should parse regular url into album ID', async function (){
const result = await google.parseUrl('https://play.google.com/music/listen#/album/Byp6lvzimyf74wxi5634ul4tgam/Jamie+xx/In+Colour');
result.id.should.equal('Byp6lvzimyf74wxi5634ul4tgam');
});
it('should parse url without ID into album ID', function* (){
const result = yield google.parseUrl('https://play.google.com/music/listen#/album//Jamie+xx/In+Colour');
it('should parse url without ID into album ID', async function (){
const result = await google.parseUrl('https://play.google.com/music/listen#/album//Jamie+xx/In+Colour');
result.id.should.equal('Bvfmezcj3n42lo4xeuslpclbyrm');
});
it('should parse share url into album ID', function* (){
const result = yield google.parseUrl('https://play.google.com/music/m/Byp6lvzimyf74wxi5634ul4tgam');
it('should parse share url into album ID', async function (){
const result = await google.parseUrl('https://play.google.com/music/m/Byp6lvzimyf74wxi5634ul4tgam');
result.id.should.equal('Byp6lvzimyf74wxi5634ul4tgam');
});
});

View file

@ -3,43 +3,43 @@ import * as itunes from '../../lib/services/itunes';
describe('iTunes Music', function(){
describe('lookupId', function(){
it('should find album by ID', function* (){
const result = yield itunes.lookupId('id215206912', 'album');
it('should find album by ID', async function (){
const result = await itunes.lookupId('id215206912', 'album');
result.name.should.equal('Peace Orchestra');
});
it('should find track by ID', function* (){
const result = yield itunes.lookupId('id215206958', 'track');
it('should find track by ID', async function (){
const result = await itunes.lookupId('id215206958', 'track');
result.name.should.equal('Double Drums');
});
});
describe('search', function(){
it('should find album by search', function* (){
const result = yield itunes.search({type: 'album', artist: {name: 'Deftones'}, name: 'White Pony'});
it('should find album by search', async function (){
const result = await itunes.search({type: 'album', artist: {name: 'Deftones'}, name: 'White Pony'});
result.name.should.equal('White Pony');
});
it('should find awkward album by search', function* (){
const result = yield itunes.search({type: 'album', artist: {name: 'Anavitória'}, name: 'Fica'});
it('should find awkward album by search', async function (){
const result = await itunes.search({type: 'album', artist: {name: 'Anavitória'}, name: 'Fica'});
result.name.should.equal('Fica (feat. Matheus & Kauan) - Single');
});
it('should find track by search', function* (){
const result = yield itunes.search({type: 'track', artist: {name: 'Deftones'}, albumName: 'Deftones', name: 'Hexagram'});
it('should find track by search', async function (){
const result = await itunes.search({type: 'track', artist: {name: 'Deftones'}, albumName: 'Deftones', name: 'Hexagram'});
result.name.should.equal('Hexagram');
});
});
describe('lookupUrl', function(){
describe('parseUrl', function(){
it('should parse album url into ID', function* (){
const result = yield itunes.parseUrl('https://itunes.apple.com/us/album/double-drums/id215206912');
it('should parse album url into ID', async function (){
const result = await itunes.parseUrl('https://itunes.apple.com/us/album/double-drums/id215206912');
result.id.should.equal('us215206912');
});
it('should parse track url into ID', function* (){
const result = yield itunes.parseUrl('https://itunes.apple.com/us/album/double-drums/id215206912?i=215206958&uo=4');
it('should parse track url into ID', async function (){
const result = await itunes.parseUrl('https://itunes.apple.com/us/album/double-drums/id215206912?i=215206958&uo=4');
result.id.should.equal('us215206958');
});
});

View file

@ -3,37 +3,37 @@ import * as spotify from '../../lib/services/spotify';
describe('Spotify', function(){
describe('lookupId', function(){
it('should find album by ID', function* (){
const result = yield spotify.lookupId('77UW17CZFyCaRLHdHeofZu', 'album');
it('should find album by ID', async function (){
const result = await spotify.lookupId('77UW17CZFyCaRLHdHeofZu', 'album');
result.name.should.equal('Listen');
});
it('should find track by ID', function* (){
const result = yield spotify.lookupId('7dS5EaCoMnN7DzlpT6aRn2', 'track');
it('should find track by ID', async function (){
const result = await spotify.lookupId('7dS5EaCoMnN7DzlpT6aRn2', 'track');
result.name.should.equal('Take Me To Church');
});
});
describe('search', function(){
it('should find album by search', function* (){
const result = yield spotify.search({type: 'album', artist: {name: 'David Guetta'}, name: 'Listen (Deluxe)'});
it('should find album by search', async function (){
const result = await spotify.search({type: 'album', artist: {name: 'David Guetta'}, name: 'Listen (Deluxe)'});
result.name.should.equal('Listen (Deluxe)');
});
it('should find br album by search', function* (){
const result = yield spotify.search({type: 'album', artist: {name: 'Anavitória'}, name: 'Fica'});
it('should find br album by search', async function (){
const result = await spotify.search({type: 'album', artist: {name: 'Anavitória'}, name: 'Fica'});
result.name.should.equal('Fica');
});
it('should find album by various artists by search', function* (){
const result = yield spotify.search({type: 'album', artist: {name: 'Various Artists'}, name: 'The Get Down Part II: Original Soundtrack From The Netflix Original Series'});
it('should find album by various artists by search', async function (){
const result = await spotify.search({type: 'album', artist: {name: 'Various Artists'}, name: 'The Get Down Part II: Original Soundtrack From The Netflix Original Series'});
result.name.should.equal('The Get Down Part II: Original Soundtrack From The Netflix Original Series');
});
});
describe('parseUrl', function(){
it('should parse url into ID', function* (){
const result = yield spotify.parseUrl('https://play.spotify.com/album/77UW17CZFyCaRLHdHeofZu');
it('should parse url into ID', async function (){
const result = await spotify.parseUrl('https://play.spotify.com/album/77UW17CZFyCaRLHdHeofZu');
result.id.should.equal('77UW17CZFyCaRLHdHeofZu');
});
});

View file

@ -3,15 +3,15 @@ import * as youtube from '../../lib/services/youtube';
describe('Youtube', function(){
describe('lookup', function(){
it('should find album by lookup', function* (){
const result = yield youtube.lookupId('6JnGBs88sL0');
it('should find album by lookup', async function (){
const result = await youtube.lookupId('6JnGBs88sL0');
result.name.should.equal('Say It Right');
});
});
describe('search', function(){
it('should find album by search', function* (){
const result = yield youtube.search({type: 'track', artist: {name: 'Aesop Rock'}, album: {name: 'Skeconsthon'}, name: 'Zero Dark Thirty'});
it('should find album by search', async function (){
const result = await youtube.search({type: 'track', artist: {name: 'Aesop Rock'}, album: {name: 'Skeconsthon'}, name: 'Zero Dark Thirty'});
result.name.should.equal('Aesop Rock - Zero Dark Thirty (Official Video)');
});
});