mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
Full test coverage of the OpenAPI
Also: fix related bugs
This commit is contained in:
parent
783f28762f
commit
66ba8e565c
@ -1,6 +1,10 @@
|
|||||||
# Changelog Fab-manager
|
# Changelog Fab-manager
|
||||||
|
|
||||||
- Ability to run `fablab:chain:all` non interactively
|
- Ability to run `fablab:chain:all` non interactively
|
||||||
|
- Full test coverage of the OpenAPI
|
||||||
|
- Fix a bug: unable to get the Events without images from the OpenAPI
|
||||||
|
- Fix a bug: unable to get the Space reservations from the OpenAPI
|
||||||
|
- Fix a bug: unable to get invoices from the OpenAPI
|
||||||
|
|
||||||
## v5.0.7 2021 June 24
|
## v5.0.7 2021 June 24
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ class OpenAPI::V1::InvoicesController < OpenAPI::V1::BaseController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@invoices = Invoice.order(created_at: :desc)
|
@invoices = Invoice.order(created_at: :desc)
|
||||||
|
.includes(invoicing_profile: :user)
|
||||||
.references(:invoicing_profiles)
|
.references(:invoicing_profiles)
|
||||||
|
|
||||||
@invoices = @invoices.where('invoicing_profiles.user_id = ?', params[:user_id]) if params[:user_id].present?
|
@invoices = @invoices.where('invoicing_profiles.user_id = ?', params[:user_id]) if params[:user_id].present?
|
||||||
|
@ -16,7 +16,7 @@ class OpenAPI::V1::ReservationsDoc < OpenAPI::V1::BaseDoc
|
|||||||
description 'Index of reservations made by users, with optional pagination. Order by *created_at* descendant.'
|
description 'Index of reservations made by users, with optional pagination. Order by *created_at* descendant.'
|
||||||
param_group :pagination
|
param_group :pagination
|
||||||
param :user_id, [Integer, Array], optional: true, desc: 'Scope the request to one or various users.'
|
param :user_id, [Integer, Array], optional: true, desc: 'Scope the request to one or various users.'
|
||||||
param :reservable_type, %w[Event Machine Training], optional: true, desc: 'Scope the request to a specific type of reservable.'
|
param :reservable_type, %w[Event Machine Space Training], optional: true, desc: 'Scope the request to a specific type of reservable.'
|
||||||
param :reservable_id, [Integer, Array], optional: true, desc: 'Scope the request to one or various reservables.'
|
param :reservable_id, [Integer, Array], optional: true, desc: 'Scope the request to one or various reservables.'
|
||||||
|
|
||||||
example <<-RESERVATIONS
|
example <<-RESERVATIONS
|
||||||
|
@ -27,6 +27,7 @@ class Invoice < PaymentDocument
|
|||||||
|
|
||||||
def file
|
def file
|
||||||
dir = "invoices/#{invoicing_profile.id}"
|
dir = "invoices/#{invoicing_profile.id}"
|
||||||
|
dir = "test/fixtures/files/invoices/#{invoicing_profile.id}" if Rails.env.test?
|
||||||
|
|
||||||
# create directories if they doesn't exists (invoice & invoicing_profile_id)
|
# create directories if they doesn't exists (invoice & invoicing_profile_id)
|
||||||
FileUtils.mkdir_p dir
|
FileUtils.mkdir_p dir
|
||||||
|
@ -3,10 +3,12 @@ json.events @events do |event|
|
|||||||
json.extract! event, :nb_total_places, :nb_free_places
|
json.extract! event, :nb_total_places, :nb_free_places
|
||||||
json.start_at event.availability.start_at
|
json.start_at event.availability.start_at
|
||||||
json.end_at event.availability.end_at
|
json.end_at event.availability.end_at
|
||||||
json.event_image do
|
if event.event_image
|
||||||
json.large_url root_url.chomp('/') + event.event_image.attachment.large.url
|
json.event_image do
|
||||||
json.medium_url root_url.chomp('/') + event.event_image.attachment.medium.url
|
json.large_url root_url.chomp('/') + event.event_image.attachment.large.url
|
||||||
json.small_url root_url.chomp('/') + event.event_image.attachment.small.url
|
json.medium_url root_url.chomp('/') + event.event_image.attachment.medium.url
|
||||||
|
json.small_url root_url.chomp('/') + event.event_image.attachment.small.url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
json.prices do
|
json.prices do
|
||||||
json.normal do
|
json.normal do
|
||||||
|
BIN
test/fixtures/files/invoices/7/FabManager_invoice-3_10062015.pdf
vendored
Normal file
BIN
test/fixtures/files/invoices/7/FabManager_invoice-3_10062015.pdf
vendored
Normal file
Binary file not shown.
0
test/fixtures/open_api_calls_count_tracings.yml
vendored
Normal file
0
test/fixtures/open_api_calls_count_tracings.yml
vendored
Normal file
7
test/fixtures/open_api_clients.yml
vendored
Normal file
7
test/fixtures/open_api_clients.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
minitest:
|
||||||
|
id: 1
|
||||||
|
name: minitest
|
||||||
|
calls_count: 0
|
||||||
|
token: TcAbo97tro21vBkbesZTkg2L
|
||||||
|
created_at: '2021-06-28 06:43:39.237107'
|
||||||
|
updated_at: '2021-06-28 06:43:39.237107'
|
21
test/integration/open_api/bookable_machines_test.rb
Normal file
21
test/integration/open_api/bookable_machines_test.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module OpenApi; end
|
||||||
|
|
||||||
|
class OpenApi::BookableMachinesTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all bookable machines without user_id' do
|
||||||
|
get '/open_api/v1/bookable_machines', headers: open_api_headers(@token)
|
||||||
|
assert_response :internal_server_error
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all bookable machines' do
|
||||||
|
get '/open_api/v1/bookable_machines?user_id=3', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
36
test/integration/open_api/events_test.rb
Normal file
36
test/integration/open_api/events_test.rb
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module OpenApi; end
|
||||||
|
|
||||||
|
class OpenApi::EventsTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all events' do
|
||||||
|
get '/open_api/v1/events', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all events with pagination' do
|
||||||
|
get '/open_api/v1/events?page=1&per_page=5', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list events for a given IDs' do
|
||||||
|
get '/open_api/v1/events?id=[3,4]', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all upcoming events' do
|
||||||
|
get '/open_api/v1/events?upcoming=true', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all upcoming events with pagination' do
|
||||||
|
get '/open_api/v1/events?upcoming=true&page=1&per_page=5', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
37
test/integration/open_api/invoices_test.rb
Normal file
37
test/integration/open_api/invoices_test.rb
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module OpenApi; end
|
||||||
|
|
||||||
|
class OpenApi::InvoicesTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all invoices' do
|
||||||
|
get '/open_api/v1/invoices', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all invoices with pagination' do
|
||||||
|
get '/open_api/v1/invoices?page=1&per_page=5', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all invoices for a user' do
|
||||||
|
get '/open_api/v1/invoices?user_id=3', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all invoices for a user with pagination' do
|
||||||
|
get '/open_api/v1/invoices?user_id=3&page=1&per_page=5', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'download an invoice' do
|
||||||
|
get '/open_api/v1/invoices/3/download', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
assert_match /^inline; filename=/, response.headers['Content-Disposition']
|
||||||
|
end
|
||||||
|
end
|
52
test/integration/open_api/machines_test.rb
Normal file
52
test/integration/open_api/machines_test.rb
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module OpenApi; end
|
||||||
|
|
||||||
|
class OpenApi::MachinesTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all machines' do
|
||||||
|
get '/open_api/v1/machines', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'create a machine' do
|
||||||
|
post '/open_api/v1/machines',
|
||||||
|
params: {
|
||||||
|
machine: {
|
||||||
|
name: 'IJFX 350 Laser',
|
||||||
|
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore...',
|
||||||
|
spec: 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium...',
|
||||||
|
disabled: true
|
||||||
|
}
|
||||||
|
}.to_json,
|
||||||
|
headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'update a machine' do
|
||||||
|
patch '/open_api/v1/machines/3',
|
||||||
|
params: {
|
||||||
|
machine: {
|
||||||
|
disabled: true,
|
||||||
|
name: '[DISABLED] Shopbot'
|
||||||
|
}
|
||||||
|
}.to_json,
|
||||||
|
headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'get a machine' do
|
||||||
|
get '/open_api/v1/machines/3', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'delete a machine' do
|
||||||
|
delete '/open_api/v1/machines/3', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
41
test/integration/open_api/reservations_test.rb
Normal file
41
test/integration/open_api/reservations_test.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module OpenApi; end
|
||||||
|
|
||||||
|
class OpenApi::ReservationsTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all reservations' do
|
||||||
|
get '/open_api/v1/reservations', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all reservations with pagination' do
|
||||||
|
get '/open_api/v1/reservations?page=1&per_page=5', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all reservations for a user' do
|
||||||
|
get '/open_api/v1/reservations?user_id=3', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all reservations for a user with pagination' do
|
||||||
|
get '/open_api/v1/reservations?user_id=3&page=1&per_page=5', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all machine reservations for a user' do
|
||||||
|
get '/open_api/v1/reservations?reservable_type=Machine&user_id=3', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all machine 4 reservations' do
|
||||||
|
get '/open_api/v1/reservations?reservable_type=Machine&reservable_id=4', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
17
test/integration/open_api/trainings_test.rb
Normal file
17
test/integration/open_api/trainings_test.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module OpenApi; end
|
||||||
|
|
||||||
|
class OpenApi::TrainingsTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all trainings' do
|
||||||
|
get '/open_api/v1/trainings', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
31
test/integration/open_api/users_test.rb
Normal file
31
test/integration/open_api/users_test.rb
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module OpenApi; end
|
||||||
|
|
||||||
|
class OpenApi::UsersTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all users' do
|
||||||
|
get '/open_api/v1/users', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all users with pagination' do
|
||||||
|
get '/open_api/v1/users?page=1&per_page=5', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all users filtering by IDs' do
|
||||||
|
get '/open_api/v1/users?user_id=[3,4,5]', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'list all users filtering by email' do
|
||||||
|
get '/open_api/v1/users?email=jean.dupond@gmail.com', headers: open_api_headers(@token)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class PaymentSchedulesControllerTest < ActionDispatch::IntegrationTest
|
class PaymentSchedulesTest < ActionDispatch::IntegrationTest
|
||||||
def setup
|
def setup
|
||||||
@user = User.friendly.find('pjproudhon')
|
@user = User.friendly.find('pjproudhon')
|
||||||
login_as(@user, scope: :user)
|
login_as(@user, scope: :user)
|
@ -36,6 +36,10 @@ class ActiveSupport::TestCase
|
|||||||
{ 'Accept' => Mime[:json], 'Content-Type' => Mime[:json].to_s }
|
{ 'Accept' => Mime[:json], 'Content-Type' => Mime[:json].to_s }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def open_api_headers(token)
|
||||||
|
{ 'Accept' => Mime[:json], 'Content-Type' => Mime[:json].to_s, 'Authorization' => "Token token=#{token}" }
|
||||||
|
end
|
||||||
|
|
||||||
def stripe_payment_method(error: nil)
|
def stripe_payment_method(error: nil)
|
||||||
number = '4242424242424242'
|
number = '4242424242424242'
|
||||||
exp_month = 4
|
exp_month = 4
|
||||||
|
Loading…
Reference in New Issue
Block a user