|
| 1 | +require "minitest/autorun" |
| 2 | +require "teller" |
| 3 | + |
| 4 | +describe Teller::Config do |
| 5 | + let(:config) { Teller::Config } |
| 6 | + |
| 7 | + it "allows setting access_token" do |
| 8 | + config.access_token = "your_access_token" |
| 9 | + _(config.access_token).must_equal "your_access_token" |
| 10 | + end |
| 11 | + |
| 12 | + it "allows setting certificate using certificate=" do |
| 13 | + config.certificate = "test/fixtures/certificate.pem" |
| 14 | + _(config.certificate).must_be_kind_of OpenSSL::X509::Certificate |
| 15 | + end |
| 16 | + |
| 17 | + it "allows setting private_key using private_key =" do |
| 18 | + private_key_path = "test/fixtures/private_key.pem" |
| 19 | + File.stub(:read, "your_private_key_content") do |
| 20 | + private_key = config.private_key = private_key_path |
| 21 | + _(config.private_key).must_be_kind_of OpenSSL::PKey::EC |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + it "allows setting multiple attributes using setup block" do |
| 26 | + config.setup do |conf| |
| 27 | + conf.access_token = "your_access_token" |
| 28 | + conf.certificate = "test/fixtures/certificate.pem" |
| 29 | + conf.private_key = "test/fixtures/private_key.pem" |
| 30 | + end |
| 31 | + |
| 32 | + _(config.access_token).must_equal "your_access_token" |
| 33 | + _(config.certificate).must_be_kind_of OpenSSL::X509::Certificate |
| 34 | + _(config.private_key).must_be_kind_of OpenSSL::PKey::EC |
| 35 | + end |
| 36 | + |
| 37 | + it "allows setting multiple attributes using setup hash" do |
| 38 | + config.setup(access_token: "your_access_token", |
| 39 | + certificate: "test/fixtures/certificate.pem", |
| 40 | + private_key: "test/fixtures/private_key.pem") |
| 41 | + |
| 42 | + _(config.access_token).must_equal "your_access_token" |
| 43 | + _(config.certificate).must_be_kind_of OpenSSL::X509::Certificate |
| 44 | + _(config.private_key).must_be_kind_of OpenSSL::PKey::EC |
| 45 | + end |
| 46 | + |
| 47 | + it "raises Teller::Config::Error for invalid certificate file path" do |
| 48 | + assert_raises(Teller::Config::Error) do |
| 49 | + config.certificate = "non_existent_cert.pem" |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + it "raises Teller::Config::Error for invalid private key file path" do |
| 54 | + assert_raises(Teller::Config::Error) do |
| 55 | + config.private_key = "non_existent_key.pem" |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + it "raises Teller::Config::Error for invalid certificate data" do |
| 60 | + assert_raises(Teller::Config::Error) do |
| 61 | + config.certificate = "test/fixtures/invalid.pem" |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + it "raises Teller::Config::Error for invalid private key data" do |
| 66 | + assert_raises(Teller::Config::Error) do |
| 67 | + config.private_key = "test/fixtures/invalid.pem" |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | +end |
0 commit comments