From a97b94640e6f653ff358e1e4ba975187c825d2a4 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 5 Feb 2017 16:58:58 +0100 Subject: [PATCH] writing test for pasteId function --- js/test.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/js/test.js b/js/test.js index 58a7fdbb..000362c5 100644 --- a/js/test.js +++ b/js/test.js @@ -1,7 +1,13 @@ 'use strict'; var jsc = require('jsverify'), jsdom = require('jsdom-global'), - cleanup = jsdom(); + cleanup = jsdom(), + + a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m', + 'n','o','p','q','r','s','t','u','v','w','x','y','z'], + alnumString = a2zString.concat(['0','1','2','3','4','5','6','7','8','9']), + queryString = alnumString.concat(['+','%','&','.','*','-','_']); + global.$ = global.jQuery = require('./jquery-3.1.1'); global.sjcl = require('./sjcl-1.0.6'); global.Base64 = require('./base64-2.1.9'); @@ -56,13 +62,6 @@ describe('helper', function () { }); describe('scriptLocation', function () { - after(function () { - cleanup(); - }); - - var a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'], - alnumString = a2zString.concat(['0','1','2','3','4','5','6','7','8','9']), - queryString = alnumString.concat(['+','%','&','.','*','-','_']); jsc.property( 'returns the URL without query & fragment', jsc.nearray(jsc.elements(a2zString)), @@ -78,5 +77,25 @@ describe('helper', function () { } ); }); + + describe('pasteId', function () { + jsc.property( + 'returns the query string without separator, if any', + jsc.nearray(jsc.elements(a2zString)), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + 'string', + function (schema, address, query, fragment) { + var query = query.join(''), + clean = jsdom('', { + url: schema.join('') + '://' + address.join('') + + '/?' + query + '#' + fragment + }), + result = $.PrivateBin.helper.pasteId(); + clean(); + return query === result; + } + ); + }); });