import {PromiseBackend} from '../node_modules/deferred/src/PromiseMock';
import {Pipeline} from '../src/pipeline';

describe('Pipeline', () => {
  PromiseBackend.setGlobal(window);
  PromiseBackend.patchWithMock();

  it('should run even when there are not steps', () => {
    var pipeline = new Pipeline();
    var context = {};
    var resolved = false;

    pipeline.run(context).then((result) => {
      expect(result.completed).toBe(true);
    });

    PromiseBackend.flush(true);
  });
});

@@ -215,281 +215,1922 @@
 %0A%0A  
-it('should run even when there are not steps', () =%3E %7B%0A    var pipeline = new Pipeline();%0A    var context
+var pipeline,%0A      spy,%0A      context;%0A%0A  beforeEach(() =%3E %7B%0A    context = %7B%7D;%0A    pipeline = new Pipeline();%0A  %7D);%0A%0A  it('should run even when there are not steps', () =%3E %7B%0A    pipeline.run(context).then((result) =%3E %7B%0A      expect(result.completed).toBe(true);%0A    %7D);%0A%0A    PromiseBackend.flush(true);%0A  %7D);%0A%0A  it('should pass the context to the step', () =%3E %7B%0A    var step = mockStep();%0A    pipeline.withStep(step);%0A    pipeline.run(context).then((result) =%3E %7B%0A      expect(result.completed).toBe(true);%0A    %7D);%0A%0A    expect(step.spy).toHaveBeenCalledWith(context);%0A  %7D);%0A%0A%0A  it('should set the context to incomplete if a step cancels', () =%3E %7B%0A    pipeline.withStep((context) =%3E context.cancel()).%0A    run(context).catch((result) =%3E %7B%0A      expect(result.completed).toBe(false);%0A      expect(result.status).toBe('rejected');%0A    %7D);%0A%0A    PromiseBackend.flush(true);%0A  %7D);%0A%0A%0A  it('should set the context to incomplete if a step throws', () =%3E %7B%0A    pipeline.withStep(() =%3E %7B%0A      throw new Error('oops');%0A    %7D).%0A    run(context).catch((result)
  =
+%3E
  %7B
-%7D;%0A    var resolved = false;%0A%0A    pipeline.run(context).then((result) =%3E %7B%0A      expect(result.completed).toBe(true);%0A    %7D);%0A%0A    PromiseBackend.flush(true);%0A  %7D);
+%0A      expect(result.completed).toBe(false);%0A      expect(result.status).toBe('rejected');%0A    %7D);%0A%0A    PromiseBackend.flush(true);%0A  %7D);%0A%0A%0A  it('should delegate to the next step if the previous one cancels', () =%3E %7B%0A    var firstStep = false;%0A%0A    pipeline.%0A      withStep((context) =%3E %7B%0A        firstStep = true;%0A        return context.next();%0A      %7D).%0A      withStep((context) =%3E context.complete()).%0A      run(context).then((result) =%3E %7B%0A        expect(firstStep).toBe(true);%0A        expect(result.completed).toBe(true);%0A        expect(result.status).toBe('completed');%0A      %7D);%0A%0A    PromiseBackend.flush(true);%0A  %7D);%0A%0A%0A%0A  function mockStep (name) %7B%0A    var spy = jasmine.createSpy(name ? (name + ' step') : 'step');%0A    return %7B%0A      run: (ctx) =%3E %7B%0A        spy(ctx);%0A        return Promise.resolve();%0A      %7D,%0A      name: name,%0A      spy: spy%0A    %7D;%0A  %7D
 %0A%7D);

improve pipeline test