forgeplus/spec/requests/wallets_spec.rb

46 lines
1.7 KiB
Ruby

require 'rails_helper'
RSpec.describe 'Wallet', type: :request do
let(:valid_session) {
{ user_id: 6, www_user_id: 6 }
}
describe 'GET /wallets/balance.json' do
it 'success' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/balance.json', params: { id: 6 }
expect(JSON.parse(response.body)['balance']).to eq(100)
end
end
describe 'GET /wallets/coin_changes.json' do
context 'category all' do
it 'return 2 records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'all' }
expect(JSON.parse(response.body)['coin_changes'].length).to eq(2)
# expect(JSON.parse(response.body)).to eq('')
end
end
context 'category outcome' do
it 'return 1 outcome records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'outcome' }
expect(JSON.parse(response.body)['coin_changes'][0]['amount']).to eq(5)
expect(JSON.parse(response.body)['coin_changes'].length).to eq(1)
end
end
context 'category outcome' do
it 'return 1 income records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'income' }
expect(JSON.parse(response.body)['coin_changes'][0]['amount']).to eq(10)
expect(JSON.parse(response.body)['coin_changes'].length).to eq(1)
end
end
end
end