Move specs to where they belong

This commit is contained in:
Pau Perez
2021-04-22 15:34:26 +02:00
parent 5845ace8e9
commit 679de40a41
2 changed files with 24 additions and 18 deletions

View File

@@ -66,30 +66,13 @@ module Api
context 'as an admin user' do
before do
allow(controller).to receive(:spree_current_user) { admin_user }
get :index
end
it "retrieves a list of orders with appropriate attributes,
including line items with appropriate attributes" do
get :index
returns_orders(json_response)
end
it "formats completed_at to 'yyyy-mm-dd hh:mm'" do
completed_dates = json_response['orders'].map{ |order| order['completed_at'] }
correct_formats = completed_dates.all?{ |a| a == order1.completed_at.strftime('%B %d, %Y') }
expect(correct_formats).to be_truthy
end
it "returns distributor object with id key" do
distributors = json_response['orders'].map{ |order| order['distributor'] }
expect(distributors.all?{ |d| d.key?('id') }).to be_truthy
end
it "returns the order number" do
order_numbers = json_response['orders'].map{ |order| order['number'] }
expect(order_numbers.all?{ |number| number.match("^R\\d{5,10}$") }).to be_truthy
end
end
context 'as an enterprise user' do

View File

@@ -4,6 +4,7 @@ require "spec_helper"
describe Api::Admin::OrderSerializer do
let(:serializer) { described_class.new order }
let(:order) { build(:order) }
describe "#display_outstanding_balance" do
let(:order) { create(:order) }
@@ -67,4 +68,26 @@ describe Api::Admin::OrderSerializer do
end
end
end
describe "#completed_at" do
let(:order) { build(:order, state: 'complete', completed_at: DateTime.parse("2021-04-02")) }
it "formats the date" do
expect(serializer.completed_at).to eq("April 02, 2021")
end
end
describe "#distributor" do
before { order.distributor = build(:distributor_enterprise) }
it "returns distributor object with id key" do
expect(serializer.distributor.id).to eq(order.distributor.id)
end
end
describe "#number" do
it "returns the order number" do
expect(serializer.number).to eq(order.number)
end
end
end