require 'spec_helper' RSpec.describe PortalConnectors::ScreeningClient do describe ".sign" do it "returns signature of request" do client = described_class.singleton params = { action_type: "login", details: { user_id: 1 } } expect(client.sign(params)).to be_present end end describe "#submit_action", vcr: true do context "server response with error status" do it "returns error" do client = described_class.singleton params = { action_type: "login", details: { user_id: 1 } } error, ok = client.submit_action(params) expect(ok).to be_falsey expect(error["error"]).to eq "Invalid nonce" end end context "server response with success status" do it "returns action details" do client = described_class.singleton params = { action_type: "login", details: { user_id: 1 } } action_details, ok = client.submit_action(params) expect(ok).to be_truthy expect(action_details["details"]).to match( { "user_id" => 1, } ) end end end describe "#fetch_user" do context "invalid params", :vcr do it "returns error" do client = described_class.singleton params = {} json_body, ok = client.fetch_user(params) expect(ok).to be_falsy expect(json_body['error']).to include("app_name is missing") expect(json_body['error']).to include("app_user_id is missing") end end context "user does not exist", :vcr do it "returns error" do client = described_class.singleton params = { app_name: "remitano", app_user_id: 1 } json_body, ok = client.fetch_user(params) expect(ok).to be_falsy expect(json_body["error"]).to include('User not found') end end context "valid params", :vcr do it "returns user details" do client = described_class.singleton params = { app_name: "remitano", app_user_id: 1 } user_details, ok = client.fetch_user(params) expect(ok).to be_truthy expect(user_details).to match( { "app_name" => "remitano", "app_user_id" => 1, "risk_score" => "0.0" } ) end end end end