@manhgdev/soundcloud-package 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +12 -0
- package/.eslintrc.json +17 -0
- package/LICENSE +21 -0
- package/README.md +196 -0
- package/bun.lock +914 -0
- package/dist/index.js +867 -0
- package/package.json +38 -0
- package/src/index.js +203 -0
- package/src/modules/discover.js +19 -0
- package/src/modules/media.js +66 -0
- package/src/modules/playlists.js +26 -0
- package/src/modules/search.js +52 -0
- package/src/modules/tracks.js +56 -0
- package/src/modules/users.js +58 -0
- package/tests/client-id.test.js +12 -0
- package/tests/discover.test.js +35 -0
- package/tests/find-ids.test.js +14 -0
- package/tests/media.test.js +27 -0
- package/tests/playlists.test.js +45 -0
- package/tests/search.test.js +70 -0
- package/tests/tracks.test.js +27 -0
- package/tests/users.test.js +49 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
import { test, expect } from "bun:test";
|
2
|
+
import SoundCloudAPI from '../src/index.js';
|
3
|
+
|
4
|
+
// Test với API thật
|
5
|
+
test('search.all should make a request to /search endpoint', async () => {
|
6
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
7
|
+
|
8
|
+
const result = await api.search.all('test query', { limit: 10 });
|
9
|
+
console.log("Search All Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
10
|
+
|
11
|
+
// Kiểm tra cấu trúc kết quả
|
12
|
+
expect(result).toBeDefined();
|
13
|
+
expect(result.collection).toBeDefined();
|
14
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('search.tracks should make a request to /search/tracks endpoint', async () => {
|
18
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
19
|
+
|
20
|
+
const result = await api.search.tracks('test track', { limit: 5 });
|
21
|
+
console.log("Search Tracks Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
22
|
+
|
23
|
+
expect(result).toBeDefined();
|
24
|
+
expect(result.collection).toBeDefined();
|
25
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
26
|
+
});
|
27
|
+
|
28
|
+
test('search.users should make a request to /search/users endpoint', async () => {
|
29
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
30
|
+
|
31
|
+
const result = await api.search.users('test user');
|
32
|
+
console.log("Search Users Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
33
|
+
|
34
|
+
expect(result).toBeDefined();
|
35
|
+
expect(result.collection).toBeDefined();
|
36
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
37
|
+
});
|
38
|
+
|
39
|
+
test('search.albums should make a request to /search/albums endpoint', async () => {
|
40
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
41
|
+
|
42
|
+
const result = await api.search.albums('test album');
|
43
|
+
console.log("Search Albums Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
44
|
+
|
45
|
+
expect(result).toBeDefined();
|
46
|
+
expect(result.collection).toBeDefined();
|
47
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
48
|
+
});
|
49
|
+
|
50
|
+
test('search.playlists should make a request to /search/playlists_without_albums endpoint', async () => {
|
51
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
52
|
+
|
53
|
+
const result = await api.search.playlists('test playlist');
|
54
|
+
console.log("Search Playlists Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
55
|
+
|
56
|
+
expect(result).toBeDefined();
|
57
|
+
expect(result.collection).toBeDefined();
|
58
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
59
|
+
});
|
60
|
+
|
61
|
+
test('search.byGenre should make a request with genre filter', async () => {
|
62
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
63
|
+
|
64
|
+
const result = await api.search.byGenre('electronic', { limit: 5 });
|
65
|
+
console.log("Search By Genre Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
66
|
+
|
67
|
+
expect(result).toBeDefined();
|
68
|
+
expect(result.collection).toBeDefined();
|
69
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
70
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { test, expect } from "bun:test";
|
2
|
+
import SoundCloudAPI from '../src/index.js';
|
3
|
+
|
4
|
+
// Sử dụng ID thật từ kết quả tìm kiếm
|
5
|
+
const TEST_TRACK_ID = 45719017; // Skrillex - Bangarang feat Sirah
|
6
|
+
const TEST_TRACK_IDS = [45719017, 45719017]; // Sử dụng cùng một track ID cho đơn giản
|
7
|
+
|
8
|
+
test('tracks.getMultiple should fetch multiple tracks', async () => {
|
9
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
10
|
+
|
11
|
+
const result = await api.tracks.getMultiple(TEST_TRACK_IDS);
|
12
|
+
console.log("Multiple Tracks Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
13
|
+
|
14
|
+
expect(result).toBeDefined();
|
15
|
+
expect(Array.isArray(result)).toBe(true);
|
16
|
+
});
|
17
|
+
|
18
|
+
test('tracks.getRelated should fetch related tracks', async () => {
|
19
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
20
|
+
|
21
|
+
const result = await api.tracks.getRelated(TEST_TRACK_ID, { limit: 5 });
|
22
|
+
console.log("Related Tracks Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
23
|
+
|
24
|
+
expect(result).toBeDefined();
|
25
|
+
expect(result.collection).toBeDefined();
|
26
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
27
|
+
});
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { test, expect } from "bun:test";
|
2
|
+
import SoundCloudAPI from '../src/index.js';
|
3
|
+
|
4
|
+
// Sử dụng ID thật từ kết quả tìm kiếm
|
5
|
+
const TEST_USER_ID = 856062; // Skrillex
|
6
|
+
|
7
|
+
test('users.getUser should fetch user information', async () => {
|
8
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
9
|
+
|
10
|
+
const result = await api.users.getUser(TEST_USER_ID);
|
11
|
+
console.log("User Info Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
12
|
+
|
13
|
+
expect(result).toBeDefined();
|
14
|
+
expect(result.id).toBeDefined();
|
15
|
+
expect(result.kind).toBe('user');
|
16
|
+
});
|
17
|
+
|
18
|
+
test('users.getTracks should fetch user tracks', async () => {
|
19
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
20
|
+
|
21
|
+
const result = await api.users.getTracks(TEST_USER_ID, { limit: 5 });
|
22
|
+
console.log("User Tracks Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
23
|
+
|
24
|
+
expect(result).toBeDefined();
|
25
|
+
expect(result.collection).toBeDefined();
|
26
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
27
|
+
});
|
28
|
+
|
29
|
+
test('users.getPlaylists should fetch user playlists', async () => {
|
30
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
31
|
+
|
32
|
+
const result = await api.users.getPlaylists(TEST_USER_ID, { limit: 5 });
|
33
|
+
console.log("User Playlists Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
34
|
+
|
35
|
+
expect(result).toBeDefined();
|
36
|
+
expect(result.collection).toBeDefined();
|
37
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
38
|
+
});
|
39
|
+
|
40
|
+
test('users.getFollowings should fetch user followings', async () => {
|
41
|
+
const api = new SoundCloudAPI({ autoFetchClientId: true });
|
42
|
+
|
43
|
+
const result = await api.users.getFollowings(TEST_USER_ID, { limit: 5 });
|
44
|
+
console.log("User Followings Result:", JSON.stringify(result, null, 2).substring(0, 500) + "...");
|
45
|
+
|
46
|
+
expect(result).toBeDefined();
|
47
|
+
expect(result.collection).toBeDefined();
|
48
|
+
expect(Array.isArray(result.collection)).toBe(true);
|
49
|
+
});
|