<commit_before>/*!
 * Module dependencies.
 */

var cordova = require('./helper/cordova'),
    contentSync = require('../www/sync'),
    execSpy,
    execWin;

/*!
 * Sync specification.
 */

describe('phonegap-plugin-contentsync', function() {
    describe('.sync', function() {
        beforeEach(function() {
            execWin = jasmine.createSpy(function() { return { result : { progressLength: 1} } });
            execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
        });

        it('should return an instance of ContentSync', function() {
            var sync = contentSync.sync({ src: 'dummySrc' });
            expect(sync).toEqual(jasmine.any(contentSync.ContentSync));
        });

        it('should delegate to exec', function() {
            var sync = contentSync.sync({ src: 'dummySrc' });

            expect(execSpy).toHaveBeenCalled();
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                jasmine.any(Object)
            );
        });

        it('should fire the success callback with a return value', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            expect(execWin).toHaveBeenCalled();
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                jasmine.any(Object)
            );

        });

        it('should set options.type to "replace" by default', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                ['dummySrc', 'replace']
            );
        });

        it('should set options.type to whatever we specify', function(){
            var sync = contentSync.sync({ src: 'dummySrc', type: 'superduper' });
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                ['dummySrc', 'superduper']
            );
        });

        it('should throw an error when provided with no options and not call exec', function(){
            expect(function(){ contentSync.sync(); }).toThrow(new Error('An options object with a src property is needed'));
            expect(execSpy).not.toHaveBeenCalled();
        });

        it('should throw an error when provided with no options.src and not call exec', function(){
            expect(function(){ contentSync.sync( { nimbly: 'bimbly' } ); }).toThrow(new Error('An options object with a src property is needed'));
            expect(execSpy).not.toHaveBeenCalled();
        });
    });

    describe('.cancel', function(){
         beforeEach(function() {
            execSpy = spyOn(cordova.required, 'cordova/exec');
        });

        it('should delegate to exec', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            sync.cancel();
            expect(execSpy).toHaveBeenCalled();
            expect(execSpy.callCount).toEqual(2);
            expect(execSpy.mostRecentCall.args).toEqual(
                [ jasmine.any(Function), null, 'Sync', 'cancel', [] ]
            );
        });
    });

    describe('.on', function(){
        beforeEach(function() {
            execSpy = spyOn(cordova.required, 'cordova/exec');
        });
        
        it('should fire the complete callback when we publish it', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            var completeWin = jasmine.createSpy(function() { console.log('i win') });
            sync.on('complete', completeWin);
            sync.publish('complete');
            expect(completeWin).toHaveBeenCalled();
        });

        it('should fire the cancel callback when we publish it', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            var cancelCallback = jasmine.createSpy(function() { console.log('i cancel') });
            sync.on('cancel', cancelCallback);
            sync.publish('cancel');
            expect(cancelCallback).toHaveBeenCalled();
        });

        it('should fire the progress callback when we publish it', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            var progressCallback = jasmine.createSpy(function() { console.log('i progress') });
            sync.on('progress', progressCallback);
            sync.publish('progress');
            expect(progressCallback).toHaveBeenCalled();
        });

        it('should fire the error callback when we publish it', function(){<commit_msg>[#3] - added another test case to check for arguments on publish<commit_after>/*!
 * Module dependencies.
 */

var cordova = require('./helper/cordova'),
    contentSync = require('../www/sync'),
    execSpy,
    execWin;

/*!
 * Sync specification.
 */

describe('phonegap-plugin-contentsync', function() {
    describe('.sync', function() {
        beforeEach(function() {
            execWin = jasmine.createSpy(function() { return { result : { progressLength: 1} } });
            execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
        });

        it('should return an instance of ContentSync', function() {
            var sync = contentSync.sync({ src: 'dummySrc' });
            expect(sync).toEqual(jasmine.any(contentSync.ContentSync));
        });

        it('should delegate to exec', function() {
            var sync = contentSync.sync({ src: 'dummySrc' });

            expect(execSpy).toHaveBeenCalled();
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                jasmine.any(Object)
            );
        });

        it('should fire the success callback with a return value', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            expect(execWin).toHaveBeenCalled();
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                jasmine.any(Object)
            );

        });

        it('should set options.type to "replace" by default', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                ['dummySrc', 'replace']
            );
        });

        it('should set options.type to whatever we specify', function(){
            var sync = contentSync.sync({ src: 'dummySrc', type: 'superduper' });
            expect(execSpy).toHaveBeenCalledWith(
                jasmine.any(Function),
                null,
                'Sync',
                'sync',
                ['dummySrc', 'superduper']
            );
        });

        it('should throw an error when provided with no options and not call exec', function(){
            expect(function(){ contentSync.sync(); }).toThrow(new Error('An options object with a src property is needed'));
            expect(execSpy).not.toHaveBeenCalled();
        });

        it('should throw an error when provided with no options.src and not call exec', function(){
            expect(function(){ contentSync.sync( { nimbly: 'bimbly' } ); }).toThrow(new Error('An options object with a src property is needed'));
            expect(execSpy).not.toHaveBeenCalled();
        });
    });

    describe('.cancel', function(){
         beforeEach(function() {
            execSpy = spyOn(cordova.required, 'cordova/exec');
        });

        it('should delegate to exec', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            sync.cancel();
            expect(execSpy).toHaveBeenCalled();
            expect(execSpy.callCount).toEqual(2);
            expect(execSpy.mostRecentCall.args).toEqual(
                [ jasmine.any(Function), null, 'Sync', 'cancel', [] ]
            );
        });
    });

    describe('.on', function(){
        beforeEach(function() {
            execSpy = spyOn(cordova.required, 'cordova/exec');
        });
        
        it('should fire the complete callback when we publish it', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            var completeWin = jasmine.createSpy(function() { console.log('i win') });
            sync.on('complete', completeWin);
            sync.publish('complete');
            expect(completeWin).toHaveBeenCalled();
        });

        it('should fire the cancel callback when we publish it', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            var cancelCallback = jasmine.createSpy(function() { console.log('i cancel') });
            sync.on('cancel', cancelCallback);
            sync.publish('cancel');
            expect(cancelCallback).toHaveBeenCalled();
        });

        it('should fire the progress callback when we publish it', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            var progressCallback = jasmine.createSpy(function() { console.log('i progress') });
            sync.on('progress', progressCallback);
            sync.publish('progress');
            expect(progressCallback).toHaveBeenCalled();
        });

        it('should fire the progress callback with an argument when we publish it with an argument', function(){
            var sync = contentSync.sync({ src: 'dummySrc' });
            var myMsg = 'this is custom';
            var progressCallback = jasmine.createSpy(function( theMsg ) { return theMsg; });
            sync.on('progress', progressCallback);
            sync.publish('progress', myMsg);
            expect(progressCallback).toHaveBeenCalled();
            expect(progressCallback.mostRecentCall.args).toEqual( ['this is custom'] );
        });

        it('should fire the error callback when we publish it', function(){
{'fraction_non_alphanumeric': 0.13644805004398397, 'fraction_numerical': 0.000488710780959828, 'mean_word_length': 1.9970708845928529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6770595', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2583, 'n_words': 626}