-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.test.js
More file actions
147 lines (107 loc) · 4.01 KB
/
Copy pathindex.test.js
File metadata and controls
147 lines (107 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import {expect} from "chai";
import * as dotenv from "dotenv";
dotenv.config();
import Client from "./src/Tidal.js";
import {AccessTokenError, OptionsError, FavoriteType} from "./index.js";
describe("throws errors", () => {
it("throws AccessTokenError", () => {
try {
const tidal = new Client({
"userId": "x"
});
} catch(e) {
expect(e).to.eql(new AccessTokenError("No access token provided."));
}
});
it("throws OptionsError", () => {
try {
const tidal = new Client({
"accessToken": "x"
});
} catch(e) {
expect(e).to.eql(new OptionsError("No User ID supplied."));
}
});
});
describe("makes successful api calls", () => {
beforeEach(async () => {
await new Promise(resolve => setTimeout(resolve, 1000));
console.log("waiting...");
});
const tidal = new Client({
accessToken: process.env.TIDAL_ACCESS_TOKEN,
userId: process.env.TIDAL_USER_ID
});
it("retrieves user data", async () => {
const res = await tidal.getUserData();
expect(res).to.include.any.keys("username");
});
it("retrieves user subscription", async () => {
const res = await tidal.getUserSubscription();
expect(res).to.include.any.keys("subscription");
});
it("retrieves user profile", async () => {
const res = await tidal.getUserProfile();
expect(res).to.include.any.keys("name");
});
it("retrieves user followers", async () => {
const res = await tidal.getUserFollowers();
console.log(res);
expect(res).to.include.any.keys("items");
});
it("retrieves user following", async () => {
const res = await tidal.getUserFollowing();
expect(res).to.include.any.keys("items");
});
it("retrieves user playlists", async () => {
const res = await tidal.getUserPlaylists();
expect(res).to.include.any.keys("items");
});
it("retrieves user favorite tracks", async () => {
const res = await tidal.getUserFavorites(FavoriteType.TRACKS);
expect(res).to.include.any.keys("items");
});
it("retrieves user favorite playlists", async () => {
const res = await tidal.getUserFavorites(FavoriteType.PLAYLISTS);
expect(res).to.include.any.keys("items");
});
it("retrieves user favorites last updated", async () => {
const res = await tidal.getUserFavoritesLastUpdated();
expect(res).to.include.any.keys("updatedFavoriteTracks");
});
it("retrieves playlist info", async () => {
const playlistId = process.env.TIDAL_PLAYLIST_ID;
const res = await tidal.getPlaylistInfo(playlistId);
expect(res).to.include.any.keys("uuid", "title", "numberOfTracks");
});
it("retrieves playlist tracks", async () => {
const playlistId = process.env.TIDAL_PLAYLIST_ID;
const res = await tidal.getPlaylistTracks(playlistId);
expect(res).to.include.any.keys("items");
});
it("retrieves track info", async() => {
const trackId = process.env.TIDAL_TRACK_ID;
const res = await tidal.getTrackInfo(trackId);
expect(res).to.include.any.keys("id", "title", "duration");
});
it("creates a playlist", async () => {
const res = await tidal.createPlaylist({
name: "Test Playlist"
});
expect(res).to.include.any.keys("trn", "data");
});
it("adds items to a playlist", async () => {
const playlistId = process.env.TIDAL_PLAYLIST_ID;
const trackId = process.env.TIDAL_TRACK_ID;
const res = await tidal.addTracksToPlaylist(playlistId, [trackId], {
onDupes: "ADD"
});
expect(res).to.include.any.keys("lastUpdated", "addedItemIds");
});
it("searches for tracks", async () => {
const res = await tidal.search({
query: "Tick Tock",
});
expect(res).to.include.any.keys("tracks");
});
});