<NME> index.spec.js
<BEF> /*!
 * Module dependencies.
 */

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

/*!
 * Specification.
 */

describe('phonegap-plugin-contentsync', function() {
    beforeEach(function() {
        options = { src: 'http://path/to/src.zip', id: 'app-1' };
        execWin = jasmine.createSpy();
        execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
    });

    describe('.sync', function() {
        it('should require the options parameter', function() {
            expect(function() {
                options = undefined;
                contentSync.sync(options);
            }).toThrow();
            expect(execSpy).not.toHaveBeenCalled();
        });

        it('should require the options.src parameter for merge/replace', function() {
            expect(function() {
                options.src = undefined;
                contentSync.sync(options);
            }).toThrow();
            expect(execSpy).not.toHaveBeenCalled();
        });

        it('should not require the options.src parameter for local', function() {
            expect(function() {
                options.src = undefined;
                options.src = "local";
                contentSync.sync(options);
            }).not.toThrow();
            expect(execSpy).not.toHaveBeenCalled();
        });

        it('should require the options.id parameter', function() {
            expect(function() {
                options.id = undefined;
                contentSync.sync(options);
            }).toThrow();
            expect(execSpy).not.toHaveBeenCalled();
        });

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

    describe('.loadUrl', function() {
      it('should raise an error if url is not provided', function() {
        expect(function() {
          contentSync.loadUrl(null);
        }).toThrow();
      });

    });

    describe('ContentSync instance', function() {
        describe('cordova.exec', function() {
            it('should call cordova.exec on next process tick', function(done) {
                contentSync.sync(options);
                setTimeout(function() {
                    expect(execSpy).toHaveBeenCalledWith(
                        jasmine.any(Function),
                        jasmine.any(Function),
                        'Sync',
            expect(function(){ contentSync.sync( { nimbly: 'bimbly' } ); }).toThrow(new Error('An options object with a src property is needed'));
            expect(execSpy).not.toHaveBeenCalled();
        });

    });
});
                });

                it('should be passed as whatever we specify', function(done) {
                    options.type = 'superduper';
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[2]).toEqual(options.type);
                        done();
                    });
                    contentSync.sync(options);
                });
            });

            describe('options.headers', function() {
                it('should default to null', function(done) {
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[3]).toEqual(null);
                        done();
                    });
                    contentSync.sync(options);
                });

                it('should be passed as whatever we specify', function(done) {
                    options.headers = { 'Authorization': 'SECRET_PASSWORD' };
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[3]).toEqual(options.headers);
                        done();
                    });
                    contentSync.sync(options);
                });
            });

            describe('options.copyCordovaAssets', function() {
                it('should default to false', function(done) {
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[4]).toEqual(false);
                        done();
                    });
                    contentSync.sync(options);
                });
                it('should be passed as whatever we specify', function(done) {
                    options.copyCordovaAssets = true;
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[4]).toEqual(options.copyCordovaAssets);
                        done();
                    });
                    contentSync.sync(options);
                });
            });

            describe('options.copyRootApp', function() {
                it('should default to false', function(done) {
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[5]).toEqual(false);
                        done();
                    });
                    contentSync.sync(options);
                });
                it('should be passed as whatever we specify', function(done) {
                    options.copyRootApp = true;
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[5]).toEqual(options.copyRootApp);
                        done();
                    });
                    contentSync.sync(options);
                });
            });
            describe('options.timeout', function() {
                it('should default to 15.0', function(done) {
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[6]).toEqual(15.0);
                        done();
                    });
                    contentSync.sync(options);
                });
                it('should be passed as whatever we specify', function(done) {
                    options.timeout = 30.0;
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[6]).toEqual(options.timeout);
                        done();
                    });
                    contentSync.sync(options);
                });
            });
            describe('options.trustHost', function() {
                it('should default to false', function(done) {
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[7]).toEqual(false);
                        done();
                    });
                    contentSync.sync(options);
                });
                it('should be passed as whatever we specify', function(done) {
                    options.trustHost = true;
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[7]).toEqual(options.trustHost);
                        done();
                    });
                    contentSync.sync(options);
                });
            });
            describe('options.manifest', function() {
                it('should default to the empty string', function(done) {
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[8]).toEqual("");
                        done();
                    });
                    contentSync.sync(options);
                });
                it('should be passed as whatever we specify', function(done) {
                    options.manifest = "manifest.json";
                    execSpy.andCallFake(function(win, fail, service, id, args) {
                        expect(args[8]).toEqual(options.manifest);
                        done();
                    });
                    contentSync.sync(options);
                });
            });
        });

        describe('on "progress" event', function() {
            it('should be emitted with an argument', function(done) {
                execSpy.andCallFake(function(win, fail, service, id, args) {
                    win({ 'progress': 1 });
                });
                var sync = contentSync.sync(options);
                sync.on('progress', function(data) {
                    expect(data.progress).toEqual(1);
                    done();
                });
            });
        });

        describe('on "complete" event', function() {
            beforeEach(function() {
                execSpy.andCallFake(function(win, fail, service, id, args) {
                    win({
                        localPath: 'file:///path/to/content'
                    });
                });
            });

            it('should be emitted on success', function(done) {
                var sync = contentSync.sync(options);
                sync.on('complete', function(data) {
                    done();
                });
            });

            it('should provide the data.localPath argument', function(done) {
                var sync = contentSync.sync(options);
                sync.on('complete', function(data) {
                    expect(data.localPath).toEqual('file:///path/to/content');
                    done();
                });
            });
        });

        describe('on "error" event', function() {
            it('should be emitted with an Error', function(done) {
                execSpy.andCallFake(function(win, fail, service, id, args) {
                    fail('something went wrong');
                });
                var sync = contentSync.sync(options);
                sync.on('error', function(e) {
                    expect(e).toEqual(jasmine.any(Error));
                    expect(e.message).toEqual('something went wrong');
                    done();
                });
            });
        });

        describe('.cancel()', function() {
            it('should delegate to exec', function(done) {
                var sync = contentSync.sync(options);
                sync.cancel();
                setTimeout(function() {
                    expect(execSpy).toHaveBeenCalled();
                    expect(execSpy.callCount).toEqual(2); // 1) sync, 2) cancel
                    expect(execSpy.mostRecentCall.args).toEqual([
                        jasmine.any(Function),
                        jasmine.any(Function),
                        'Sync',
                        'cancel',
                        [ options.id ]
                    ]);
                    done();
                }, 100);
            });

            it('should emit the "cancel" event', function(done) {
                execSpy.andCallFake(function(win, fail, service, id, args) {
                    win();
                });
                var sync = contentSync.sync(options);
                sync.on('cancel', function() {
                    done();
                });
                sync.cancel();
            });
        });
    });

    describe('PROGRESS_STATE enumeration', function() {
        it('should defined 0 as STOPPED', function() {
            expect(contentSync.PROGRESS_STATE[0]).toEqual('STOPPED');
        });

        it('should defined 1 as DOWNLOADING', function() {
            expect(contentSync.PROGRESS_STATE[1]).toEqual('DOWNLOADING');
        });

        it('should defined 2 as EXTRACTING', function() {
            expect(contentSync.PROGRESS_STATE[2]).toEqual('EXTRACTING');
        });

        it('should defined 3 as COMPLETE', function() {
            expect(contentSync.PROGRESS_STATE[3]).toEqual('COMPLETE');
        });
    });
});

<MSG> [#3] - added cancel tests

<DFF> @@ -80,6 +80,35 @@ describe('phonegap-plugin-contentsync', 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(
+                [ null, null, 'Sync', 'cancel', [] ]
+            );
+        });
+    });
 
+    describe('.on', function(){
+        beforeEach(function() {
+            execWin = jasmine.createSpy(function() { return { result : { progressLength: 1} } });
+            execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
+        });
+        
+        it('should fire the publish the complete event when sync is complete', function(){
+            var sync = contentSync.sync({ src: 'dummySrc' });   
+            var completeWin = function(){ console.log('i win') };
+            //sync.on('complete', completeWin);
+            //expect(completeWin).toHaveBeenCalled();
+        });
     });
 });

{'commit': "diff --git a/spec/index.spec.js b/spec/index.spec.js\nindex 82642a4..a210f8f 100644\n--- a/spec/index.spec.js\n+++ b/spec/index.spec.js\n@@ -80,6 +80,35 @@ describe('phonegap-plugin-contentsync', function() {\n             expect(function(){ contentSync.sync( { nimbly: 'bimbly' } ); }).toThrow(new Error('An options object with a src property is needed'));\n             expect(execSpy).not.toHaveBeenCalled();\n         });\n+    });\n+\n+    describe('.cancel', function(){\n+         beforeEach(function() {\n+            execSpy = spyOn(cordova.required, 'cordova/exec');\n+        });\n+\n+        it('should delegate to exec', function(){\n+            var sync = contentSync.sync({ src: 'dummySrc' });\n+            sync.cancel();\n+            expect(execSpy).toHaveBeenCalled();\n+            expect(execSpy.callCount).toEqual(2);\n+            expect(execSpy.mostRecentCall.args).toEqual(\n+                [ null, null, 'Sync', 'cancel', [] ]\n+            );\n+        });\n+    });\n \n+    describe('.on', function(){\n+        beforeEach(function() {\n+            execWin = jasmine.createSpy(function() { return { result : { progressLength: 1} } });\n+            execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);\n+        });\n+        \n+        it('should fire the publish the complete event when sync is complete', function(){\n+            var sync = contentSync.sync({ src: 'dummySrc' });   \n+            var completeWin = function(){ console.log('i win') };\n+            //sync.on('complete', completeWin);\n+            //expect(completeWin).toHaveBeenCalled();\n+        });\n     });\n });\n", 'commit_subject': '[#3] - added cancel tests', 'repo_name': 'phonegap/phonegap-plugin-contentsync', 'committer': {'name': 'timkim', 'email': '665f298d3acc58ffb898f6d782259c5391564f3b@adobe.com', 'time_sec': '1419032139', 'tz_offset': '-480', 'date': {'seconds': '1419032139'}}, 'commit_tree': 'f7d1d991b62d320f04700da5dc6fafc51f21d05f', 'commit_message': '[#3] - added cancel tests\n', 'language_name': 'C#', 'license': 'apache-2.0', 'hunks': "@@ -80,6 +80,35 @@ describe('phonegap-plugin-contentsync', function() {\n             expect(function(){ contentSync.sync( { nimbly: 'bimbly' } ); }).toThrow(new Error('An options object with a src property is needed'));\n             expect(execSpy).not.toHaveBeenCalled();\n         });\n+    });\n+\n+    describe('.cancel', function(){\n+         beforeEach(function() {\n+            execSpy = spyOn(cordova.required, 'cordova/exec');\n+        });\n+\n+        it('should delegate to exec', function(){\n+            var sync = contentSync.sync({ src: 'dummySrc' });\n+            sync.cancel();\n+            expect(execSpy).toHaveBeenCalled();\n+            expect(execSpy.callCount).toEqual(2);\n+            expect(execSpy.mostRecentCall.args).toEqual(\n+                [ null, null, 'Sync', 'cancel', [] ]\n+            );\n+        });\n+    });\n \n+    describe('.on', function(){\n+        beforeEach(function() {\n+            execWin = jasmine.createSpy(function() { return { result : { progressLength: 1} } });\n+            execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);\n+        });\n+        \n+        it('should fire the publish the complete event when sync is complete', function(){\n+            var sync = contentSync.sync({ src: 'dummySrc' });   \n+            var completeWin = function(){ console.log('i win') };\n+            //sync.on('complete', completeWin);\n+            //expect(completeWin).toHaveBeenCalled();\n+        });\n     });\n });\n", 'addition_count': 29, 'deletion_count': 0, 'src_file': 'a/spec/index.spec.js', 'tgt_file': 'b/spec/index.spec.js', 'file_extension': '.js', 'before_file': '/*!\n * Module dependencies.\n */\n\nvar cordova = require(\'./helper/cordova\'),\n    contentSync = require(\'../www\'),\n    execSpy,\n    execWin,\n    options;\n\n/*!\n * Specification.\n */\n\ndescribe(\'phonegap-plugin-contentsync\', function() {\n    beforeEach(function() {\n        options = { src: \'http://path/to/src.zip\', id: \'app-1\' };\n        execWin = jasmine.createSpy();\n        execSpy = spyOn(cordova.required, \'cordova/exec\').andCallFake(execWin);\n    });\n\n    describe(\'.sync\', function() {\n        it(\'should require the options parameter\', function() {\n            expect(function() {\n                options = undefined;\n                contentSync.sync(options);\n            }).toThrow();\n            expect(execSpy).not.toHaveBeenCalled();\n        });\n\n        it(\'should require the options.src parameter for merge/replace\', function() {\n            expect(function() {\n                options.src = undefined;\n                contentSync.sync(options);\n            }).toThrow();\n            expect(execSpy).not.toHaveBeenCalled();\n        });\n\n        it(\'should not require the options.src parameter for local\', function() {\n            expect(function() {\n                options.src = undefined;\n                options.src = "local";\n                contentSync.sync(options);\n            }).not.toThrow();\n            expect(execSpy).not.toHaveBeenCalled();\n        });\n\n        it(\'should require the options.id parameter\', function() {\n            expect(function() {\n                options.id = undefined;\n                contentSync.sync(options);\n            }).toThrow();\n            expect(execSpy).not.toHaveBeenCalled();\n        });\n\n        it(\'should return an instance of ContentSync\', function() {\n            var sync = contentSync.sync(options);\n            expect(sync).toEqual(jasmine.any(contentSync.ContentSync));\n        });\n    });\n\n    describe(\'.loadUrl\', function() {\n      it(\'should raise an error if url is not provided\', function() {\n        expect(function() {\n          contentSync.loadUrl(null);\n        }).toThrow();\n      });\n\n    });\n\n    describe(\'ContentSync instance\', function() {\n        describe(\'cordova.exec\', function() {\n            it(\'should call cordova.exec on next process tick\', function(done) {\n                contentSync.sync(options);\n                setTimeout(function() {\n                    expect(execSpy).toHaveBeenCalledWith(\n                        jasmine.any(Function),\n                        jasmine.any(Function),\n                        \'Sync\',\n            expect(function(){ contentSync.sync( { nimbly: \'bimbly\' } ); }).toThrow(new Error(\'An options object with a src property is needed\'));\n            expect(execSpy).not.toHaveBeenCalled();\n        });\n\n    });\n});\n                });\n\n                it(\'should be passed as whatever we specify\', function(done) {\n                    options.type = \'superduper\';\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[2]).toEqual(options.type);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n            });\n\n            describe(\'options.headers\', function() {\n                it(\'should default to null\', function(done) {\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[3]).toEqual(null);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n\n                it(\'should be passed as whatever we specify\', function(done) {\n                    options.headers = { \'Authorization\': \'SECRET_PASSWORD\' };\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[3]).toEqual(options.headers);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n            });\n\n            describe(\'options.copyCordovaAssets\', function() {\n                it(\'should default to false\', function(done) {\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[4]).toEqual(false);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n                it(\'should be passed as whatever we specify\', function(done) {\n                    options.copyCordovaAssets = true;\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[4]).toEqual(options.copyCordovaAssets);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n            });\n\n            describe(\'options.copyRootApp\', function() {\n                it(\'should default to false\', function(done) {\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[5]).toEqual(false);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n                it(\'should be passed as whatever we specify\', function(done) {\n                    options.copyRootApp = true;\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[5]).toEqual(options.copyRootApp);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n            });\n            describe(\'options.timeout\', function() {\n                it(\'should default to 15.0\', function(done) {\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[6]).toEqual(15.0);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n                it(\'should be passed as whatever we specify\', function(done) {\n                    options.timeout = 30.0;\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[6]).toEqual(options.timeout);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n            });\n            describe(\'options.trustHost\', function() {\n                it(\'should default to false\', function(done) {\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[7]).toEqual(false);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n                it(\'should be passed as whatever we specify\', function(done) {\n                    options.trustHost = true;\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[7]).toEqual(options.trustHost);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n            });\n            describe(\'options.manifest\', function() {\n                it(\'should default to the empty string\', function(done) {\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[8]).toEqual("");\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n                it(\'should be passed as whatever we specify\', function(done) {\n                    options.manifest = "manifest.json";\n                    execSpy.andCallFake(function(win, fail, service, id, args) {\n                        expect(args[8]).toEqual(options.manifest);\n                        done();\n                    });\n                    contentSync.sync(options);\n                });\n            });\n        });\n\n        describe(\'on "progress" event\', function() {\n            it(\'should be emitted with an argument\', function(done) {\n                execSpy.andCallFake(function(win, fail, service, id, args) {\n                    win({ \'progress\': 1 });\n                });\n                var sync = contentSync.sync(options);\n                sync.on(\'progress\', function(data) {\n                    expect(data.progress).toEqual(1);\n                    done();\n                });\n            });\n        });\n\n        describe(\'on "complete" event\', function() {\n            beforeEach(function() {\n                execSpy.andCallFake(function(win, fail, service, id, args) {\n                    win({\n                        localPath: \'file:///path/to/content\'\n                    });\n                });\n            });\n\n            it(\'should be emitted on success\', function(done) {\n                var sync = contentSync.sync(options);\n                sync.on(\'complete\', function(data) {\n                    done();\n                });\n            });\n\n            it(\'should provide the data.localPath argument\', function(done) {\n                var sync = contentSync.sync(options);\n                sync.on(\'complete\', function(data) {\n                    expect(data.localPath).toEqual(\'file:///path/to/content\');\n                    done();\n                });\n            });\n        });\n\n        describe(\'on "error" event\', function() {\n            it(\'should be emitted with an Error\', function(done) {\n                execSpy.andCallFake(function(win, fail, service, id, args) {\n                    fail(\'something went wrong\');\n                });\n                var sync = contentSync.sync(options);\n                sync.on(\'error\', function(e) {\n                    expect(e).toEqual(jasmine.any(Error));\n                    expect(e.message).toEqual(\'something went wrong\');\n                    done();\n                });\n            });\n        });\n\n        describe(\'.cancel()\', function() {\n            it(\'should delegate to exec\', function(done) {\n                var sync = contentSync.sync(options);\n                sync.cancel();\n                setTimeout(function() {\n                    expect(execSpy).toHaveBeenCalled();\n                    expect(execSpy.callCount).toEqual(2); // 1) sync, 2) cancel\n                    expect(execSpy.mostRecentCall.args).toEqual([\n                        jasmine.any(Function),\n                        jasmine.any(Function),\n                        \'Sync\',\n                        \'cancel\',\n                        [ options.id ]\n                    ]);\n                    done();\n                }, 100);\n            });\n\n            it(\'should emit the "cancel" event\', function(done) {\n                execSpy.andCallFake(function(win, fail, service, id, args) {\n                    win();\n                });\n                var sync = contentSync.sync(options);\n                sync.on(\'cancel\', function() {\n                    done();\n                });\n                sync.cancel();\n            });\n        });\n    });\n\n    describe(\'PROGRESS_STATE enumeration\', function() {\n        it(\'should defined 0 as STOPPED\', function() {\n            expect(contentSync.PROGRESS_STATE[0]).toEqual(\'STOPPED\');\n        });\n\n        it(\'should defined 1 as DOWNLOADING\', function() {\n            expect(contentSync.PROGRESS_STATE[1]).toEqual(\'DOWNLOADING\');\n        });\n\n        it(\'should defined 2 as EXTRACTING\', function() {\n            expect(contentSync.PROGRESS_STATE[2]).toEqual(\'EXTRACTING\');\n        });\n\n        it(\'should defined 3 as COMPLETE\', function() {\n            expect(contentSync.PROGRESS_STATE[3]).toEqual(\'COMPLETE\');\n        });\n    });\n});\n', 'message': '[#3] - added cancel tests\n', 'author_name': 'timkim', 'lang': 'spec'}