Welcome to mirror list, hosted at ThFree Co, Russian Federation.

instrumentation_link_spec.js « apollo « lib « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef686129257bc16249bc46f3d6ad3427f9582aef (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
42
43
44
45
46
47
48
49
50
51
52
53
54
import { testApolloLink } from 'helpers/test_apollo_link';
import { getInstrumentationLink, FEATURE_CATEGORY_HEADER } from '~/lib/apollo/instrumentation_link';

const TEST_FEATURE_CATEGORY = 'foo_feature';

describe('~/lib/apollo/instrumentation_link', () => {
  const setFeatureCategory = (val) => {
    window.gon.feature_category = val;
  };

  afterEach(() => {
    getInstrumentationLink.cache.clear();
  });

  describe('getInstrumentationLink', () => {
    describe('with no gon.feature_category', () => {
      beforeEach(() => {
        setFeatureCategory(null);
      });

      it('returns null', () => {
        expect(getInstrumentationLink()).toBe(null);
      });
    });

    describe('with gon.feature_category', () => {
      beforeEach(() => {
        setFeatureCategory(TEST_FEATURE_CATEGORY);
      });

      it('returns memoized apollo link', () => {
        const result = getInstrumentationLink();

        // expect.any(ApolloLink) doesn't work for some reason...
        expect(result).toHaveProp('request');
        expect(result).toBe(getInstrumentationLink());
      });

      it('adds a feature category header from the returned apollo link', async () => {
        const defaultHeaders = { Authorization: 'foo' };
        const operation = await testApolloLink(getInstrumentationLink(), {
          context: { headers: defaultHeaders },
        });

        const { headers } = operation.getContext();

        expect(headers).toEqual({
          ...defaultHeaders,
          [FEATURE_CATEGORY_HEADER]: TEST_FEATURE_CATEGORY,
        });
      });
    });
  });
});