summaryrefslogtreecommitdiffstats
path: root/test/utils/Routes.test.js
diff options
context:
space:
mode:
authorSteven Thomas <steve.thomas@amdocs.com>2018-09-13 16:22:40 -0400
committerSteven Thomas <steve.thomas@amdocs.com>2018-09-13 16:23:05 -0400
commit96319fec0d2af2be5802a56d6b05a3ada939c8df (patch)
tree630e87f62fbbebcded761bf3e67d0f3eb5b78598 /test/utils/Routes.test.js
parentd1975c8134f0401b0ccebf3719eda129d53dac14 (diff)
increasing test coverage to 20 percent
Issue-ID: AAI-1599 Change-Id: I345e38d4319e52b56de0a33d7065e02617cc2103 Signed-off-by: Steven Thomas <steve.thomas@amdocs.com>
Diffstat (limited to 'test/utils/Routes.test.js')
-rw-r--r--test/utils/Routes.test.js129
1 files changed, 129 insertions, 0 deletions
diff --git a/test/utils/Routes.test.js b/test/utils/Routes.test.js
new file mode 100644
index 0000000..12d318c
--- /dev/null
+++ b/test/utils/Routes.test.js
@@ -0,0 +1,129 @@
+import {
+ buildRouteObjWithHash,
+ decryptParamsForView,
+ buildRouteObjWithFilters,
+ changeUrlAddress
+} from 'utils/Routes.js';
+import {
+ encrypt
+} from 'utils/Crypto.js';
+
+describe('Routes', () => {
+ it('build route with hash', () => {
+ const expectedResult = {
+ route: '/vnfSearch',
+ hashId: 'someCrazyHashHere'
+ };
+
+ const result = buildRouteObjWithHash(expectedResult.route, expectedResult.hashId);
+
+ expect(JSON.stringify(result)).toBe(JSON.stringify(expectedResult));
+ });
+
+ it('decrypt params for view', () => {
+ const stringToEncrypt = 'someCrazyStringHere';
+ const encryptedString = encrypt(stringToEncrypt);
+ const result = decryptParamsForView(encryptedString);
+
+ expect(JSON.stringify(result)).toBe(JSON.stringify({}));
+ });
+
+ it('decrypt params for view with obj', () => {
+ const objToEncrypt = [{id: 'someCrazyParamHere'}, {id: 'anotherCrazyParam'}];
+ const encryptedObj = encrypt(JSON.stringify(objToEncrypt));
+ const result = decryptParamsForView(encryptedObj);
+
+ expect(JSON.stringify(result)).toBe(JSON.stringify(objToEncrypt));
+ });
+
+ it('build routes with filters', () => {
+ const objToEncrypt = [{id: 'someCrazyParamHere'}, {id: 'anotherCrazyParam'}];
+ const encryptedObj = encrypt(JSON.stringify(objToEncrypt));
+ const result = decryptParamsForView(encryptedObj);
+
+ expect(JSON.stringify(result)).toBe(JSON.stringify(objToEncrypt));
+ const filterObj = {
+ filter1: 'value1',
+ filter2: undefined,
+ filter3: 'anotherValue'
+ };
+ const routePath = '/vnfSearch';
+ const expectedResults = {
+ route: routePath,
+ filterValues: [
+ {
+ filterId: 'filter1',
+ filterValue: 'value1'
+ },
+ {
+ filterId: 'filter2',
+ filterValue: ''
+ },
+ {
+ filterId: 'filter3',
+ filterValue: 'anotherValue'
+ }
+ ]
+ }
+
+ const routeWithFilters = buildRouteObjWithFilters(routePath, filterObj);
+
+ expect(JSON.stringify(routeWithFilters)).toBe(JSON.stringify(expectedResults));
+ });
+
+ it('change URL address for well known paths', () => {
+ const pathObj = {
+ route: 'schema',
+ filterValues: [
+ {
+ filterId: 'filter1',
+ filterValue: 'value1'
+ },
+ {
+ filterId: 'filter2',
+ filterValue: undefined
+ },
+ {
+ filterId: 'filter3',
+ filterValue: 'anotherValue'
+ }
+ ]
+ };
+ let historyObj = [];
+ const filterList = [
+ 'filter1=value1',
+ 'filter2=',
+ 'filter3=anotherValue'
+ ];
+ const toGo = '/' + pathObj.route + '/' + filterList.toString();
+ const expectedResult = [
+ toGo,
+ {
+ lastRoute: pathObj.route
+ }
+ ];
+
+ changeUrlAddress(pathObj, historyObj);
+
+ expect(JSON.stringify(historyObj)).toBe(JSON.stringify(expectedResult));
+ });
+
+ it('change URL address for well known paths with hash id', () => {
+ const pathObj = {
+ route: 'schema',
+ hashId: 'someCrazyHashIdHere'
+ };
+ let historyObj = [];
+ const toGo = '/' + pathObj.route + '/' + pathObj.hashId;
+ const expectedResult = [
+ toGo,
+ {
+ lastRoute: pathObj.route
+ }
+ ];
+
+ changeUrlAddress(pathObj, historyObj);
+
+ expect(JSON.stringify(historyObj)).toBe(JSON.stringify(expectedResult));
+ });
+})