This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from algolia/feature/mergeSearchParameters
- Loading branch information
Showing
7 changed files
with
322 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
var test = require( "tape" ); | ||
var SearchParameters = require( "../../src/SearchParameters" ); | ||
|
||
test( "setqueryparameter should update existing parameter", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"] | ||
} ); | ||
|
||
var newValue = []; | ||
var newsp = sp.setQueryParameter( "facets", newValue ); | ||
|
||
t.equal( newsp.facets, newValue, "update of an existing parameter" ); | ||
|
||
t.end(); | ||
} ); | ||
|
||
test( "setqueryparameter should add non-existing parameter", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"] | ||
} ); | ||
|
||
var newValue = [ "attributesToHighlight" ]; | ||
var newsp = sp.setQueryParameter( "attributesToHighlight", newValue ); | ||
|
||
t.equal( newsp.attributesToHighlight, newValue, "add new parameter" ); | ||
|
||
t.end(); | ||
} ); | ||
|
||
test( "setQueryParameter should not create a new instance if the update is non effective", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"], | ||
maxValuesPerFacet : 10 | ||
} ); | ||
|
||
var newValue = 10; | ||
var newsp = sp.setQueryParameter( "maxValuesPerFacet", newValue ); | ||
|
||
t.equal( newsp, sp, "No change should result in the same instance" ); | ||
|
||
t.end(); | ||
} ); | ||
|
||
test( "setQueryParameter should throw an error when trying to add an unknown parameter", function( t ) { | ||
var sp = new SearchParameters( { | ||
facets : ["facet"] | ||
} ); | ||
|
||
t.throws( sp.setQueryParameter.bind( sp, "unknown", "" ), | ||
"Unknown parameter should throw an exception" ); | ||
|
||
t.end(); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use strict"; | ||
var test = require( "tape" ); | ||
var SearchParameters = require( "../../src/SearchParameters" ); | ||
|
||
test( "setQueryParameters should be able to mix an actual state with a new set of parameters", function( t ) { | ||
var originalSP = new SearchParameters( { | ||
facets : [ "a", "b" ], | ||
ignorePlurals : false, | ||
attributesToHighlight : "" | ||
} ); | ||
|
||
var params = { | ||
facets : [ "a", "c" ], | ||
attributesToHighlight : [ "city", "country" ], | ||
replaceSynonymsInHighlight : true | ||
}; | ||
var newSP = originalSP.setQueryParameters( params ); | ||
|
||
t.equal( newSP.facets, params.facets, "Facets should be updated (existing parameter)" ); | ||
t.equal( newSP.attributesToHighlight, newSP.attributesToHighlight, "attributesToHighlight should be updated (existing parameter)" ); | ||
t.equal( newSP.replaceSynonymsInHighlight, newSP.replaceSynonymsInHighlight, "replaceSynonymsInHighlight should be updated (new parameter)" ); | ||
t.equal( newSP.ignorePlurals, originalSP.ignorePlurals, "ignorePlurals should be the same as the original" ); | ||
|
||
t.end(); | ||
} ); | ||
|
||
test( "setQueryParameters should not add unknown properties", function( t ) { | ||
var originalSP = new SearchParameters( { | ||
facets : [ "a", "b" ], | ||
ignorePlurals : false, | ||
attributesToHighlight : "" | ||
} ); | ||
|
||
var params = { | ||
unknow1 : [ "a", "c" ], | ||
facet : [ "city", "country" ] | ||
}; | ||
|
||
t.throws( originalSP.setQueryParameters.bind( originalSP, params ), | ||
"The new searchParameters should be strictly equal" ); | ||
|
||
t.end(); | ||
} ); |
Oops, something went wrong.