<commit_before>'use strict';

const q = require('qunit');
const isEqual = require('lodash/isEqual');
const { client, usePlayer, tracks } = require('./test_context');
const { waitUntil, pathCollectionsEqual } = require('./utils');

q.module('playlists api', usePlayer());

q.test('get playlists', async assert =>
{
    const playlists = await client.getPlaylists();

    assert.ok(playlists);
    assert.equal(playlists.length, 1);

    const playlist = playlists[0];

    assert.equal(typeof playlist.id, 'string');
    assert.equal(typeof playlist.title, 'string');

    delete playlist.id;
    delete playlist.title;

    assert.deepEqual(playlist, {
        index: 0,
        isCurrent: true,
        itemCount: 0,
        totalTime: 0,
    });
});

q.test('add playlist simple', async assert =>
{
    await client.addPlaylist();

    const playlists = await client.getPlaylists();
    assert.equal(playlists.length, 2);

    const playlist = playlists[1];
    assert.equal(typeof playlist.id, 'string');
    delete playlist.id;

    assert.deepEqual(playlist, {
        index: 1,
        title: 'New playlist',
        isCurrent: false,
        itemCount: 0,
        totalTime: 0,
    });
});

q.test('add playlist full', async assert =>
{
    await client.addPlaylist({ title: 'My playlist', index: 0 });

    const playlists = await client.getPlaylists();
    assert.equal(playlists.length, 2);

    const playlist = playlists[0];<commit_msg>api: add get playlist items test<commit_after>'use strict';

const q = require('qunit');
const isEqual = require('lodash/isEqual');
const { client, usePlayer, tracks } = require('./test_context');
const { waitUntil, pathCollectionsEqual } = require('./utils');

q.module('playlists api', usePlayer());

q.test('get playlists', async assert =>
{
    const playlists = await client.getPlaylists();

    assert.ok(playlists);
    assert.equal(playlists.length, 1);

    const playlist = playlists[0];

    assert.equal(typeof playlist.id, 'string');
    assert.equal(typeof playlist.title, 'string');

    delete playlist.id;
    delete playlist.title;

    assert.deepEqual(playlist, {
        index: 0,
        isCurrent: true,
        itemCount: 0,
        totalTime: 0,
    });
});

q.test('get playlist items', async assert =>
{
    const columns = ['%track%'];

    await client.addPlaylistItems(0, [tracks.t1]);
    await client.addPlaylistItems(0, [tracks.t2]);
    await client.addPlaylistItems(0, [tracks.t3]);

    const expected = [
        { columns: ['01'] },
        { columns: ['02'] },
        { columns: ['03'] },
    ];

    const result1 = await client.getPlaylistItems(0, columns, '0:3');
    assert.equal(result1.offset, 0);
    assert.equal(result1.totalCount, 3);
    assert.deepEqual(result1.items, expected);

    const result2 = await client.getPlaylistItems(0, columns, '0:2');
    assert.equal(result2.offset, 0);
    assert.equal(result2.totalCount, 3);
    assert.deepEqual(result2.items, expected.slice(0, 2));

    const result3 = await client.getPlaylistItems(0, columns, '2:2');
    assert.equal(result3.offset, 2);
    assert.equal(result3.totalCount, 3);
    assert.deepEqual(result3.items, expected.slice(2, 3));

    const result4 = await client.getPlaylistItems(0, columns, '4:4');
    assert.equal(result4.offset, 3);
    assert.equal(result4.totalCount, 3);
    assert.deepEqual(result4.items, []);
});

q.test('add playlist simple', async assert =>
{
    await client.addPlaylist();

    const playlists = await client.getPlaylists();
    assert.equal(playlists.length, 2);

    const playlist = playlists[1];
    assert.equal(typeof playlist.id, 'string');
    delete playlist.id;

    assert.deepEqual(playlist, {
        index: 1,
        title: 'New playlist',
        isCurrent: false,
        itemCount: 0,
        totalTime: 0,
    });
});

q.test('add playlist full', async assert =>
{
    await client.addPlaylist({ title: 'My playlist', index: 0 });

    const playlists = await client.getPlaylists();
    assert.equal(playlists.length, 2);

    const playlist = playlists[0];
{'fraction_non_alphanumeric': 0.15022091310751104, 'fraction_numerical': 0.01914580265095729, 'mean_word_length': 3.362955032119914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2347223', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1278, 'n_words': 292}