mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Merge pull request #6578 from Matt-Yorkley/products-endpoint-content-type
Products endpoint content type
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
Darkswarm.factory 'OrderCycleResource', ($resource) ->
|
||||
$resource('/api/order_cycles/:id', {}, {
|
||||
$resource('/api/order_cycles/:id.json', {}, {
|
||||
'products':
|
||||
method: 'GET'
|
||||
isArray: true
|
||||
url: '/api/order_cycles/:id/products'
|
||||
url: '/api/order_cycles/:id/products.json'
|
||||
params:
|
||||
id: '@id'
|
||||
'taxons':
|
||||
method: 'GET'
|
||||
isArray: true
|
||||
url: '/api/order_cycles/:id/taxons'
|
||||
url: '/api/order_cycles/:id/taxons.json'
|
||||
params:
|
||||
id: '@id'
|
||||
'properties':
|
||||
method: 'GET'
|
||||
isArray: true
|
||||
url: '/api/order_cycles/:id/properties'
|
||||
url: '/api/order_cycles/:id/properties.json'
|
||||
params:
|
||||
id: '@id'
|
||||
})
|
||||
|
||||
@@ -10,6 +10,9 @@ module Api
|
||||
include Spree::Core::ControllerHelpers::SSL
|
||||
include ::ActionController::Head
|
||||
include ::ActionController::ConditionalGet
|
||||
include ActionView::Layouts
|
||||
|
||||
layout false
|
||||
|
||||
attr_accessor :current_api_user
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ module Api
|
||||
search_params
|
||||
).products_json
|
||||
|
||||
render plain: products, content_type: "application/json"
|
||||
render plain: products
|
||||
rescue ProductsRenderer::NoProducts
|
||||
render_no_products
|
||||
end
|
||||
@@ -33,19 +33,19 @@ module Api
|
||||
|
||||
render plain: ActiveModel::ArraySerializer.new(
|
||||
taxons, each_serializer: Api::TaxonSerializer
|
||||
).to_json, content_type: "application/json"
|
||||
).to_json
|
||||
end
|
||||
|
||||
def properties
|
||||
render plain: ActiveModel::ArraySerializer.new(
|
||||
product_properties | producer_properties, each_serializer: Api::PropertySerializer
|
||||
).to_json, content_type: "application/json"
|
||||
).to_json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_no_products
|
||||
render status: :not_found, json: ''
|
||||
render status: :not_found, json: {}
|
||||
end
|
||||
|
||||
def product_properties
|
||||
|
||||
@@ -148,6 +148,21 @@ module Api
|
||||
expect(product_ids).to include product3.id
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order cycle is closed" do
|
||||
before do
|
||||
allow(controller).to receive(:order_cycle) { order_cycle }
|
||||
allow(order_cycle).to receive(:open?) { false }
|
||||
end
|
||||
|
||||
# Regression test for https://github.com/openfoodfoundation/openfoodnetwork/issues/6491
|
||||
it "renders no products without error" do
|
||||
api_get :products, id: order_cycle.id, distributor: distributor.id
|
||||
|
||||
expect(json_response).to eq({})
|
||||
expect(response).to have_http_status :not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#taxons" do
|
||||
|
||||
@@ -47,8 +47,8 @@ feature "Shops caching", js: true, caching: true do
|
||||
let(:exchange) { order_cycle.exchanges.to_enterprises(distributor).outgoing.first }
|
||||
|
||||
let(:test_domain) { "#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}" }
|
||||
let(:taxons_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/taxons?distributor=#{distributor.id}.json" }
|
||||
let(:properties_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/properties?distributor=#{distributor.id}.json" }
|
||||
let(:taxons_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/taxons.json?distributor=#{distributor.id}" }
|
||||
let(:properties_key) { "views/#{test_domain}/api/order_cycles/#{order_cycle.id}/properties.json?distributor=#{distributor.id}" }
|
||||
let(:options) { { expires_in: CacheService::FILTERS_EXPIRY } }
|
||||
|
||||
before do
|
||||
|
||||
@@ -13,7 +13,7 @@ describe 'Products service', ->
|
||||
properties = null
|
||||
taxons = null
|
||||
GmapsGeo = {}
|
||||
endpoint = "/api/order_cycles/1/products?distributor=1"
|
||||
endpoint = "/api/order_cycles/1/products.json?distributor=1"
|
||||
|
||||
beforeEach ->
|
||||
product =
|
||||
|
||||
Reference in New Issue
Block a user