Skip to content

Commit

Permalink
Soundcloud api and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Mar 5, 2018
1 parent 26355cf commit cb22e1e
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 86 deletions.
3 changes: 2 additions & 1 deletion app/globals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
ytApiKey: "AIzaSyCIM4EzNqi1in22f4Z3Ru3iYvLaY8tc3bo",
lastfmApiKey: "2b75dcb291e2b0c9a2c994aca522ac14",
lastfmApiSecret: "2ee49e35f08b837d43b2824198171fc8"
lastfmApiSecret: "2ee49e35f08b837d43b2824198171fc8",
soundcloudApiKey: "I49FIxeHiQfMWdhxi0pI7MjiV210nFx6"
};
10 changes: 10 additions & 0 deletions app/rest/Soundcloud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import globals from '../globals';
const apiUrl = 'https://api.soundcloud.com';

function prepareUrl(url) {
return `${url}&client_id=${globals.soundcloudApiKey}`;
}

export function soundcloudSearch(terms) {
return fetch(prepareUrl(apiUrl + '/tracks?limit=50&q=' + terms));
}
6 changes: 1 addition & 5 deletions app/rest/Youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ function prepareUrl(url) {
return `${url}&key=${globals.ytApiKey}`;
}

function trackSearch(track) {
export function trackSearch(track) {
return fetch(prepareUrl("https://www.googleapis.com/youtube/v3/search?part=id,snippet&type=video&maxResults=50&q="+encodeURIComponent(track)));
}

module.exports = {
trackSearch
};
15 changes: 15 additions & 0 deletions test/soundcloud.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { soundcloudSearch } from '../app/rest/Soundcloud';
import { expect } from 'chai';

describe('Soundcloud REST API tests', () => {
it('performs a basic search', () => {
soundcloudSearch('death grips - get got')
.then(data => data.json())
.then(results => {
expect(results[0]).to.be.an('object').that.includes.all.keys('id', 'title', 'duration', 'stream_url');
})
.catch(err => {
console.error(err);
});
});
});
160 changes: 80 additions & 80 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ describe('Billboard api tests', () => {

it('gets a pop songs list', () => {
billboard.getTop(billboard.lists.genres[0].link)
.then(songs => {
expect(songs).to.be.an('array').that.has.lengthOf(40);
})
.catch(err => {
console.error(err);
});
.then(songs => {
expect(songs).to.be.an('array').that.has.lengthOf(40);
})
.catch(err => {
console.error(err);
});
});
});

Expand All @@ -30,102 +30,102 @@ describe('Last.fm api tests', () => {

it('tests getting top tags', () => {
lastfm.getTopTags()
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('toptags.tag');
var sample = results.toptags.tag[0];
expect(sample).to.be.an('object').that.has.all.keys('name', 'count', 'reach');
});
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('toptags.tag');
var sample = results.toptags.tag[0];
expect(sample).to.be.an('object').that.has.all.keys('name', 'count', 'reach');
});
});

it('tests getting tag info', () => {
lastfm.getTagInfo('indie')
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.property('tag');
expect(results.tag).to.be.an('object').that.has.all.keys(
'name',
'total',
'reach',
'wiki'
);
})
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.property('tag');
expect(results.tag).to.be.an('object').that.has.all.keys(
'name',
'total',
'reach',
'wiki'
);
})
.catch(err => {
console.error(err);
});
});

it('tests getting top tag tracks', () => {
lastfm.getTagTracks('indie')
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('tracks.track');
var sample = results.tracks.track[0];
expect(sample).to.be.an('object').that.has.all.keys(
'name',
'artist',
'duration',
'streamable',
'mbid',
'url',
'image',
'@attr'
);
})
.catch(err => {
console.error(err);
});
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('tracks.track');
var sample = results.tracks.track[0];
expect(sample).to.be.an('object').that.has.all.keys(
'name',
'artist',
'duration',
'streamable',
'mbid',
'url',
'image',
'@attr'
);
})
.catch(err => {
console.error(err);
});
});

it('tests getting top tag albums', () => {
lastfm.getTagAlbums('indie')
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('albums.album');
var sample = results.albums.album[0];
expect(sample).to.be.an('object').that.has.all.keys(
'name',
'mbid',
'url',
'artist',
'image',
'@attr'
);
})
.catch(err => {
console.error(err);
});
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('albums.album');
var sample = results.albums.album[0];
expect(sample).to.be.an('object').that.has.all.keys(
'name',
'mbid',
'url',
'artist',
'image',
'@attr'
);
})
.catch(err => {
console.error(err);
});
});

it('tests getting top tag artists', () => {
lastfm.getTagArtists('indie')
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('topartists.artist');
var sample = results.topartists.artist[0];
expect(sample).to.be.an('object').that.has.all.keys(
'name',
'mbid',
'url',
'streamable',
'image',
'@attr'
);
})
.catch(err => {
console.error(err);
});
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.nested.property('topartists.artist');
var sample = results.topartists.artist[0];
expect(sample).to.be.an('object').that.has.all.keys(
'name',
'mbid',
'url',
'streamable',
'image',
'@attr'
);
})
.catch(err => {
console.error(err);
});
});

it('tests getting similar tags', () => {
lastfm.getSimilarTags('electronic')
.then(response => response.json())
.then(results => {
console.log(results);
})
.catch(err => {
console.error(err);
});
.then(response => response.json())
.then(results => {
expect(results).to.be.an('object').that.has.property('similartags');
})
.catch(err => {
console.error(err);
});
});

});

0 comments on commit cb22e1e

Please sign in to comment.