summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/pipeline_details_mediator_spec.js
blob: 9fec2f61f7829e0ef4b70999a0c4086097eae6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Vue from 'vue';
import PipelineMediator from '~/pipelines/pipeline_details_mediatior';

describe('PipelineMdediator', () => {
  let mediator;
  beforeEach(() => {
    mediator = new PipelineMediator({ endpoint: 'foo' });
  });

  it('should set defaults', () => {
    expect(mediator.options).toEqual({ endpoint: 'foo' });
    expect(mediator.state.isLoading).toEqual(false);
    expect(mediator.store).toBeDefined();
    expect(mediator.service).toBeDefined();
  });

  describe('request and store data', () => {
    const interceptor = (request, next) => {
      next(request.respondWith(JSON.stringify({ foo: 'bar' }), {
        status: 200,
      }));
    };

    beforeEach(() => {
      Vue.http.interceptors.push(interceptor);
    });

    afterEach(() => {
      Vue.http.interceptors = _.without(Vue.http.interceptor, interceptor);
    });

    it('should store received data', (done) => {
      mediator.fetchPipeline();

      setTimeout(() => {
        expect(mediator.store.state.pipeline).toEqual({ foo: 'bar' });
        done();
      });
    });
  });
});