28_introduce_rswag #35
3 changed files with 42 additions and 38 deletions
|
@ -2,21 +2,26 @@ require 'swagger_helper'
|
|||
|
||||
describe 'Financial Transaction', type: :request do
|
||||
include ApiHelper
|
||||
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) }
|
||||
|
||||
path '/financial_transactions' do
|
||||
get 'financial transactions' do
|
||||
tags 'Financial Transaction'
|
||||
produces 'application/json'
|
||||
parameter name: "page[number]", in: :query, type: :integer, required: false
|
||||
parameter name: "page[size]", in: :query, type: :integer, required: false
|
||||
|
||||
let!(:financial_transaction) { create(:financial_transaction) }
|
||||
let(:api_scopes) { ['finance:read', 'finance:write'] }
|
||||
parameter name: "per_page", in: :query, type: :integer, required: false
|
||||
parameter name: "page", in: :query, type: :integer, required: false
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
meta: {
|
||||
'$ref' => '#/components/schemas/pagination'
|
||||
type: :object,
|
||||
items:
|
||||
{
|
||||
'$ref': '#/components/schemas/Meta'
|
||||
}
|
||||
},
|
||||
financial_transaction: {
|
||||
type: :array,
|
||||
|
@ -25,12 +30,11 @@ describe 'Financial Transaction', type: :request do
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
let(:page) { { number: 1, size: 20 } }
|
||||
let(:page) { 1 }
|
||||
let(:per_page) { 10 }
|
||||
run_test!
|
||||
end
|
||||
|
||||
it_handles_invalid_token
|
||||
it_handles_invalid_scope
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,20 +56,7 @@ describe 'Financial Transaction', type: :request do
|
|||
let(:id) { FinancialTransaction.create(user: user).id }
|
||||
run_test!
|
||||
end
|
||||
|
||||
response '401', 'not logged in' do
|
||||
schema type: :object, properties: {
|
||||
financial_transaction: {
|
||||
type: :array,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/FinancialTransaction'
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:Authorization) { 'abc' }
|
||||
let(:id) { FinancialTransaction.create(name: 'TestTransaction').id }
|
||||
run_test!
|
||||
end
|
||||
it_handles_invalid_scope_with_id(:financial_transaction)
|
||||
|
||||
response '404', 'financial transaction not found' do
|
||||
schema type: :object, properties: {
|
||||
|
@ -79,6 +70,8 @@ describe 'Financial Transaction', type: :request do
|
|||
let(:id) { 'invalid' }
|
||||
run_test!
|
||||
end
|
||||
# response 403
|
||||
it_handles_invalid_scope_with_id(:financial_transaction)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,18 @@ module ApiHelper
|
|||
end
|
||||
end
|
||||
|
||||
def self.it_handles_invalid_token_with_id(class_sym)
|
||||
context 'with invalid access token' do
|
||||
let(:Authorization) { 'abc' }
|
||||
let(:id) { create(class_sym).id }
|
||||
|
||||
response 401, 'not logged-in' do
|
||||
schema '$ref' => '#/components/schemas/Error401'
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.it_handles_invalid_scope
|
||||
context 'with invalid scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
|
@ -29,6 +41,18 @@ module ApiHelper
|
|||
end
|
||||
end
|
||||
|
||||
def self.it_handles_invalid_scope_with_id(class_sym)
|
||||
context 'with invalid scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
let(:id) { create(class_sym).id }
|
||||
|
||||
response 403, 'missing scope' do
|
||||
schema '$ref' => '#/components/schemas/Error403'
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.it_handles_invalid_token_and_scope(*args)
|
||||
it_handles_invalid_token(*args)
|
||||
it_handles_invalid_scope(*args)
|
||||
|
|
|
@ -24,16 +24,6 @@ RSpec.configure do |config|
|
|||
paths: {},
|
||||
components: {
|
||||
schemas: {
|
||||
pagination: {
|
||||
type: :object,
|
||||
properties: {
|
||||
recordCount: { type: :integer },
|
||||
pageCount: { type: :integer },
|
||||
currentPage: { type: :integer },
|
||||
pageSize: { type: :integer }
|
||||
},
|
||||
required: %w(recordCount pageCount currentPage pageSize)
|
||||
},
|
||||
ArticleCategory: {
|
||||
type: :object,
|
||||
properties: {
|
||||
|
@ -51,12 +41,9 @@ RSpec.configure do |config|
|
|||
properties: {
|
||||
id: {
|
||||
type: :integer
|
||||
},
|
||||
name: {
|
||||
type: :string
|
||||
}
|
||||
},
|
||||
required: %w[id financial_transaction_type]
|
||||
required: %w[amount note user_id]
|
||||
},
|
||||
FinancialTransactionClass: {
|
||||
type: :object,
|
||||
|
|
Loading…
Reference in a new issue