Skip to content

Commit

Permalink
feat(product-projections): set markMatchingVariants flag to false by …
Browse files Browse the repository at this point in the history
…default
  • Loading branch information
Abimbola Idowu committed Feb 8, 2017
1 parent ae72a37 commit d9ec17d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
14 changes: 8 additions & 6 deletions src/coffee/services/product-projections.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ BaseService = require './base'
# A [`ProductProjection`](http://dev.sphere.io/http-api-projects-products.html#product-projection) is a representation
# of a the `current` or `staged` version of a product (**only GET requests**).
#
# _Products are the sellable goods in an e-commerce project on SPHERE.IO. This document explains some design concepts of products on SPHERE.IO and describes the available HTTP APIs for working with them._
# _Products are the sellable goods in an e-commerce project on SPHERE.IO.
# This document explains some design concepts of products on SPHERE.IO and describes the available HTTP APIs for working with them._
#
# Examples
#
Expand All @@ -25,6 +26,7 @@ class ProductProjectionService extends BaseService
super()
_.extend @_params.query,
fuzzy: false
markMatchingVariants: false
staged: false
filter: []
filterByQuery: []
Expand All @@ -33,7 +35,7 @@ class ProductProjectionService extends BaseService
searchKeywords: []

@_params.encoded = @_params.encoded.concat(['filter', 'filter.query', 'filter.facets', 'facets', 'searchKeywords'])
@_params.plain = @_params.plain.concat(['staged', 'fuzzy'])
@_params.plain = @_params.plain.concat(['staged', 'fuzzy', 'markMatchingVariants'])

# Public: Define whether to query for staged or current product projection.
#
Expand Down Expand Up @@ -74,9 +76,8 @@ class ProductProjectionService extends BaseService
# Examples
#
# service = client.productProjections
# service.text('Sapphure', 'en').markMatchingVariants(true).search()
markMatchingVariants: (value) ->
return this unless _.isBoolean(value)
# service.text('Sapphure', 'en').markMatchingVariants().search()
markMatchingVariants: (value = true) ->
@_params.query.markMatchingVariants = value
debug 'Setting markMatchingVariants: %s', value
this
Expand Down Expand Up @@ -245,6 +246,7 @@ class ProductProjectionService extends BaseService
{staged, fuzzy, text, filter, filterByQuery, filterByFacets, facet, searchKeywords, markMatchingVariants} = _.defaults @_params.query,
fuzzy: false
staged: false
markMatchingVariants: false
filter: []
filterByQuery: []
filterByFacets: []
Expand All @@ -255,7 +257,7 @@ class ProductProjectionService extends BaseService
customQueryString.push "staged=#{staged}" if staged
customQueryString.push "fuzzy=#{fuzzy}" if fuzzy
customQueryString.push "text.#{text.lang}=#{text.value}" if text
customQueryString.push "markMatchingVariants=#{markMatchingVariants}" if _.isBoolean markMatchingVariants
customQueryString.push "markMatchingVariants=#{markMatchingVariants}" if markMatchingVariants

# filter param
_.each filter, (f) -> customQueryString.push "filter=#{f}"
Expand Down
28 changes: 14 additions & 14 deletions src/spec/client/services/product-projections.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ describe 'ProductProjectionService', ->
it 'should reset default params', ->
expect(@service._params).toEqual
encoded: ['where', 'expand', 'sort', 'filter', 'filter.query', 'filter.facets', 'facets', 'searchKeywords']
plain: ['perPage', 'page', 'staged', 'fuzzy']
plain: ['perPage', 'page', 'staged', 'fuzzy', 'markMatchingVariants']
query:
where: []
operator: 'and'
sort: []
expand: []
staged: false
fuzzy: false
markMatchingVariants: false
filter: []
filterByQuery: []
filterByFacets: []
Expand All @@ -46,6 +47,7 @@ describe 'ProductProjectionService', ->
_.each [
['staged', [false]]
['fuzzy', [false]]
['markMatchingVariants', [false]]
['text', ['foo', 'de']]
['filter', ['foo:bar']]
['filterByQuery', ['foo:bar']]
Expand All @@ -68,14 +70,8 @@ describe 'ProductProjectionService', ->
it 'should query for markMatchingVariants when set to true', ->
expect(@service.markMatchingVariants(true)._queryString()).toBe 'markMatchingVariants=true'

it 'should query for markMatchingVariants when set to false', ->
expect(@service.markMatchingVariants(false)._queryString()).toBe 'markMatchingVariants=false'

it 'should query for not set anything when no value is passed to markMatchingVariants', ->
expect(@service.markMatchingVariants()._queryString()).toBe ''

it 'should query for not set anything when value passed to markMatchingVariants is not valid boolean', ->
expect(@service.markMatchingVariants()._queryString()).toBe ''
it 'should query for set markMatchingVariants to true when called', ->
expect(@service.markMatchingVariants()._queryString()).toBe 'markMatchingVariants=true'

it 'should query for published', ->
expect(@service.staged(false)._queryString()).toBe ''
Expand Down Expand Up @@ -123,6 +119,7 @@ describe 'ProductProjectionService', ->
.sort('createdAt')
.staged()
.fuzzy()
.markMatchingVariants()
.text('foo', 'de')
.filter('filter1:bar1')
.filter('filter2:bar2')
Expand All @@ -134,7 +131,7 @@ describe 'ProductProjectionService', ->
.facet('facet2:bar2')
expect(@service._params).toEqual
encoded: ['where', 'expand', 'sort', 'filter', 'filter.query', 'filter.facets', 'facets', 'searchKeywords']
plain: ['perPage', 'page', 'staged', 'fuzzy']
plain: ['perPage', 'page', 'staged', 'fuzzy', 'markMatchingVariants']
query:
where: []
operator: 'and'
Expand All @@ -144,6 +141,7 @@ describe 'ProductProjectionService', ->
perPage: 25
staged: true
fuzzy: true
markMatchingVariants: true
text:
lang: 'de'
value: 'foo'
Expand All @@ -155,14 +153,15 @@ describe 'ProductProjectionService', ->
_service.search()
expect(@service._params).toEqual
encoded: ['where', 'expand', 'sort', 'filter', 'filter.query', 'filter.facets', 'facets', 'searchKeywords']
plain: ['perPage', 'page', 'staged', 'fuzzy']
plain: ['perPage', 'page', 'staged', 'fuzzy', 'markMatchingVariants']
query:
where: []
operator: 'and'
sort: []
expand: []
staged: false
fuzzy: false
markMatchingVariants: false
filter: []
filterByQuery: []
filterByFacets: []
Expand All @@ -184,10 +183,10 @@ describe 'ProductProjectionService', ->
expect(@service._params.queryString).toEqual 'filter=variants.price.centAmount%3A100&filter=variants.attributes.foo%3Abar&staged=true&limit=100&offset=2'

it 'should analyze and store params from queryString', ->
@service.byQueryString('where=productType(id="123")&perPage=100&staged=true&fuzzy=true')
@service.byQueryString('where=productType(id="123")&perPage=100&staged=true&fuzzy=true&markMatchingVariants=true')
expect(@service._params).toEqual
encoded: ['where', 'expand', 'sort', 'filter', 'filter.query', 'filter.facets', 'facets', 'searchKeywords']
plain: ['perPage', 'page', 'staged', 'fuzzy']
plain: ['perPage', 'page', 'staged', 'fuzzy', 'markMatchingVariants']
query:
where: ['productType(id%3D%22123%22)']
operator: 'and'
Expand All @@ -201,7 +200,8 @@ describe 'ProductProjectionService', ->
perPage: '100'
staged: 'true'
fuzzy: 'true'
queryString : 'where=productType(id%3D%22123%22)&perPage=100&staged=true&fuzzy=true'
markMatchingVariants: 'true'
queryString : 'where=productType(id%3D%22123%22)&perPage=100&staged=true&fuzzy=true&markMatchingVariants=true'

describe ':: search', ->

Expand Down

0 comments on commit d9ec17d

Please sign in to comment.