28_introduce_rswag #35
3 changed files with 341 additions and 3 deletions
|
@ -23,8 +23,10 @@ describe 'User', type: :request do
|
|||
properties: {
|
||||
amount: { type: :integer },
|
||||
financial_transaction_type: { type: :integer },
|
||||
note: { type: :string } }
|
||||
note: { type: :string }
|
||||
}
|
||||
}
|
||||
let(:financial_transaction) { { amount: 3, financial_transaction_type_id: create(:financial_transaction_type).id, note: 'lirum larum' } }
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
|
@ -35,9 +37,38 @@ describe 'User', type: :request do
|
|||
}
|
||||
}
|
||||
}
|
||||
let(:financial_transaction) { { amount: 3, financial_transaction_type_id: create(:financial_transaction_type).id, note: 'lirum larum' } }
|
||||
run_test!
|
||||
end
|
||||
|
||||
# 401
|
||||
it_handles_invalid_token_with_id(:financial_transaction)
|
||||
|
||||
# 403
|
||||
# description: user has no ordergroup, is below minimum balance, self service is disabled, or missing scope
|
||||
it_handles_invalid_scope_with_id(:financial_transaction)
|
||||
|
||||
# TODO: fix 404 and 422
|
||||
# 404
|
||||
# Type not found
|
||||
# description: financial transaction type not found
|
||||
# Should be 404, but is 200 with validation errors..
|
||||
# Rswag::Specs::UnexpectedResponse:
|
||||
# Expected response code '404' to match '200'
|
||||
# Response body: {"error":"not_found","error_description":"Couldn't find FinancialTransactionType with 'id'=invalid"}
|
||||
# let(:financial_transaction) { { amount: 3, financial_transaction_type_id: 'invalid', note: 'lirum larum' } }
|
||||
# response '404', 'invalid parameter value' do
|
||||
# schema '$ref' => '#/components/schemas/Error404'
|
||||
# run_test!
|
||||
# end
|
||||
|
||||
# 422
|
||||
# response '422', 'invalid parameter value' do
|
||||
# let(:financial_transaction) { { amount: -3, financial_transaction_type_id: create(:financial_transaction_type).id, note: -2 } }
|
||||
|
||||
# schema '$ref' => '#/components/schemas/Error422'
|
||||
# run_test!
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
get 'financial transactions of the members ordergroup' do
|
||||
|
|
259
spec/requests/api/user/group_order_articles_spec.rb
Normal file
259
spec/requests/api/user/group_order_articles_spec.rb
Normal file
|
@ -0,0 +1,259 @@
|
|||
require 'swagger_helper'
|
||||
|
||||
describe 'User', type: :request do
|
||||
include ApiHelper
|
||||
|
||||
let(:api_scopes) { ['group_orders:user'] }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:other_user2) { create :user }
|
||||
let(:order) { create(:order, article_count: 4) }
|
||||
let(:order_articles) { order.order_articles }
|
||||
let(:group_order) { create :group_order, ordergroup: user.ordergroup, order_id: order.id }
|
||||
let(:goa) { create :group_order_article, group_order: group_order, order_article: order_articles.first }
|
||||
|
||||
before do
|
||||
goa
|
||||
end
|
||||
|
||||
path '/user/group_order_articles' do
|
||||
post 'group order article to create' do
|
||||
tags 'User', 'Order'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
parameter name: :group_order_article, in: :body, schema: {
|
||||
type: :object,
|
||||
properties: {
|
||||
order_article_id: { type: :integer },
|
||||
quantity: { type: :integer },
|
||||
tolerance: { type: :string }
|
||||
}
|
||||
}
|
||||
|
||||
let(:group_order_article) { { order_article_id: order_articles.last.id, quantity: 1, tolerance: 2 } }
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article_for_create: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticleForCreate'
|
||||
}
|
||||
}
|
||||
}
|
||||
run_test!
|
||||
end
|
||||
|
||||
# 401
|
||||
it_handles_invalid_token_with_id(:group_order_article)
|
||||
|
||||
# 403
|
||||
# description: user has no ordergroup, is below minimum balance, self service is disabled, or missing scope
|
||||
it_handles_invalid_scope_with_id(:group_order_article)
|
||||
|
||||
# 404
|
||||
response '404', 'order article not found in open orders' do
|
||||
let(:group_order_article) { { order_article_id: 'invalid', quantity: 1, tolerance: 2 } }
|
||||
schema '$ref' => '#/components/schemas/Error404'
|
||||
run_test!
|
||||
end
|
||||
|
||||
# 422
|
||||
response '422', 'invalid parameter value' do
|
||||
let(:group_order_article) { { order_article_id: goa.order_article_id, quantity: 1, tolerance: 2 } }
|
||||
schema '$ref' => '#/components/schemas/Error422'
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
|
||||
get 'group order articles of the members ordergroup' do
|
||||
tags 'User', 'Order'
|
||||
produces 'application/json'
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
meta: {
|
||||
type: :object,
|
||||
items:
|
||||
{
|
||||
'$ref': '#/components/schemas/Meta'
|
||||
}
|
||||
},
|
||||
group_order_article: {
|
||||
type: :array,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['group_order_articles'].first['id']).to eq(goa.id)
|
||||
end
|
||||
end
|
||||
# responses 401 & 403
|
||||
it_handles_invalid_token_and_scope
|
||||
end
|
||||
end
|
||||
|
||||
path '/user/group_order_articles/{id}' do
|
||||
patch 'summary: update a group order article (but delete if quantity and tolerance are zero)' do
|
||||
tags 'User', 'GroupOrderArticle'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
parameter name: :id, in: :path, type: :string
|
||||
|
||||
parameter name: :group_order_article, in: :body, schema: {
|
||||
type: :object,
|
||||
properties: {
|
||||
order_article_id: { type: :integer },
|
||||
quantity: { type: :integer },
|
||||
tolerance: { type: :integer }
|
||||
}
|
||||
}
|
||||
let(:id) { goa.id }
|
||||
let(:group_order_article) { { order_article_id: goa.order_article_id, quantity: 2, tolerance: 2 } }
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article_for_create: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticleForUpdate'
|
||||
}
|
||||
}
|
||||
}
|
||||
run_test!
|
||||
end
|
||||
# 401
|
||||
response 401, 'missing token' do
|
||||
let(:Authorization) { 'abc' }
|
||||
schema '$ref' => '#/components/schemas/Error401'
|
||||
run_test!
|
||||
end
|
||||
# 403
|
||||
response 403, 'missing scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
schema '$ref' => '#/components/schemas/Error403'
|
||||
run_test!
|
||||
end
|
||||
# 404
|
||||
response '404', 'group order article not found' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:id) { 'invalid' }
|
||||
run_test!
|
||||
end
|
||||
|
||||
#422
|
||||
response '422', 'invalid parameter value' do
|
||||
let(:group_order_article) { { order_article_id: 'invalid', quantity: -5, tolerance: 'invalid' } }
|
||||
schema '$ref' => '#/components/schemas/Error422'
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
|
||||
get 'find group order article by id' do
|
||||
tags 'User', 'GroupOrderArticle'
|
||||
produces 'application/json'
|
||||
parameter name: :id, in: :path, type: :string
|
||||
|
||||
let(:id) { goa.id }
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
}
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['group_order_article']['id']).to eq(goa.id)
|
||||
end
|
||||
end
|
||||
|
||||
# 401
|
||||
response 401, 'missing token' do
|
||||
let(:Authorization) { 'abc' }
|
||||
schema '$ref' => '#/components/schemas/Error401'
|
||||
run_test!
|
||||
end
|
||||
# 403
|
||||
response 403, 'missing scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
schema '$ref' => '#/components/schemas/Error403'
|
||||
run_test!
|
||||
end
|
||||
# 404
|
||||
response '404', 'group order article not found' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:id) { 'invalid' }
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
|
||||
delete 'remove group order article' do
|
||||
tags 'User', 'Order'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
let(:api_scopes) { ['group_orders:user'] }
|
||||
|
||||
parameter name: :id, in: :path, type: :string
|
||||
|
||||
let(:id) { goa.id }
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
}
|
||||
run_test!
|
||||
end
|
||||
|
||||
# 401
|
||||
response 401, 'missing token' do
|
||||
let(:Authorization) { 'abc' }
|
||||
schema '$ref' => '#/components/schemas/Error401'
|
||||
run_test!
|
||||
end
|
||||
|
||||
# 403
|
||||
response 403, 'missing scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
schema '$ref' => '#/components/schemas/Error403'
|
||||
run_test!
|
||||
end
|
||||
|
||||
# 404
|
||||
response '404', 'group order article not found' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:id) { 'invalid' }
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -208,6 +208,54 @@ RSpec.configure do |config|
|
|||
},
|
||||
required: %w[id name financial_transaction_class]
|
||||
},
|
||||
GroupOrderArticleForUpdate: {
|
||||
type: :object,
|
||||
properties: {
|
||||
quantity:
|
||||
{
|
||||
type: :integer,
|
||||
description: 'number of units ordered by the users ordergroup'
|
||||
},
|
||||
tolerance:
|
||||
{
|
||||
type: :integer,
|
||||
description: 'number of extra units the users ordergroup is willing to buy for filling a box'
|
||||
}
|
||||
}
|
||||
},
|
||||
GroupOrderArticleForCreate: {
|
||||
type: :object,
|
||||
properties: {
|
||||
order_article_id:
|
||||
{
|
||||
type: :integer,
|
||||
description: 'id of order article'
|
||||
}
|
||||
}
|
||||
},
|
||||
GroupOrderArticle: {
|
||||
type: :object,
|
||||
properties: {
|
||||
id: {
|
||||
type: :integer
|
||||
},
|
||||
result: {
|
||||
type: :float,
|
||||
description: 'number of units the users ordergroup will receive or has received'
|
||||
},
|
||||
total_price:
|
||||
{
|
||||
type: :float,
|
||||
description: 'total price of this group order article'
|
||||
},
|
||||
order_article_id:
|
||||
{
|
||||
type: :integer,
|
||||
description: 'id of order article'
|
||||
}
|
||||
},
|
||||
required: %w[order_article_id]
|
||||
},
|
||||
Meta: {
|
||||
type: :object,
|
||||
properties: {
|
||||
|
@ -305,7 +353,7 @@ RSpec.configure do |config|
|
|||
properties: {
|
||||
error: {
|
||||
type: :string,
|
||||
description: 'unprocessable entity'
|
||||
description: '<tt>unprocessable entity</tt>'
|
||||
},
|
||||
error_description: {
|
||||
'$ref': '#/components/schemas/Error/properties/error_description'
|
||||
|
|
Loading…
Reference in a new issue