chore: rubocop
chore: fix api test conventions chore: rubocop -A spec/ chore: more rubocop -A fix failing test rubocop fixes removes helper methods that are in my opinion dead code more rubocop fixes rubocop -a --auto-gen-config
This commit is contained in:
parent
f6fb804bbe
commit
fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions
108
spec/requests/api/v1/user/financial_transactions_spec.rb
Normal file
108
spec/requests/api/v1/user/financial_transactions_spec.rb
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
require 'swagger_helper'
|
||||
|
||||
describe 'User' do
|
||||
include ApiHelper
|
||||
|
||||
let(:api_scopes) { ['finance:user'] }
|
||||
let(:user) { create(:user, groups: [create(:ordergroup)]) }
|
||||
let(:other_user2) { create(:user) }
|
||||
let(:ft) { create(:financial_transaction, user: user, ordergroup: user.ordergroup) }
|
||||
|
||||
before do
|
||||
ft
|
||||
end
|
||||
|
||||
path '/user/financial_transactions' do
|
||||
post 'create new financial transaction (requires enabled self service)' do
|
||||
tags 'Financial Transaction'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
|
||||
parameter name: :financial_transaction, in: :body, schema: {
|
||||
type: :object,
|
||||
properties: {
|
||||
amount: { type: :integer },
|
||||
financial_transaction_type: { type: :integer },
|
||||
note: { type: :string }
|
||||
}
|
||||
}
|
||||
|
||||
let(:financial_transaction) do
|
||||
{ amount: 3, financial_transaction_type_id: create(:financial_transaction_type).id, note: 'lirum larum' }
|
||||
end
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
financial_transaction: { '$ref': '#/components/schemas/FinancialTransaction' }
|
||||
}
|
||||
run_test!
|
||||
end
|
||||
|
||||
it_handles_invalid_token_with_id
|
||||
it_handles_invalid_scope_with_id 'user has no ordergroup, is below minimum balance, self service is disabled, or missing scope'
|
||||
|
||||
response '404', 'financial transaction type not found' do
|
||||
schema '$ref' => '#/components/schemas/Error404'
|
||||
let(:financial_transaction) { { amount: 3, financial_transaction_type_id: 'invalid', note: 'lirum larum' } }
|
||||
run_test!
|
||||
end
|
||||
|
||||
response '422', 'invalid parameter value' do
|
||||
xit 'TODO: fix controller to actually send a 422 for invalid params: https://github.com/foodcoops/foodsoft/issues/999'
|
||||
# schema '$ref' => '#/components/schemas/Error422'
|
||||
# let(:financial_transaction) { { amount: -3, financial_transaction_type_id: create(:financial_transaction_type).id, note: -2 } }
|
||||
# run_test!
|
||||
end
|
||||
end
|
||||
|
||||
get "financial transactions of the member's ordergroup" do
|
||||
tags 'User', 'Financial Transaction'
|
||||
produces 'application/json'
|
||||
pagination_param
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
meta: { '$ref': '#/components/schemas/Meta' },
|
||||
financial_transaction: {
|
||||
type: :array,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/FinancialTransaction'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['financial_transactions'].first['id']).to eq(ft.id)
|
||||
end
|
||||
end
|
||||
|
||||
it_handles_invalid_token_and_scope
|
||||
end
|
||||
end
|
||||
|
||||
path '/user/financial_transactions/{id}' do
|
||||
get 'find financial transaction by id' do
|
||||
tags 'User', 'Financial Transaction'
|
||||
produces 'application/json'
|
||||
id_url_param
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
financial_transaction: {
|
||||
'$ref': '#/components/schemas/FinancialTransaction'
|
||||
}
|
||||
}
|
||||
let(:id) { ft.id }
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['financial_transaction']['id']).to eq(ft.id)
|
||||
end
|
||||
end
|
||||
|
||||
it_handles_invalid_token_with_id
|
||||
it_handles_invalid_scope_with_id 'user has no ordergroup or missing scope'
|
||||
it_cannot_find_object 'financial transaction not found'
|
||||
end
|
||||
end
|
||||
end
|
||||
194
spec/requests/api/v1/user/group_order_articles_spec.rb
Normal file
194
spec/requests/api/v1/user/group_order_articles_spec.rb
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
require 'swagger_helper'
|
||||
|
||||
describe 'User' 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
|
||||
get 'group order articles' do
|
||||
tags 'User', 'Order'
|
||||
produces 'application/json'
|
||||
pagination_param
|
||||
q_ordered_url_param
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
meta: { '$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
|
||||
|
||||
it_handles_invalid_token
|
||||
it_handles_invalid_scope 'user has no ordergroup or missing scope'
|
||||
end
|
||||
|
||||
post 'create new group order article' do
|
||||
tags 'User', 'Order'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
parameter name: :group_order_article, in: :body,
|
||||
description: 'group order article to create',
|
||||
required: true,
|
||||
schema: { '$ref': '#/components/schemas/GroupOrderArticleForCreate' }
|
||||
|
||||
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: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
},
|
||||
order_article: {
|
||||
'$ref': '#/components/schemas/OrderArticle'
|
||||
}
|
||||
}
|
||||
run_test!
|
||||
end
|
||||
|
||||
it_handles_invalid_token_with_id
|
||||
it_handles_invalid_scope_with_id 'user has no ordergroup, order not open, is below minimum balance, has not enough apple points, or missing scope'
|
||||
|
||||
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
|
||||
|
||||
response '422', 'invalid parameter value or group order article already exists' 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
|
||||
end
|
||||
|
||||
path '/user/group_order_articles/{id}' do
|
||||
get 'find group order article by id' do
|
||||
tags 'User', 'Order'
|
||||
produces 'application/json'
|
||||
id_url_param
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
},
|
||||
order_article: {
|
||||
'$ref': '#/components/schemas/OrderArticle'
|
||||
}
|
||||
}
|
||||
|
||||
let(:id) { goa.id }
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['group_order_article']['id']).to eq(goa.id)
|
||||
end
|
||||
end
|
||||
|
||||
it_handles_invalid_scope_with_id
|
||||
it_handles_invalid_token_with_id
|
||||
it_cannot_find_object 'group order article not found'
|
||||
end
|
||||
|
||||
patch 'update a group order article (but delete if quantity and tolerance are zero)' do
|
||||
tags 'User', 'Order'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
id_url_param
|
||||
parameter name: :group_order_article, in: :body,
|
||||
description: 'group order article update',
|
||||
required: true,
|
||||
schema: { '$ref': '#/components/schemas/GroupOrderArticleForUpdate' }
|
||||
|
||||
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: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
run_test!
|
||||
end
|
||||
|
||||
response 401, 'not logged-in' do
|
||||
schema '$ref' => '#/components/schemas/Error401'
|
||||
let(:Authorization) { 'abc' } # rubocop:disable RSpec/VariableName
|
||||
run_test!
|
||||
end
|
||||
|
||||
response 403,
|
||||
'user has no ordergroup, order not open, is below minimum balance, has not enough apple points, or missing scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
schema '$ref' => '#/components/schemas/Error403'
|
||||
run_test!
|
||||
end
|
||||
|
||||
response '404', 'order article not found in open orders' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
let(:id) { 'invalid' }
|
||||
run_test!
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
delete 'remove group order article' do
|
||||
tags 'User', 'Order'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
id_url_param
|
||||
let(:api_scopes) { ['group_orders:user'] }
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
group_order_article: {
|
||||
'$ref': '#/components/schemas/GroupOrderArticle'
|
||||
}
|
||||
}
|
||||
let(:id) { goa.id }
|
||||
run_test!
|
||||
end
|
||||
|
||||
it_handles_invalid_token_with_id
|
||||
|
||||
response 403,
|
||||
'user has no ordergroup, order not open, is below minimum balance, has not enough apple points, or missing scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
schema '$ref' => '#/components/schemas/Error403'
|
||||
run_test!
|
||||
end
|
||||
|
||||
it_cannot_find_object 'order article not found in open orders'
|
||||
end
|
||||
end
|
||||
end
|
||||
103
spec/requests/api/v1/user/users_spec.rb
Normal file
103
spec/requests/api/v1/user/users_spec.rb
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
require 'swagger_helper'
|
||||
|
||||
describe 'User' do
|
||||
include ApiHelper
|
||||
|
||||
path '/user' do
|
||||
get 'info about the currently logged-in user' do
|
||||
tags 'User'
|
||||
produces 'application/json'
|
||||
let(:api_scopes) { ['user:read'] }
|
||||
let(:other_user1) { create(:user) }
|
||||
let(:user) { create(:user) }
|
||||
let(:other_user2) { create(:user) }
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object,
|
||||
properties: {
|
||||
user: {
|
||||
type: :object,
|
||||
properties: {
|
||||
id: {
|
||||
type: :integer
|
||||
},
|
||||
name: {
|
||||
type: :string,
|
||||
description: 'full name'
|
||||
},
|
||||
email: {
|
||||
type: :string,
|
||||
description: 'email address'
|
||||
},
|
||||
locale: {
|
||||
type: :string,
|
||||
description: 'language code'
|
||||
}
|
||||
},
|
||||
required: %w[id name email]
|
||||
}
|
||||
}
|
||||
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['user']['id']).to eq(user.id)
|
||||
end
|
||||
end
|
||||
|
||||
it_handles_invalid_token_and_scope
|
||||
end
|
||||
end
|
||||
|
||||
path '/user/financial_overview' do
|
||||
get 'financial summary about the currently logged-in user' do
|
||||
tags 'User', 'Financial Transaction'
|
||||
produces 'application/json'
|
||||
let(:user) { create(:user, :ordergroup) }
|
||||
let(:api_scopes) { ['finance:user'] }
|
||||
FinancialTransactionClass.create(name: 'TestTransaction')
|
||||
|
||||
response 200, 'success' do
|
||||
schema type: :object,
|
||||
properties: {
|
||||
financial_overview: {
|
||||
type: :object,
|
||||
properties: {
|
||||
|
||||
account_balance: {
|
||||
type: :number,
|
||||
description: 'booked accout balance of ordergroup'
|
||||
},
|
||||
available_funds: {
|
||||
type: :number,
|
||||
description: 'fund available to order articles'
|
||||
},
|
||||
financial_transaction_class_sums: {
|
||||
type: :array,
|
||||
properties: {
|
||||
id: {
|
||||
type: :integer,
|
||||
description: 'id of the financial transaction class'
|
||||
},
|
||||
name: {
|
||||
type: :string,
|
||||
description: 'name of the financial transaction class'
|
||||
},
|
||||
amount: {
|
||||
type: :number,
|
||||
description: 'sum of the amounts belonging to the financial transaction class'
|
||||
}
|
||||
},
|
||||
required: %w[id name amount]
|
||||
}
|
||||
},
|
||||
required: %w[account_balance available_funds financial_transaction_class_sums]
|
||||
}
|
||||
}
|
||||
|
||||
run_test!
|
||||
end
|
||||
|
||||
it_handles_invalid_token_and_scope
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue