|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe PaystackSdk::Resources::Verification do |
| 4 | + let(:connection) { instance_double("PaystackSdk::Connection") } |
| 5 | + let(:verification) { described_class.new(connection) } |
| 6 | + |
| 7 | + describe "#resolve_account" do |
| 8 | + it "resolves a bank account and wraps response" do |
| 9 | + response_double = double("Response", success?: true) |
| 10 | + expect(connection).to receive(:get) |
| 11 | + .with("/bank/resolve", {account_number: "0001234567", bank_code: "058"}) |
| 12 | + .and_return(response_double) |
| 13 | + expect(PaystackSdk::Response).to receive(:new).with(response_double) |
| 14 | + verification.resolve_account(account_number: "0001234567", bank_code: "058") |
| 15 | + end |
| 16 | + |
| 17 | + it "raises error for missing account_number" do |
| 18 | + expect { |
| 19 | + verification.resolve_account(account_number: nil, bank_code: "058") |
| 20 | + }.to raise_error(PaystackSdk::MissingParamError, /account_number/) |
| 21 | + end |
| 22 | + |
| 23 | + it "raises error for missing bank_code" do |
| 24 | + expect { |
| 25 | + verification.resolve_account(account_number: "0001234567", bank_code: nil) |
| 26 | + }.to raise_error(PaystackSdk::MissingParamError, /bank_code/) |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + describe "#resolve_card_bin" do |
| 31 | + it "resolves a card bin and wraps response" do |
| 32 | + response_double = double("Response", success?: true) |
| 33 | + expect(connection).to receive(:get) |
| 34 | + .with("/decision/bin/539983") |
| 35 | + .and_return(response_double) |
| 36 | + expect(PaystackSdk::Response).to receive(:new).with(response_double) |
| 37 | + verification.resolve_card_bin("539983") |
| 38 | + end |
| 39 | + |
| 40 | + it "raises error for missing bin" do |
| 41 | + expect { |
| 42 | + verification.resolve_card_bin(nil) |
| 43 | + }.to raise_error(PaystackSdk::MissingParamError, /bin/) |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + describe "#validate_account" do |
| 48 | + let(:required_params) do |
| 49 | + { |
| 50 | + account_number: "0001234567", |
| 51 | + account_name: "Jane Doe", |
| 52 | + account_type: "personal", |
| 53 | + bank_code: "058", |
| 54 | + country_code: "NG", |
| 55 | + document_type: "identityNumber" |
| 56 | + } |
| 57 | + end |
| 58 | + |
| 59 | + it "validates an account and wraps response" do |
| 60 | + response_double = double("Response", success?: true) |
| 61 | + expect(connection).to receive(:post) |
| 62 | + .with("/bank/validate", required_params) |
| 63 | + .and_return(response_double) |
| 64 | + expect(PaystackSdk::Response).to receive(:new).with(response_double) |
| 65 | + verification.validate_account(required_params) |
| 66 | + end |
| 67 | + |
| 68 | + it "raises error for missing required fields" do |
| 69 | + %i[account_number account_name account_type bank_code country_code document_type].each do |field| |
| 70 | + params = required_params.dup |
| 71 | + params.delete(field) |
| 72 | + expect { |
| 73 | + verification.validate_account(params) |
| 74 | + }.to raise_error(PaystackSdk::MissingParamError, /#{field}/) |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + it "validates an account with all params and wraps response" do |
| 79 | + all_params = required_params.merge( |
| 80 | + document_number: "1234567890123" |
| 81 | + ) |
| 82 | + response_double = double("Response", success?: true) |
| 83 | + expect(connection).to receive(:post) |
| 84 | + .with("/bank/validate", all_params) |
| 85 | + .and_return(response_double) |
| 86 | + expect(PaystackSdk::Response).to receive(:new).with(response_double) |
| 87 | + verification.validate_account(all_params) |
| 88 | + end |
| 89 | + end |
| 90 | +end |
0 commit comments