summaryrefslogtreecommitdiff
path: root/spec/javascripts/serverless/store/mutations_spec.js
blob: ca3053e5c384fe6d2e9df56e6bc42bf55d739800 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import mutations from '~/serverless/store/mutations';
import * as types from '~/serverless/store/mutation_types';
import { mockServerlessFunctions, mockMetrics } from '../mock_data';

describe('ServerlessMutations', () => {
  describe('Functions List Mutations', () => {
    it('should ensure loading is true', () => {
      const state = {};

      mutations[types.REQUEST_FUNCTIONS_LOADING](state);

      expect(state.isLoading).toEqual(true);
    });

    it('should set proper state once functions are loaded', () => {
      const state = {};

      mutations[types.RECEIVE_FUNCTIONS_SUCCESS](state, mockServerlessFunctions);

      expect(state.isLoading).toEqual(false);
      expect(state.hasFunctionData).toEqual(true);
      expect(state.functions).toEqual(mockServerlessFunctions);
    });

    it('should ensure loading has stopped and hasFunctionData is false when there are no functions available', () => {
      const state = {};

      mutations[types.RECEIVE_FUNCTIONS_NODATA_SUCCESS](state);

      expect(state.isLoading).toEqual(false);
      expect(state.hasFunctionData).toEqual(false);
      expect(state.functions).toBe(undefined);
    });

    it('should ensure loading has stopped, and an error is raised', () => {
      const state = {};

      mutations[types.RECEIVE_FUNCTIONS_ERROR](state, 'sample error');

      expect(state.isLoading).toEqual(false);
      expect(state.hasFunctionData).toEqual(false);
      expect(state.functions).toBe(undefined);
      expect(state.error).not.toBe(undefined);
    });
  });

  describe('Function Details Metrics Mutations', () => {
    it('should ensure isLoading and hasPrometheus data flags indicate data is loaded', () => {
      const state = {};

      mutations[types.RECEIVE_METRICS_SUCCESS](state, mockMetrics);

      expect(state.isLoading).toEqual(false);
      expect(state.hasPrometheusData).toEqual(true);
      expect(state.graphData).toEqual(mockMetrics);
    });

    it('should ensure isLoading and hasPrometheus data flags are cleared indicating no functions available', () => {
      const state = {};

      mutations[types.RECEIVE_METRICS_NODATA_SUCCESS](state);

      expect(state.isLoading).toEqual(false);
      expect(state.hasPrometheusData).toEqual(false);
      expect(state.graphData).toBe(undefined);
    });

    it('should properly indicate an error', () => {
      const state = {};

      mutations[types.RECEIVE_METRICS_ERROR](state, 'sample error');

      expect(state.hasPrometheusData).toEqual(false);
      expect(state.error).not.toBe(undefined);
    });

    it('should properly indicate when prometheus is installed', () => {
      const state = {};

      mutations[types.RECEIVE_METRICS_NO_PROMETHEUS](state);

      expect(state.hasPrometheus).toEqual(false);
      expect(state.hasPrometheusData).toEqual(false);
    });
  });
});