[AAI] Remove Robby Maharajh & Harish Kajur as committers
[aai/sparky-fe.git] / test / utils / Routes.test.js
1 import {
2   buildRouteObjWithHash,
3   decryptParamsForView,
4   buildRouteObjWithFilters,
5   changeUrlAddress
6 } from 'utils/Routes.js';
7 import {
8   encrypt
9 } from 'utils/Crypto.js';
10
11 describe('Routes', () => {
12   it('build route with hash', () => {
13     const expectedResult = {
14       route: '/vnfSearch',
15       hashId: 'someCrazyHashHere'
16     };
17
18     const result = buildRouteObjWithHash(expectedResult.route, expectedResult.hashId);
19
20     expect(JSON.stringify(result)).toBe(JSON.stringify(expectedResult));
21   });
22
23   it('decrypt params for view', () => {
24     const stringToEncrypt = 'someCrazyStringHere';
25     const encryptedString = encrypt(stringToEncrypt);
26     const result = decryptParamsForView(encryptedString);
27
28     expect(JSON.stringify(result)).toBe(JSON.stringify({}));
29   });
30
31   it('decrypt params for view with obj', () => {
32     const objToEncrypt = [{id: 'someCrazyParamHere'}, {id: 'anotherCrazyParam'}];
33     const encryptedObj = encrypt(JSON.stringify(objToEncrypt));
34     const result = decryptParamsForView(encryptedObj);
35
36     expect(JSON.stringify(result)).toBe(JSON.stringify(objToEncrypt));
37   });
38
39   it('build routes with filters', () => {
40     const objToEncrypt = [{id: 'someCrazyParamHere'}, {id: 'anotherCrazyParam'}];
41     const encryptedObj = encrypt(JSON.stringify(objToEncrypt));
42     const result = decryptParamsForView(encryptedObj);
43
44     expect(JSON.stringify(result)).toBe(JSON.stringify(objToEncrypt));
45     const filterObj = {
46       filter1: 'value1',
47       filter2: undefined,
48       filter3: 'anotherValue'
49     };
50     const routePath = '/vnfSearch';
51     const expectedResults = {
52       route: routePath,
53       filterValues: [
54         {
55           filterId: 'filter1',
56           filterValue: 'value1'
57         },
58         {
59           filterId: 'filter2',
60           filterValue: ''
61         },
62         {
63           filterId: 'filter3',
64           filterValue: 'anotherValue'
65         }
66       ]
67     }
68
69     const routeWithFilters = buildRouteObjWithFilters(routePath, filterObj);
70
71     expect(JSON.stringify(routeWithFilters)).toBe(JSON.stringify(expectedResults));
72   });
73
74   it('change URL address for well known paths', () => {
75     const pathObj = {
76       route: 'schema',
77       filterValues: [
78         {
79           filterId: 'filter1',
80           filterValue: 'value1'
81         },
82         {
83           filterId: 'filter2',
84           filterValue: undefined
85         },
86         {
87           filterId: 'filter3',
88           filterValue: 'anotherValue'
89         }
90       ]
91     };
92     let historyObj = [];
93     const filterList = [
94       'filter1=value1',
95       'filter2=',
96       'filter3=anotherValue'
97     ];
98     const toGo = '/' + pathObj.route + '/' + filterList.toString();
99     const expectedResult = [
100       toGo,
101       {
102         lastRoute: pathObj.route
103       }
104     ];
105
106     changeUrlAddress(pathObj, historyObj);
107
108     expect(JSON.stringify(historyObj)).toBe(JSON.stringify(expectedResult));
109   });
110
111   it('change URL address for well known paths with hash id', () => {
112     const pathObj = {
113       route: 'schema',
114       hashId: 'someCrazyHashIdHere'
115     };
116     let historyObj = [];
117     const toGo = '/' + pathObj.route + '/' + pathObj.hashId;
118     const expectedResult = [
119       toGo,
120       {
121         lastRoute: pathObj.route
122       }
123     ];
124
125     changeUrlAddress(pathObj, historyObj);
126
127     expect(JSON.stringify(historyObj)).toBe(JSON.stringify(expectedResult));
128   });
129 })