Skip to content

Commit 3758523

Browse files
committed
fix get trending
1 parent 8f45daf commit 3758523

File tree

6 files changed

+114
-1
lines changed

6 files changed

+114
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
node_modules
22
.DS_Store
33
dist
4-
test

test/download.spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { SoundCloud } = require("../dist");
2+
3+
const concat = (stream, callback) => {
4+
let body = "";
5+
stream.on("data", (chunk) => {
6+
const textChunk = chunk.toString("utf8");
7+
body += textChunk;
8+
});
9+
stream.on("error", callback);
10+
stream.on("end", () => {
11+
callback(null, body);
12+
});
13+
};
14+
15+
describe("Download tracks", () => {
16+
it("Stream is readable", async () => {
17+
const scdl = new SoundCloud();
18+
await scdl.connect();
19+
20+
const permalink =
21+
"https://soundcloud.com/martingarrix/martin-garrix-feat-bonn-no-sleep";
22+
const stream = await scdl.download(permalink);
23+
concat(stream, (err, body) => {
24+
expect(err).toBeNull();
25+
expect(Boolean(body)).toEqual(true);
26+
});
27+
});
28+
});

test/playlist-album.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { SoundCloud } = require("../dist");
2+
3+
describe("Get playlist/album", () => {
4+
it("Returns a playlist/album with valid url", async () => {
5+
const scdl = new SoundCloud();
6+
await scdl.connect();
7+
8+
const permalink =
9+
"https://soundcloud.com/martingarrix/sets/martin-garrix-matisse-sadko";
10+
const playlist = await scdl.playlists.getPlaylist(permalink);
11+
expect(playlist.permalink_url).toEqual(permalink);
12+
});
13+
});

test/search.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { SoundCloud } = require("../dist");
2+
3+
describe("Connect", () => {
4+
const filters = ["albums", "all", "playlists", "tracks", "users"];
5+
const query = "Martin Garrix";
6+
const limit = 5;
7+
8+
it("Returns a valid object with a maximum collection length of <limit>", async () => {
9+
const soundCloud = new SoundCloud();
10+
await soundCloud.connect();
11+
12+
for (const filter of filters) {
13+
const result = await soundCloud.search({
14+
query,
15+
filter,
16+
limit,
17+
});
18+
expect(result.collection.length).toBeLessThanOrEqual(limit);
19+
}
20+
});
21+
});

test/track.spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { SoundCloud } = require("../dist");
2+
3+
describe("Get tracks by ids", () => {
4+
it("Returns an array of objects with a maximum length of <ids.length> and tracks[0] has valid url", async () => {
5+
const scdl = new SoundCloud();
6+
await scdl.connect();
7+
8+
const ids = [578933490, 499766382];
9+
const tracks = await scdl.tracks.getTracksByIds(ids);
10+
expect(tracks.length).toBeLessThanOrEqual(ids.length);
11+
expect(tracks[0].permalink_url).toEqual(
12+
"https://soundcloud.com/martingarrix/martin-garrix-feat-bonn-no-sleep"
13+
);
14+
});
15+
});
16+
17+
describe("Get track by permalink", () => {
18+
const permalink =
19+
"https://soundcloud.com/martingarrix/martin-garrix-feat-bonn-no-sleep";
20+
21+
it("Returns a track with valid url", async () => {
22+
const scdl = new SoundCloud();
23+
await scdl.connect();
24+
const track = await scdl.tracks.getTrack(permalink);
25+
expect(track.permalink_url).toEqual(permalink);
26+
});
27+
});
28+
29+
describe("Get trending tracks", () => {
30+
it("Returns a valid object with a maximum collection length of <limit>", async () => {
31+
const scdl = new SoundCloud();
32+
await scdl.connect();
33+
34+
const limit = 10;
35+
const tracks = await scdl.tracks.getTrending({
36+
limit: limit,
37+
});
38+
expect(tracks.collection.length).toEqual(limit);
39+
});
40+
});

test/users.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { SoundCloud } = require("../dist");
2+
3+
describe("Get user", () => {
4+
it("Returns a user with valid url", async () => {
5+
const scdl = new SoundCloud();
6+
await scdl.connect();
7+
8+
const permalink = "https://soundcloud.com/martingarrix";
9+
const user = await scdl.users.getUser(permalink);
10+
expect(user.permalink_url).toEqual(permalink);
11+
});
12+
});

0 commit comments

Comments
 (0)