mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
fix test
This commit is contained in:
parent
2dbc026db1
commit
61273bd66f
4
test/fixtures/wallet_transactions.yml
vendored
4
test/fixtures/wallet_transactions.yml
vendored
@ -1,7 +1,7 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
transaction1:
|
||||
user_id: 4
|
||||
wallet: wallet_4
|
||||
user_id: 5
|
||||
wallet: wallet_5
|
||||
transaction_type: credit
|
||||
amount: 1000
|
||||
|
4
test/fixtures/wallets.yml
vendored
4
test/fixtures/wallets.yml
vendored
@ -4,7 +4,7 @@ wallet_2:
|
||||
|
||||
wallet_4:
|
||||
user_id: 4
|
||||
amount: 1000
|
||||
amount: 0
|
||||
|
||||
wallet_6:
|
||||
user_id: 6
|
||||
@ -12,7 +12,7 @@ wallet_6:
|
||||
|
||||
wallet_5:
|
||||
user_id: 5
|
||||
amount: 0
|
||||
amount: 1000
|
||||
|
||||
wallet_3:
|
||||
user_id: 3
|
||||
|
@ -69,7 +69,7 @@ class EventsTest < ActionDispatch::IntegrationTest
|
||||
reservable_type: 'Event',
|
||||
nb_reserve_places: 2,
|
||||
nb_reserve_reduced_places: 0,
|
||||
slot_attributes: [
|
||||
slots_attributes: [
|
||||
{
|
||||
start_at: e.availability.start_at,
|
||||
end_at: e.availability.end_at,
|
||||
@ -114,4 +114,4 @@ class EventsTest < ActionDispatch::IntegrationTest
|
||||
assert_equal 20, e.nb_total_places, 'Total number of places was not updated'
|
||||
assert_equal 18, e.nb_free_places, 'Number of free places was not updated'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,8 +3,8 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
||||
# Called before every test method runs. Can be used
|
||||
# to set up fixture information.
|
||||
def setup
|
||||
@kdumas = User.find_by(username: 'kdumas')
|
||||
login_as(@kdumas, scope: :user)
|
||||
@vlonchamp = User.find_by(username: 'vlonchamp')
|
||||
login_as(@vlonchamp, scope: :user)
|
||||
end
|
||||
|
||||
# Called after every test method runs. Can be used to tear
|
||||
@ -15,12 +15,12 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'get my wallet' do
|
||||
get "/api/wallet/by_user/#{@kdumas.id}"
|
||||
get "/api/wallet/by_user/#{@vlonchamp.id}"
|
||||
assert_equal 200, response.status
|
||||
assert_equal Mime::JSON, response.content_type
|
||||
wallet = json_response(response.body)
|
||||
assert_equal @kdumas.wallet.user_id, wallet[:user_id]
|
||||
assert_equal @kdumas.wallet.amount, wallet[:amount]
|
||||
assert_equal @vlonchamp.wallet.user_id, wallet[:user_id]
|
||||
assert_equal @vlonchamp.wallet.amount, wallet[:amount]
|
||||
end
|
||||
|
||||
test 'admin can get wallet by user id' do
|
||||
@ -36,13 +36,13 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'cant get wallet of an user if not admin' do
|
||||
user5 = users(:user_5)
|
||||
user5 = users(:user_4)
|
||||
get "/api/wallet/by_user/#{user5.id}"
|
||||
assert_equal 403, response.status
|
||||
end
|
||||
|
||||
test 'get all transactions of wallet' do
|
||||
w = @kdumas.wallet
|
||||
w = @vlonchamp.wallet
|
||||
get "/api/wallet/#{w.id}/transactions"
|
||||
assert_equal 200, response.status
|
||||
assert_equal Mime::JSON, response.content_type
|
||||
@ -52,7 +52,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'only admin and wallet owner can show their transactions' do
|
||||
user5 = users(:user_5)
|
||||
user5 = users(:user_4)
|
||||
get "/api/wallet/#{user5.wallet.id}/transactions"
|
||||
assert_equal 403, response.status
|
||||
end
|
||||
@ -60,7 +60,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
||||
test 'admin can credit amount to a wallet' do
|
||||
admin = users(:user_1)
|
||||
login_as(admin, scope: :user)
|
||||
w = @kdumas.wallet
|
||||
w = @vlonchamp.wallet
|
||||
amount = 10
|
||||
expected_amount = w.amount + amount
|
||||
put "/api/wallet/#{w.id}/credit",
|
||||
|
@ -3,25 +3,37 @@ require 'test_helper'
|
||||
class WalletServiceTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@admin = User.find_by(username: 'admin')
|
||||
@user = User.find_by(username: 'jdupond')
|
||||
@wallet = @user.wallet
|
||||
@jdupond = User.find_by(username: 'jdupond')
|
||||
@jdupond_wallet = @jdupond.wallet
|
||||
@vlonchamp = User.find_by(username: 'vlonchamp')
|
||||
@vlonchamp_wallet = @vlonchamp.wallet
|
||||
end
|
||||
|
||||
test 'admin can credit a wallet' do
|
||||
service = WalletService.new(user: @admin, wallet: @wallet)
|
||||
expected_amount = @wallet.amount + 5
|
||||
service = WalletService.new(user: @admin, wallet: @jdupond_wallet)
|
||||
expected_amount = @jdupond_wallet.amount + 5
|
||||
assert service.credit(5)
|
||||
assert_equal @wallet.amount, expected_amount
|
||||
assert_equal @jdupond_wallet.amount, expected_amount
|
||||
end
|
||||
|
||||
test 'create a credit transaction after credit amount to wallet' do
|
||||
service = WalletService.new(user: @admin, wallet: @wallet)
|
||||
assert_equal 0, @wallet.wallet_transactions.count
|
||||
service = WalletService.new(user: @admin, wallet: @jdupond_wallet)
|
||||
assert_equal 0, @jdupond_wallet.wallet_transactions.count
|
||||
assert service.credit(10)
|
||||
transaction = @wallet.wallet_transactions.first
|
||||
transaction = @jdupond_wallet.wallet_transactions.first
|
||||
assert_equal transaction.transaction_type, 'credit'
|
||||
assert_equal transaction.amount, 10
|
||||
assert_equal transaction.user, @admin
|
||||
assert_equal transaction.wallet, @wallet
|
||||
assert_equal transaction.wallet, @jdupond_wallet
|
||||
end
|
||||
|
||||
test 'create a debit transaction after debit amoutn to wallet' do
|
||||
service = WalletService.new(user: @vlonchamp, wallet: @vlonchamp_wallet)
|
||||
assert service.debit(5, nil)
|
||||
transaction = @vlonchamp_wallet.wallet_transactions.last
|
||||
assert_equal transaction.transaction_type, 'debit'
|
||||
assert_equal transaction.amount, 5
|
||||
assert_equal transaction.user, @vlonchamp
|
||||
assert_equal transaction.wallet, @vlonchamp_wallet
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user