From ff2db0c5f8bdaa77333c5dfe88f371efd4705cf5 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 29 Aug 2019 10:04:28 +0100 Subject: [PATCH] Update spec routes, namespacing, and test content Resolving new issues after a big merge --- app/controllers/api/products_controller.rb | 2 +- .../api/products_controller_spec.rb | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index f614df2c10..6a90cdf954 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -122,7 +122,7 @@ module Api def render_paged_products(products) serializer = ActiveModel::ArraySerializer.new( products, - each_serializer: Api::Admin::ProductSerializer + each_serializer: ::Api::Admin::ProductSerializer ) render text: { diff --git a/spec/controllers/api/products_controller_spec.rb b/spec/controllers/api/products_controller_spec.rb index 294ae83925..0f2ef1a495 100644 --- a/spec/controllers/api/products_controller_spec.rb +++ b/spec/controllers/api/products_controller_spec.rb @@ -225,49 +225,49 @@ describe Api::ProductsController, type: :controller do before { current_api_user.enterprise_roles.create(enterprise: supplier2) } it "returns a list of products" do - spree_get :bulk_products, { page: 1, per_page: 15 }, format: :json - expect(returned_product_ids).to eq [product4.id, product3.id, product2.id, product1.id] + api_get :bulk_products, { page: 1, per_page: 15 }, format: :json + expect(returned_product_ids).to eq [product4.id, product3.id, product2.id, inactive_product.id, product.id] end it "returns pagination data" do - spree_get :bulk_products, { page: 1, per_page: 15 }, format: :json - expect(json_response['pagination']).to eq "results" => 4, "pages" => 1, "page" => 1, "per_page" => 15 + api_get :bulk_products, { page: 1, per_page: 15 }, format: :json + expect(json_response['pagination']).to eq "results" => 5, "pages" => 1, "page" => 1, "per_page" => 15 end it "uses defaults when page and per_page are not supplied" do - spree_get :bulk_products, format: :json - expect(json_response['pagination']).to eq "results" => 4, "pages" => 1, "page" => 1, "per_page" => 15 + api_get :bulk_products, format: :json + expect(json_response['pagination']).to eq "results" => 5, "pages" => 1, "page" => 1, "per_page" => 15 end it "returns paginated products by page" do - spree_get :bulk_products, { page: 1, per_page: 2 }, format: :json + api_get :bulk_products, { page: 1, per_page: 2 }, format: :json expect(returned_product_ids).to eq [product4.id, product3.id] - spree_get :bulk_products, { page: 2, per_page: 2 }, format: :json - expect(returned_product_ids).to eq [product2.id, product1.id] + api_get :bulk_products, { page: 2, per_page: 2 }, format: :json + expect(returned_product_ids).to eq [product2.id, inactive_product.id] end it "filters results by supplier" do - spree_get :bulk_products, { page: 1, per_page: 15, q: {supplier_id_eq: supplier.id} }, format: :json - expect(returned_product_ids).to eq [product2.id, product1.id] + api_get :bulk_products, { page: 1, per_page: 15, q: {supplier_id_eq: supplier.id} }, format: :json + expect(returned_product_ids).to eq [product2.id, inactive_product.id, product.id] end it "filters results by product category" do - spree_get :bulk_products, { page: 1, per_page: 15, q: {primary_taxon_id_eq: taxon.id} }, format: :json + api_get :bulk_products, { page: 1, per_page: 15, q: {primary_taxon_id_eq: taxon.id} }, format: :json expect(returned_product_ids).to eq [product3.id, product2.id] end it "filters results by import_date" do - product1.variants.first.import_date = 1.day.ago + product.variants.first.import_date = 1.day.ago product2.variants.first.import_date = 2.days.ago product3.variants.first.import_date = 1.day.ago - product1.save + product.save product2.save product3.save - spree_get :bulk_products, { page: 1, per_page: 15, import_date: 1.day.ago.to_date.to_s }, format: :json - expect(returned_product_ids).to eq [product3.id, product1.id] + api_get :bulk_products, { page: 1, per_page: 15, import_date: 1.day.ago.to_date.to_s }, format: :json + expect(returned_product_ids).to eq [product3.id, product.id] end end end