forked from Chimildic/goofy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.gs
More file actions
40 lines (33 loc) · 1.51 KB
/
Code.gs
File metadata and controls
40 lines (33 loc) · 1.51 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
function test_SpotifyRequest_getFullObjByIds_limit() {
// Mocking SpotifyRequest.getAll to avoid actual API calls and to spy on its usage.
const originalGetAll = SpotifyRequest.getAll;
let receivedUrls;
SpotifyRequest.getAll = (urls) => {
receivedUrls = urls;
// Return a dummy response that matches the expected structure.
return urls.map(url => {
const ids = url.match(/ids=([^&]*)/)[1].split(',');
return ids.map(id => ({ id: id, type: 'track' })); // Simplified dummy objects
});
};
try {
const ids = Array.from({ length: 51 }, (_, i) => `track_id_${i}`);
const limit = 50;
// Before the fix, the internal limit is hardcoded to 20.
// Math.ceil(51 / 20) = 3. So, 3 URLs would be generated.
// After the fix, the passed limit of 50 should be used.
// Math.ceil(51 / 50) = 2. So, 2 URLs should be generated.
SpotifyRequest.getFullObjByIds('tracks', ids, limit);
if (!receivedUrls || receivedUrls.length !== 2) {
throw new Error(`Test Failed: Expected 2 URLs to be generated, but got ${receivedUrls ? receivedUrls.length : 0}.`);
}
console.log("Test Passed: `getFullObjByIds` correctly uses the limit parameter.");
} catch (e) {
console.error(e.message);
} finally {
// Restore the original function to avoid side effects.
SpotifyRequest.getAll = originalGetAll;
}
}
// To run the test:
// test_SpotifyRequest_getFullObjByIds_limit();