foodsoft/spec/requests/api/financial_transactions_spec.rb

78 lines
2.4 KiB
Ruby
Raw Normal View History

2022-11-28 13:19:50 +01:00
require 'swagger_helper'
describe 'Financial Transaction', type: :request do
include ApiHelper
2022-11-29 18:55:45 +01:00
let!(:finance_user) { create(:user, groups: [create(:workgroup, role_finance: true)]) }
let!(:api_scopes) { ['finance:read', 'finance:write'] }
let(:api_access_token) { create(:oauth2_access_token, resource_owner_id: finance_user.id, scopes: api_scopes&.join(' ')).token }
let(:financial_transaction) { create(:financial_transaction, user: user) }
2022-11-28 13:19:50 +01:00
path '/financial_transactions' do
get 'financial transactions' do
tags 'Financial Transaction'
produces 'application/json'
2022-11-29 18:55:45 +01:00
parameter name: "per_page", in: :query, type: :integer, required: false
parameter name: "page", in: :query, type: :integer, required: false
2022-11-28 13:19:50 +01:00
response '200', 'success' do
schema type: :object, properties: {
meta: {
2022-11-29 18:55:45 +01:00
type: :object,
items:
{
'$ref': '#/components/schemas/Meta'
}
2022-11-28 13:19:50 +01:00
},
financial_transaction: {
type: :array,
items: {
'$ref': '#/components/schemas/FinancialTransaction'
}
}
}
2022-11-29 18:55:45 +01:00
let(:page) { 1 }
let(:per_page) { 10 }
2022-11-28 13:19:50 +01:00
run_test!
end
2022-11-29 18:55:45 +01:00
it_handles_invalid_scope
2022-11-28 13:19:50 +01:00
end
end
path '/financial_transactions/{id}' do
get 'Retrieves a financial transaction ' do
tags 'Category'
produces 'application/json'
parameter name: :id, in: :path, type: :string
response '200', 'financial transaction found' do
schema type: :object, properties: {
financial_transaction: {
type: :array,
items: {
'$ref': '#/components/schemas/FinancialTransaction'
}
}
}
let(:id) { FinancialTransaction.create(user: user).id }
run_test!
end
it_handles_invalid_scope_with_id(:financial_transaction, 'missing scope or no permission')
2022-11-28 13:19:50 +01:00
response '404', 'financial transaction not found' do
schema type: :object, properties: {
financial_transaction: {
type: :array,
items: {
'$ref': '#/components/schemas/FinancialTransaction'
}
}
}
let(:id) { 'invalid' }
run_test!
end
2022-11-29 18:55:45 +01:00
# response 403
it_handles_invalid_scope_with_id(:financial_transaction, 'missing scope or no permission')
2022-11-28 13:19:50 +01:00
end
end
end