mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding attributes to Order Managment API
This commit is contained in:
3
app/views/spree/api/line_items/bulk_show.v1.rabl
Normal file
3
app/views/spree/api/line_items/bulk_show.v1.rabl
Normal file
@@ -0,0 +1,3 @@
|
||||
object @line_item
|
||||
attributes :id, :quantity, :max_quantity
|
||||
node( :supplier ) { |li| partial 'spree/api/enterprises/bulk_show', :object => li.product.supplier }
|
||||
@@ -1,2 +1,8 @@
|
||||
object @order
|
||||
attributes :id
|
||||
attributes :id, :email
|
||||
node( :completed_at ) { |order| order.completed_at.blank? ? "" : order.completed_at.strftime("%F %T") }
|
||||
node( :line_items ) do |order|
|
||||
order.line_items.order('id ASC').map do |line_item|
|
||||
partial 'spree/api/line_items/bulk_show', :object => line_item
|
||||
end
|
||||
end
|
||||
@@ -6,11 +6,15 @@ module Spree
|
||||
include Spree::Api::TestingSupport::Helpers
|
||||
render_views
|
||||
|
||||
|
||||
let!(:order1) { FactoryGirl.create(:order) }
|
||||
let!(:line_item1) { FactoryGirl.create(:line_item) }
|
||||
let!(:line_item2) { FactoryGirl.create(:line_item) }
|
||||
let(:attributes) { [:id] }
|
||||
let!(:order1) { FactoryGirl.create(:order, :state => 'complete', :completed_at => Time.now ) }
|
||||
let!(:order2) { FactoryGirl.create(:order, :state => 'complete', :completed_at => Time.now ) }
|
||||
let!(:order3) { FactoryGirl.create(:order, :state => 'complete', :completed_at => Time.now ) }
|
||||
let!(:line_item1) { FactoryGirl.create(:line_item, :order => order1) }
|
||||
let!(:line_item2) { FactoryGirl.create(:line_item, :order => order2) }
|
||||
let!(:line_item3) { FactoryGirl.create(:line_item, :order => order2) }
|
||||
let!(:line_item4) { FactoryGirl.create(:line_item, :order => order3) }
|
||||
let(:order_attributes) { [:id, :email, :completed_at, :line_items] }
|
||||
let(:line_item_attributes) { [:id, :quantity, :max_quantity, :supplier] }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
@@ -18,10 +22,28 @@ module Spree
|
||||
end
|
||||
|
||||
context "as a normal user" do
|
||||
it "retrieves a list of products with appropriate attributes" do
|
||||
before :each do
|
||||
spree_get :index, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
it "retrieves a list of orders with appropriate attributes, including line items with appropriate attributes" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "retrieves a list of line items with appropriate attributes" do
|
||||
li_keys = json_response.first['line_items'].first.keys.map{ |key| key.to_sym }
|
||||
line_item_attributes.all?{ |attr| li_keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "sorts orders in ascending id order" do
|
||||
ids = json_response.map{ |order| order['id'] }
|
||||
ids[0].should < ids[1]
|
||||
ids[1].should < ids[2]
|
||||
end
|
||||
|
||||
it "formats completed_at to 'yyyy-mm-dd hh:mm'" do
|
||||
json_response.map{ |order| order['completed_at'] }.all?{ |a| a.match("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") }.should == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user