<commit_before>import {Spotilocal, SPOTILOCAL_IS_NOT_INITIALIZED} from '../src/index';
import {assert} from 'chai';

describe('#init()', function () {
    this.timeout(10000);
    it('should init spotilocal', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.init().then(() => { done(); }).catch(done);
    });
});

describe('#getStatus()', function () {
    this.timeout(10000);
    it('should fail if not initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.getStatus().then(() => {
            done('Should have failed');
        }).catch((error) => {
            assert.strictEqual(error, SPOTILOCAL_IS_NOT_INITIALIZED);
            done();
        }).catch((error) => {
            done(error);
        });
    });

    it('should get status from spotilocal if initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.init().then((spotilocal) => {
            return spotilocal.getStatus()
        }).then((status) => {
            done();
        }).catch(done);
    });
});

describe('#pause()', function () {
    this.timeout(10000);
    it('should fail if not initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.pause(true).then(() => {
            done('Should have failed');
        }).catch((error) => {
            assert.strictEqual(error, SPOTILOCAL_IS_NOT_INITIALIZED);
            done();
        }).catch((error) => {
            done(error);
        });
    });

    it('should get status from spotilocal if initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.init().then((spotilocal) => {
            return spotilocal.pause(true)
        }).then((status) => {
            done();
        }).catch(done);
    });
});<commit_msg>added tests for play()<commit_after>import {Spotilocal, SPOTILOCAL_IS_NOT_INITIALIZED} from '../src/index';
import {assert} from 'chai';

describe('#init()', function () {
    this.timeout(10000);
    it('should init spotilocal', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.init().then(() => { done(); }).catch(done);
    });
});

describe('#getStatus()', function () {
    this.timeout(10000);
    it('should fail if not initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.getStatus().then(() => {
            done('Should have failed');
        }).catch((error) => {
            assert.strictEqual(error, SPOTILOCAL_IS_NOT_INITIALIZED);
            done();
        }).catch((error) => {
            done(error);
        });
    });

    it('should get status from spotilocal if initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.init().then((spotilocal) => {
            return spotilocal.getStatus()
        }).then((status) => {
            done();
        }).catch(done);
    });
});

describe('#pause()', function () {
    this.timeout(10000);
    it('should fail if not initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.pause(true).then(() => {
            done('Should have failed');
        }).catch((error) => {
            assert.strictEqual(error, SPOTILOCAL_IS_NOT_INITIALIZED);
            done();
        }).catch((error) => {
            done(error);
        });
    });

    it('should get status from spotilocal if initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.init().then((spotilocal) => {
            return spotilocal.pause(true)
        }).then((status) => {
            done();
        }).catch(done);
    });
});

describe('#play()', function () {
    this.timeout(10000);
    it('should fail if not initialized', function (done) {
        const spotilocal = new Spotilocal();
        spotilocal.play('spotify:track:3cANM3NuUjRDTi8fdU8P6q', 'spotify:user:shyyko.serhiy:playlist:4SdN0Re3tJg9uG08z2Gkr1').then(() => {
            done('Should have failed');
        }).catch((error) => {
            assert.strictEqual(error, SPOTILOCAL_IS_NOT_INITIALIZED);
            done();
        }).catch((error) => {
            done(error);
        });
    });

    it('should play song wihtout context and return correct status', function (done) {
        const spotilocal = new Spotilocal();
        const trackUri = 'spotify:track:53zHrgxt8Xy1RkMWepJVUh';
        spotilocal.init().then((spotilocal) => {
            return spotilocal.play(trackUri)
        }).then((status) => {
            assert.strictEqual(status.playing, true);
            assert.strictEqual(status.track.track_resource.uri, trackUri);
            assert.strictEqual(status.track.track_resource.name, 'Insane');
            done();
        }).catch(done);
    });

    it('should play song in context and return correct status', function (done) {
        const spotilocal = new Spotilocal();
        const trackUri = 'spotify:track:3cANM3NuUjRDTi8fdU8P6q';
        spotilocal.init().then((spotilocal) => {
            return spotilocal.play(trackUri, 'spotify:user:shyyko.serhiy:playlist:4SdN0Re3tJg9uG08z2Gkr1')
        }).then((status) => {
            assert.strictEqual(status.playing, true);
            assert.strictEqual(status.track.track_resource.uri, trackUri);
            assert.strictEqual(status.track.track_resource.name, 'Brother');
            done();
        }).catch(done);
    });
});

describe('#play() and #pause()', function () {
    it('should play song pause it and resume it', function (done) {
        const spotilocal = new Spotilocal();
        const trackUri = 'spotify:track:3cANM3NuUjRDTi8fdU8P6q';
        spotilocal.init().then((spotilocal) => {
            return spotilocal.play(trackUri, 'spotify:user:shyyko.serhiy:playlist:4SdN0Re3tJg9uG08z2Gkr1')
        }).then((status) => {
            assert.strictEqual(status.playing, true);
            assert.strictEqual(status.track.track_resource.uri, trackUri);
            return spotilocal.pause(true);
        }).then((status)=>{
            assert.strictEqual(status.playing, false);
            assert.strictEqual(status.track.track_resource.uri, trackUri);
            return spotilocal.pause(false);            
        }).then((status)=>{
            assert.strictEqual(status.playing, true);
            assert.strictEqual(status.track.track_resource.uri, trackUri);
            done();         
        }).catch(done);
    });
});
{'fraction_non_alphanumeric': 0.1573917064899029, 'fraction_numerical': 0.012024048096192385, 'mean_word_length': 2.4825550187869028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, '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': '1620436', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1922, 'n_words': 355}