Multiple where() properties when retrieving data via MIRAGE


#1

Hi guys,

I’m using Ember v2.50 & ember-cli-mirage v.0.1.x and I’m facing an annoying thing right now.

I’m trying to test (acceptance test) some filters that are affecting the result of a product list. I’m doing this with queryParams which are set to retrieve products from the the Mirage database, but if a filter isn’t set which is undefined by default, I don’t get any data back.

My Mirage part looks like this:

mirage/config.js

this.get('cool-products', function (db, request) {

  if (request.queryParams) {

    return {
      'cool-products': db['cool-products'].where({
        gender: request.queryParams.searchedGender,
        productCategory: request.queryParams.searchedProductCategory
      })
    };

  } else {

    return {
      'cool-products': db['cool-products']
    };

  }

});

This works only if both the searchedGender and the searchedProductCategory are set. I thought Mirage could handle undefined values and ignores the within the where clause.

Does someone have an idea how to fix this problem? I cannot believe that Mirage isn’t able to deal with that, so maybe I’m doing anything wrong.

Thanks in advance! =)


#2

Nope, it can’t handle it :slight_smile: You’ll need to account for it yourself …


#3

Okay…

Now I’m building a setFilters object myself and pass it in the where(setFilters)…

But thank you anyway! =)