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