Commit 970bb3d2 by ivan Lan

Improve spec

parent dabd39b9
...@@ -54,7 +54,7 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta ...@@ -54,7 +54,7 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
path "/#{namespace}/cart/product_snapshots" do path "/#{namespace}/cart/product_snapshots" do
post(summary: '用户 添加快照至购物车( using series_id & count )') do post(summary: '用户 添加快照至购物车( using shotengai_series_id & count )') do
produces 'application/json' produces 'application/json'
consumes 'application/json' consumes 'application/json'
parameter :buyer_type, in: :query, type: :string parameter :buyer_type, in: :query, type: :string
...@@ -92,6 +92,9 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta ...@@ -92,6 +92,9 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
end end
path "/#{namespace}/orders/{id}/product_snapshots" do path "/#{namespace}/orders/{id}/product_snapshots" do
parameter :id, in: :path, type: :integer
let(:id) { @order_1.id }
get(summary: '某订单的 order 所有snapshots') do get(summary: '某订单的 order 所有snapshots') do
produces 'application/json' produces 'application/json'
consumes 'application/json' consumes 'application/json'
...@@ -100,14 +103,12 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta ...@@ -100,14 +103,12 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
let(:buyer_id) { @user.id } let(:buyer_id) { @user.id }
let(:buyer_type) { @user.class.name } let(:buyer_type) { @user.class.name }
parameter :id, in: :path, type: :integer
parameter :page, in: :query, type: :string parameter :page, in: :query, type: :string
parameter :per_page, in: :query, type: :string parameter :per_page, in: :query, type: :string
let(:page) { 1 } let(:page) { 1 }
let(:per_page) { 100 } let(:per_page) { 100 }
let(:id) { @order_1.id }
before do before do
@orders.last.product_snapshots.create!( @orders.last.product_snapshots.create!(
...@@ -123,6 +124,42 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta ...@@ -123,6 +124,42 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
} }
end end
end end
post(summary: '用户 添加快照至订单( using shotengai_series_id & count )') do
produces 'application/json'
consumes 'application/json'
parameter :buyer_type, in: :query, type: :string
parameter :buyer_id, in: :query, type: :integer
let(:buyer_id) { @user.id }
let(:buyer_type) { @user.class.name }
parameter :product_snapshot, in: :body, schema: {
type: :object, properties: {
product_snapshot: {
type: :object, properties: {
shotengai_series_id: { type: :integer },
count: { type: :integer },
}
}
}
}
before { @order_1_snapshots_count_was = @order_1.snapshots.count }
response(201, description: 'Create snapshot and add it to the cart') do
let(:product_snapshot) {
{
product_snapshot: {
shotengai_series_id: @series_1.id,
count: 10,
}
}
}
it {
expect(JSON.parse(response.body)['count']).to eq(10)
expect(@order_1.snapshots.count).to eq(@order_1_snapshots_count_was + 1)
}
end
end
end end
path "/#{namespace}/orders" do path "/#{namespace}/orders" do
......
...@@ -27,7 +27,7 @@ RSpec.describe "#{namespace}/product_snapshots", type: :request, capture_example ...@@ -27,7 +27,7 @@ RSpec.describe "#{namespace}/product_snapshots", type: :request, capture_example
@snapshot_other = create(:product_snapshot, series: @series_2, count: 5) @snapshot_other = create(:product_snapshot, series: @series_2, count: 5)
@order = create(:order) @order = create(:order)
@cart = Order::Cart.create! @cart = create(:user).order_cart
@snapshot_1.update!(order: @order) @snapshot_1.update!(order: @order)
@snapshot_other.update!(order: @order) @snapshot_other.update!(order: @order)
@snapshot_2.update!(order_cart: @cart) @snapshot_2.update!(order_cart: @cart)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment