summaryrefslogtreecommitdiffstats
path: root/test/utils/KeyMirror.test.js
blob: 22f6ff581a8e9621f767cdcb081af46e27aa80c2 (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
import keyMirror from 'utils/KeyMirror.js';

describe('KeyMirror', () => {
  it('valid key mirror with nulls', () => {
    const obj = {
      TIER_SUPPORT: null,
      INVENTORY: null,
      VNF_SEARCH: null
    }
    const mirror = keyMirror(obj);

    for (let key in obj) {
      expect(mirror).toHaveProperty(key);
      expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(Symbol(key)));
    }
  });

  it('valid key mirror with undefined', () => {
    const obj = {
      TIER_SUPPORT: undefined,
      INVENTORY: undefined,
      VNF_SEARCH: undefined
    }
    const mirror = keyMirror(obj);

    for (let key in obj) {
      expect(mirror).toHaveProperty(key);
      expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(Symbol(key)));
    }
  });

  it('valid key mirror with values', () => {
    let preMirrorList = {
      TIER_SUPPORT: 'tier support',
      INVENTORY: 'inventory',
      VNF_SEARCH: 'vnf search'
    };
    const mirror = keyMirror(preMirrorList);

    for (let key in preMirrorList) {
      expect(mirror).toHaveProperty(key);
      expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(preMirrorList[key]));
    }
  });

  it('valid key mirror with objects', () => {
    let preMirrorList = {
      TIER_SUPPORT: {
        name: 'tier support'
      },
      INVENTORY: {
        name: 'inventory'
      },
      VNF_SEARCH: {
        name: 'vnf search'
      }
    };
    const mirror = keyMirror(preMirrorList);

    for (let key in preMirrorList) {
      expect(mirror).toHaveProperty(key);
      expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(preMirrorList[key]));
    }
  });

  it('invalid key mirror', () => {
    let preMirrorList = [
      'tier support',
      'inventory',
      'vnf search'
    ]
    const mirror = () => {
      keyMirror(preMirrorList);
    }

    expect(mirror).toThrow(Error);
    expect(mirror).toThrowError('keyMirror(...): Argument must be an object.');
  });
})