'use strict';

'use strict';

const Download = require('../../lib/install/download');
const StateController = require('../../lib/state-controller');
const {fakeKiteInstallPaths} = require('../spec-helpers');

describe('Download', () => {
  let step, promise;

  fakeKiteInstallPaths();

  describe('when the download succeeds', () => {
    beforeEach(() => {
      step = new Download();
      spyOn(StateController, 'downloadKiteRelease')
      .andCallFake(() => Promise.resolve());
    });

    describe('with a valid email', () => {
      beforeEach(() => {
        promise = step.start();
      });

      it('calls the download method', () => {
        expect(StateController.downloadKiteRelease).toHaveBeenCalled();
      });

      it('returns a promise that resolve when the request succeeds', () => {
        waitsForPromise(() => promise.then(state => {
          expect(state.download.done).toBeTruthy();
        }));
      });
    });
  });

  describe('when the download fails', () => {
    beforeEach(() => {
      step = new Download();
      spyOn(StateController, 'downloadKiteRelease')
        .andCallFake(() => Promise.reject(new Error()));
    });

    describe('with a valid email', () => {
      beforeEach(() => {
        promise = step.start();
      });

      it('calls the download method', () => {
        expect(StateController.downloadKiteRelease).toHaveBeenCalled();
      });

      it('returns a promise that resolve when the request succeeds', () => {
        waitsForPromise({shouldReject: true}, () => promise);

        waitsForPromise(() => promise.catch(err => {
          expect(err.data.download.done).toBeFalsy();
        }));
      });
    });
  });
});

@@ -169,16 +169,27 @@
 allPaths
+, startStep
 %7D = requ
@@ -256,17 +256,8 @@
 step
-, promise
 ;%0A%0A 
@@ -434,23 +434,16 @@
 elease')
-%0A      
 .andCall
@@ -477,807 +477,41 @@
 ));%0A
-    %7D);%0A%0A    describe('with a valid email', () =%3E %7B%0A      beforeEach(() =%3E %7B%0A        promise = step.start();%0A      %7D);%0A%0A      it('calls the download method', () =%3E %7B%0A        expect(StateController.downloadKiteRelease).toHaveBeenCalled();%0A      %7D);%0A%0A      it('returns a promise that resolve when the request succeeds', () =%3E %7B%0A        waitsForPromise(() =%3E promise.then(state =%3E %7B%0A          expect(state.download.done).toBeTruthy(
+%0A      startStep(step
 );%0A    
-  
-  
 %7D)
-)
 ;%0A
-      %7D);%0A    %7D);%0A  %7D);%0A%0A  describe('when the download fails', () =%3E %7B%0A    beforeEach(() =%3E %7B%0A      step = new Download();%0A      spyOn(StateController, 'downloadKiteRelease')%0A        .andCallFake(() =%3E Promise.reject(new Error()));%0A    %7D);%0A%0A    describe('with a valid email', () =%3E %7B%0A      beforeEach(() =%3E %7B%0A        promise = step.start();%0A      %7D);%0A%0A  
+%0A
     
@@ -546,26 +546,24 @@
 d', () =%3E %7B%0A
-  
       expect
@@ -624,289 +624,8 @@
 ();%0A
-      %7D);%0A%0A      it('returns a promise that resolve when the request succeeds', () =%3E %7B%0A        waitsForPromise(%7BshouldReject: true%7D, () =%3E promise);%0A%0A        waitsForPromise(() =%3E promise.catch(err =%3E %7B%0A          expect(err.data.download.done).toBeFalsy();%0A        %7D));%0A      %7D);%0A
     

Fix download tests