i1-soundcloud
Version:
tiny client to the soundcloud `i1/tracks#streams` resource
65 lines (42 loc) • 1.67 kB
JavaScript
var fs = require('fs');
var test = require('tap').test;
var sinon = require('sinon');
var i1 = require('../index.js');
var client;
function clear () {
client = null;
}
test('initialize w/ empty object', function (t) {
t.plan(2);
client = new i1({ });
t.ok(client);
t.equal(client.key, '');
clear();
t.end();
});
test('initialize w/ a key', function (t) {
t.plan(2);
client = new i1({ key: 'some_key' });
t.ok(client);
t.equal(client.key, 'some_key');
clear();
t.end();
});
test('#i1Streams', function (t) {
t.plan(1);
client = new i1({ key: 'some_key' });
var expected = 'https://api.soundcloud.com/i1/tracks/123456/streams?client_id=some_key';
t.equal(client.i1Streams('123456'), expected);
clear();
t.end();
});
test('#getStreams', function (t) {
t.plan(1);
// Would love to re-implement this using Sinon's Fake XHR!
var client = sinon.stub();
client.onFirstCall().returns('{"rtmp_mp3_128_url":"rtmp://ec-rtmp-media.soundcloud.com/mp3:uaOLik82Zspo.128?9527d18f1063a01f059bf10590159adb10dea0996b8c0cdb674f9f2f261f859c9bff8d3c8732238a66f15c61c5e068290b0c519fff1361d99257121a85c6f690caa4dd3d5c2b16beb4196b4537e34344ffbc48975189c5cbda27","hls_mp3_128_url":"https://ec-hls-media.soundcloud.com/playlist/uaOLik82Zspo.128.mp3/playlist.m3u8?f10880d39085a94a0418a7e062b03d52bbdc0e179b82bde1d76ce4a21a456b0be48fb253f13741aebee9b76c5ebb0252a2985f4e99e7e24f6832aeca9e92fed5869d415f7d6d7d12285e6e2feea12bbc17dc7e6577b93ed50b8006c5"}');
var expected = fs.readFileSync('./data/streams.json').toString();
t.equal(client(), expected);
clear();
t.end();
});