Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ruby '2.2.2'
gem 'api_banking', path: "/Users/divya/code/ruby/api_banking"
gem 'rspec'
gem 'dotenv'
gem 'manacle_for'
gem 'manacle_for', path: '/Users/divya/code/ruby/manacle_gem'
26 changes: 15 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
PATH
remote: /Users/divya/code/ruby/api_banking
specs:
api_banking (0.1.11)
api_banking (0.1.12)
nokogiri
typhoeus

PATH
remote: /Users/divya/code/ruby/manacle_gem
specs:
manacle_for (0.0.11)
activerecord-oracle_enhanced-adapter
api_banking
dotenv
factory_girl
nokogiri
rspec
ruby-oci8

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -33,16 +45,8 @@ GEM
activesupport (>= 3.0.0)
ffi (1.9.14)
i18n (0.7.0)
manacle_for (0.0.7)
activerecord-oracle_enhanced-adapter
api_banking
dotenv
factory_girl
nokogiri
rspec
ruby-oci8
mini_portile2 (2.1.0)
minitest (5.9.0)
minitest (5.9.1)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
Expand Down Expand Up @@ -74,7 +78,7 @@ PLATFORMS
DEPENDENCIES
api_banking!
dotenv
manacle_for
manacle_for!
rspec

RUBY VERSION
Expand Down
11 changes: 11 additions & 0 deletions models/pc_app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class PcApp < ActiveRecord::Base
after_initialize :defaults, unless: :persisted?
self.table_name = "pc_apps"

belongs_to :pc_program, :foreign_key => 'program_code', :primary_key => 'code',:class_name => 'PcProgram'
Expand All @@ -12,4 +13,14 @@ def enable!
self.is_enabled = 'Y'
save!
end

private
def defaults
self.is_enabled = 'Y'
self.approval_status = 'A'
self.lock_version = 0
self.last_action = 'C'
self.identity_user_id = '12345'
end

end
13 changes: 13 additions & 0 deletions models/pc_customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class PcCustomer < ActiveRecord::Base
self.table_name = "pc_customers"

def disable!
self.cust_status = 'inactive'
save!
end

def enable!
self.cust_status = 'active'
save!
end
end
14 changes: 14 additions & 0 deletions models/pc_product.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class PcProduct < ActiveRecord::Base
after_initialize :defaults, unless: :persisted?
self.table_name = "pc_products"

attr_accessor :prod

belongs_to :pc_program, :foreign_key => 'program_code', :primary_key => 'code', :class_name => 'PcProgram'

def disable!
Expand All @@ -12,4 +15,15 @@ def enable!
self.is_enabled = 'Y'
save!
end

private
def defaults
self.is_enabled = 'Y'
self.approval_status = 'A'
self.lock_version = 0
self.last_action = 'C'
self.mm_admin_password = Manacle::Helper.encrypt(self.mm_admin_password)
self.rkb_password = Manacle::Helper.encrypt(self.rkb_password)
end

end
10 changes: 10 additions & 0 deletions models/pc_program.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class PcProgram < ActiveRecord::Base
after_initialize :defaults, unless: :persisted?
self.table_name = "pc_programs"

has_many :pc_products, :foreign_key => 'program_code', :primary_key => 'code', :class_name => 'PcProduct'
Expand All @@ -12,4 +13,13 @@ def enable!
self.is_enabled = 'Y'
save!
end

private
def defaults
self.is_enabled = 'Y'
self.approval_status = 'A'
self.lock_version = 0
self.last_action = 'C'
end

end
8 changes: 5 additions & 3 deletions spec/BlockCardMatchers.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require 'rspec/expectations'

module BlockCardMatchers
RSpec::Matchers.define :be_completed do
extend RSpec::Matchers::DSL
matcher :be_completed do
match do |response|
p response.try(:uniqueResponseNo)
expect(response).to be_an_instance_of ApiBanking::PrepaidCardManagementService::BlockCard::Result
end

failure_message do |response|
if actual.instance_of?(ApiBanking::Fault)
"expected result would be a success instead of #{actual.class} code #{actual.code} : #{actual.subCode} : #{actual.reasonText}"
"expected result should be BlockCard::Result instead of #{actual.class} code #{actual.code} : #{actual.subCode} : #{actual.reasonText}"
else
"expected result would be a success instead of #{response}"
"expected result should be BlockCard::Result instead of #{response} "
end
end
end
Expand Down
64 changes: 43 additions & 21 deletions spec/BlockCard_spec.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,69 @@
require_relative 'operations'
require_relative 'BlockCardMatchers'

ActiveRecord::Base.logger = Logger.new(STDOUT)

class BlockCard
# specify the list of paramaters that are always required to be printed in the report
def self.param_defaults
[{appID: nil}, {mobileNo: nil}]
end
end
# ActiveRecord::Base.logger = Logger.new(STDOUT)

RSpec.describe BlockCard do
include BlockCardMatchers

let(:appID) { 'MANACLE' }

def build_request()
request = ApiBanking::PrepaidCardManagementService::BlockCard::Request.new()

request
def build_request
BlockCard.build_request
end

def blockCard(request)
ApiBanking::PrepaidCardManagementService.blockCard(request)
end

before(:all) do
# initialize factories
@pc_program = PcProgram.create(code: 'PROGRAM1')
@pc_app = PcApp.create(app_id: 'MANACLE', program_code: @pc_program.code)
@pc_product1 = PcProduct.create({code: 'prod1', program_code: @pc_program.code}.merge(Manacle::DATA['product_attributes']))
@pc_product2 = PcProduct.create({code: 'prod2', program_code: @pc_program.code}.merge(Manacle::DATA['product_attributes']))

(@reg_request = RegisterCard.build_request()).appID = @pc_app.app_id
@reg_request.productCode = @pc_product1.code
@reg_request.proxyCardNumber = Manacle::DATA['available_proxy_card6']
ApiBanking::PrepaidCardManagementService.registerCard(@reg_request)
end

after(:all) do
# destroy factories
@pc_app.delete
@pc_program.delete
@pc_product1.delete
@pc_product2.delete
end

context "with some scenario " do
before(:each) do
context "with a registered mobile" do
context "with a card which is not blocked" do
it "should return success", case: :PPCMB2 do
(request = build_request()).appID = @pc_app.app_id
request.mobileNo = @reg_request.mobileNo
expect(blockCard(request)).to be_completed
end
end

context "and an empty request" do
it "should return fault", case: :PPC01 do
(request = build_request())
expect(blockCard(request)).to fail_with('ns:E400')
context "with a card which is already blocked" do
it "should return fault", case: :PPCMB3 do
(request = build_request()).appID = @pc_app.app_id
request.mobileNo = @reg_request.mobileNo
expect(blockCard(request)).to fail_with('http:status-400')
end
end
end

context "with an unregistered mobile" do
it "should return fault", case: :PPCMB4 do
(request = build_request()).appID = @pc_app.app_id
request.mobileNo = Manacle::DATA['unregistered_customer_mobile']
expect(blockCard(request)).to fail_with('http:status-400')
end
end

context "with an invalid app_id " do
it "should return fault", case: :PPCMB1 do
(request = build_request()).appID = 'BLANK'
expect(blockCard(request)).to fail_with('ns:E404')
end
end
end
8 changes: 5 additions & 3 deletions spec/LoadCardMatchers.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require 'rspec/expectations'

module LoadCardMatchers
RSpec::Matchers.define :be_completed do
extend RSpec::Matchers::DSL
matcher :be_completed do
match do |response|
puts response.try(:uniqueResponseNo)
expect(response).to be_an_instance_of ApiBanking::PrepaidCardManagementService::LoadCard::Result
end

failure_message do |response|
if actual.instance_of?(ApiBanking::Fault)
"expected result would be a success instead of #{actual.class} code #{actual.code} : #{actual.subCode} : #{actual.reasonText}"
"expected result would be LoadCard::Result instead of #{actual.class} code #{actual.code} : #{actual.subCode} : #{actual.reasonText}"
else
"expected result would be a success instead of #{response}"
"expected result would be LoadCard::Result instead of #{response}"
end
end
end
Expand Down
72 changes: 50 additions & 22 deletions spec/LoadCard_spec.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
require_relative 'operations'
require_relative 'LoadCardMatchers'
# require 'ruby-debug'

ActiveRecord::Base.logger = Logger.new(STDOUT)

class LoadCard
# specify the list of paramaters that are always required to be printed in the report
def self.param_defaults
[{appID: nil}, {mobileNo: nil}]
end
end
# ActiveRecord::Base.logger = Logger.new(STDOUT)

RSpec.describe LoadCard do
include LoadCardMatchers

let(:appID) { 'MANACLE' }

def build_request()
request = ApiBanking::PrepaidCardManagementService::LoadCard::Request.new()

request
LoadCard.build_request
end

def loadCard(request)
ApiBanking::PrepaidCardManagementService.loadCard(request)
end

before(:all) do
# initialize factories
p @abc
@ar = {}
@ar[:pc_program] = PcProgram.create(code: 'PROGRAM1')
@ar[:pc_app] = PcApp.create(app_id: 'MANACLE', program_code: @ar[:pc_program].code)
@ar[:pc_product1] = PcProduct.create({code: 'prod1', program_code: @ar[:pc_program].code}.merge(Manacle::DATA['product_attributes']))
@ar[:pc_product2] = PcProduct.create({code: 'prod2', program_code: @ar[:pc_program].code}.merge(Manacle::DATA['product_attributes']))

# register the proxy_card if not already registered
(request = RegisterCard.build_request()).appID = @ar[:pc_app].app_id
request.productCode = @ar[:pc_product1].code
request.proxyCardNumber = Manacle::DATA['available_proxy_card6']
@mobileNo = request.mobileNo
if ApiBanking::PrepaidCardManagementService.registerCard(request).instance_of?(ApiBanking::Fault)
@ar.each { |k,v| v.delete }
raise "registration failed "
end
end

after(:all) do
# destroy factories
@ar.each { |k,v| v.delete }
end

context "with some scenario " do
before(:each) do
end

context "and an empty request" do
it "should return fault", case: :PPC01 do
(request = build_request())
expect(loadCard(request)).to fail_with('ns:E400')
context "with a registered mobile" do
context "with valid debit account number" do
it "should return success", case: :PPCML2 do
(request = build_request()).appID = @pc_app.app_id
request.mobileNo = @mobileNo
expect(loadCard(request)).to be_completed
end
end

# context "with invalid debit account number" do
# it "should return fault", case: :PPCML3 do
# (request = build_request()).appID = @pc_app.app_id
# request.mobileNo = @mobileNo
# request.debitAccountNo = Manacle::DATA['invalid_debit_account_no']
# expect(loadCard(request)).to fail_with('ns:E502')
# end
# end
end

context "with an unregistered mobile" do
it "should return fault", case: :PPCML4 do
(request = build_request()).appID = @pc_app.app_id
request.mobileNo = Manacle::DATA['unregistered_customer_mobile']
expect(loadCard(request)).to fail_with('http:status-400')
end
end

context "with an invalid app_id " do
it "should return fault", case: :PPCML1 do
(request = build_request()).appID = 'BLANK'
expect(loadCard(request)).to fail_with('ns:E404')
end
end
end
7 changes: 4 additions & 3 deletions spec/RegisterCardMatchers.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
require 'rspec/expectations'

module RegisterCardMatchers
RSpec::Matchers.define :be_completed do
extend RSpec::Matchers::DSL
matcher :be_completed do
match do |response|
expect(response).to be_an_instance_of ApiBanking::PrepaidCardManagementService::RegisterCard::Result
end

failure_message do |response|
if actual.instance_of?(ApiBanking::Fault)
"expected result would be a success instead of #{actual.class} code #{actual.code} : #{actual.subCode} : #{actual.reasonText}"
"expected result would be RegisterCard::Result instead of #{actual.class} code #{actual.code} : #{actual.subCode} : #{actual.reasonText}"
else
"expected result would be a success instead of #{response}"
"expected result would be RegisterCard::Result instead of #{response}"
end
end
end
Expand Down
Loading