|
45 | 45 | it { is_expected.to eq true } |
46 | 46 | end |
47 | 47 | end |
| 48 | + |
| 49 | + describe "#filter_invalid" do |
| 50 | + subject(:validation) { client.filter_invalid msids } |
| 51 | + |
| 52 | + let(:msids) { ["test_12345.67890", "test_12345.67891", "test_12345.67892"] } |
| 53 | + let(:invalid_msids) { ["test_12345.67890", "test_12345.67892"] } |
| 54 | + let(:service_url) { "https://example.org" } |
| 55 | + let(:http_request) { stub_request(:post, "#{service_url}/sessions/filter") } |
| 56 | + let(:escher_keypool) { { api_key_id: 'session-validator_smart-insight_v1', api_secret: 'escher_secret' } } |
| 57 | + |
| 58 | + before do |
| 59 | + stub_const 'ENV', ENV.to_h.merge('SESSION_VALIDATOR_URL' => service_url) |
| 60 | + allow(::Escher::Keypool).to receive_message_chain(:new, :get_active_key).with("session_validator") |
| 61 | + .and_return(escher_keypool) |
| 62 | + end |
| 63 | + |
| 64 | + context "when request timeouted" do |
| 65 | + before { http_request.to_raise Faraday::TimeoutError } |
| 66 | + |
| 67 | + it { is_expected.to eq [] } |
| 68 | + end |
| 69 | + |
| 70 | + context "when given a list of msids" do |
| 71 | + before { http_request.to_return body: JSON.generate(invalid_msids) } |
| 72 | + |
| 73 | + it { is_expected.to have_requested(:post, "#{service_url}/sessions/filter"). |
| 74 | + with(body: JSON.generate({msids: msids})) } |
| 75 | + end |
| 76 | + |
| 77 | + context "when response status code is not 200 OK" do |
| 78 | + before { http_request.to_return status: [404, "Not Found"] } |
| 79 | + |
| 80 | + it { is_expected.to eq [] } |
| 81 | + end |
| 82 | + |
| 83 | + context "when server replies with a list of msids" do |
| 84 | + before { http_request.to_return body: JSON.generate(invalid_msids) } |
| 85 | + |
| 86 | + it { is_expected.to eq invalid_msids } |
| 87 | + end |
| 88 | + |
| 89 | + end |
| 90 | + |
48 | 91 | end |
0 commit comments