From b045d781f80460890560f3551be026092a134b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=A8=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=B2?= Date: Fri, 17 Nov 2017 19:06:24 +0300 Subject: [PATCH] =?UTF-8?q?Jasmine-=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/limestone.tests.js | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/limestone.tests.js diff --git a/tests/limestone.tests.js b/tests/limestone.tests.js new file mode 100644 index 0000000..b2f8f91 --- /dev/null +++ b/tests/limestone.tests.js @@ -0,0 +1,70 @@ +var SphinxClient = require('../limestone').SphinxClient + +var defaultQueryObject = { + offset : 0, + limit : 20, + mode : 0, // Sphinx.searchMode.ALL + weights : [], + sort : 0, // Sphinx.sortMode.RELEVANCE + sortby : "", + min_id : 0, + max_id : 0, + filters : [], + groupby : "", + groupfunc : 0, // Sphinx.groupFunc.DAY + groupsort : "@group desc", + groupdistinct : "", + maxmatches : 1000, + cutoff : 0, + retrycount : 0, + retrydelay : 0, + anchor : [], + indexweights : [], + ranker : 0, // Sphinx.rankingMode.PROXIMITY_BM25 + maxquerytime : 0, + fieldweights : {}, + overrides : [], + selectlist : "*", + indexes : '*', + comment : '', + query : "", + error : "", // per-reply fields (for single-query case) + warning : "", + connerror : false, + reqs : [], // requests storage (for multi-query case) + mbenc : "", + arrayresult : true, + timeout : 0 +}; + +describe('Query object bulder', function () { + it('String query', function () { + let testQuery = "Test query"; + let client = new SphinxClient(); + let queryObj = client.makeQueryObject(testQuery); + let queryBuffer = client.makeRequestBuffer(queryObj); + let exampleObj = Object.assign({}, defaultQueryObject); + + exampleObj.query = testQuery; + console.log('Object', queryBuffer.values()); + expect(queryObj).toEqual(exampleObj, "Default object with query field"); + }); + +}); + +describe('Request buffer bulder', function () { + it('String query', function () { + let testQuery = "Test query"; + let client = new SphinxClient(); + + let testQueryObj = Object.assign({}, defaultQueryObject); + + testQueryObj.query = testQuery; + + let requestBuffer = client.makeRequestBuffer(testQueryObj).toString('hex'); + let exampleBuffer = "000001180000009700000000000000010000000000000014000000000000000000000000000000000000000a5465737420717565727900000000000000012a0000000100000000000000000000000000000000000000000000000000000000000003e80000000b4067726f7570206465736300000000000000000000000000000000000000000000000000000000000000000000000000000000000000012a"; + + expect(requestBuffer).toEqual(exampleBuffer, "Default buffer with query field"); + }); + +});