From 29822599d62ce43b8ed15b8c2fca1210725b235c Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Mon, 10 Jun 2019 11:15:49 -0400 Subject: [PATCH] [DEV-5492] Add basic tests for UserSession.js --- test/server/request/UserSessionTest.js | 156 +++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 test/server/request/UserSessionTest.js diff --git a/test/server/request/UserSessionTest.js b/test/server/request/UserSessionTest.js new file mode 100644 index 0000000..b727989 --- /dev/null +++ b/test/server/request/UserSessionTest.js @@ -0,0 +1,156 @@ +/** + * Manages DataAPI requests and return data + * + * Copyright (C) 2019 R-T Specialty, LLC. + * + * This file is part of the Liza Data Collection Framework. + * + * liza is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +'use strict'; + +const { Class } = require( 'easejs' ); +const { expect } = require( 'chai' ); +const Sut = require( '../../../' ).server.request.UserSession; + + +describe( 'UserSession', () => +{ + [ + { + session: null, + expects: {}, + }, + { + session: "", + expects: {}, + }, + { + session: 'foo|s:1:"a";', + expects: { "foo": "a" }, + }, + { + session: 'foo|a:1:{i:0;s:1:"a";}', + expects: { "foo": { "0": "a" } }, + }, + { + session: 'foo|a:1:{i:0;s:1:"a";}|bar|a:1:{s:1:"a";i:1;}', + expects: { "foo": { "0": "a" }, "bar": { "a": 1 } }, + }, + ].forEach( ( data ) => + { + it( "getData", () => + { + let sut = new Sut( + 1, + { + "get": function( sesion_key, callback ) + { + return callback( data.session ); + }, + } + ); + + expect( + sut.getData() + ).to.deep.equal( data.expects ); + } ); + } ); + + + [ + { + session: null, + expects: false, + }, + { + session: "", + expects: false, + }, + { + session: 'foo|s:1:"a";', + expects: false, + }, + { + session: 'agentID|s:0:"";}', + expects: true, + }, + { + session: 'agentID|s:1:"1";}', + expects: true, + }, + ].forEach( ( data ) => + { + it( "isLoggedIn", () => + { + let sut = new Sut( + 1, + { + "get": function( sesion_key, callback ) + { + return callback( data.session ); + }, + } + ); + + expect( + sut.isLoggedIn() + ).to.be.equal( data.expects ); + } ); + } ); + + + [ + { + session: null, + expects: undefined, + }, + { + session: "", + expects: undefined, + }, + { + session: 'foo|s:1:"a";', + expects: undefined, + }, + { + session: 'agentID|s:0:"";}', + expects: undefined, + }, + { + session: 'agentID|s:1:"1";}', + expects: "1", + }, + ].forEach( ( data ) => + { + it( "agentId", () => + { + let sut = new Sut( + 1, + { + "get": function( sesion_key, callback ) + { + return callback( data.session ); + }, + } + ); + + expect( + sut.agentId() + ).to.be.equal( data.expects ); + } ); + } ); +} ); +