|
29 | 29 |
|
30 | 30 | it "is false if connection is not valid" do |
31 | 31 | stub_contribution_types(status: 401, body: any_json(status: 401)) |
32 | | - stub_authenticate(status: 401, body: any_json(status: 401)) |
33 | 32 | expect(connection.valid?).to be(false) |
34 | 33 | end |
35 | 34 | end |
|
118 | 117 |
|
119 | 118 | describe "request" do |
120 | 119 | context "when successful" do |
121 | | - before do |
122 | | - stub_authenticate |
123 | | - end |
124 | | - |
125 | 120 | it "returns HTTP::Response" do |
126 | 121 | stub_funds |
127 | 122 | expect(connection.request(path: "/funds")).to be_a(HTTP::Response) |
128 | 123 | end |
129 | 124 | end |
130 | 125 |
|
131 | | - context "when authentication fails on non-authenticate request" do |
| 126 | + context "when failure" do |
132 | 127 | before do |
133 | 128 | stub_funds(status: 401, body: any_json(status: 401)) |
134 | | - stub_authenticate |
135 | 129 | end |
136 | 130 |
|
137 | 131 | it "will raise unathenticated error after multiple attempts" do |
138 | | - expect(connection.user_resource).to receive(:authenticate).exactly(2).times.and_call_original |
139 | | - |
140 | 132 | expect { connection.request(path: "/funds") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful (401 Unauthorized): Unauthorized") |
141 | 133 | end |
142 | | - end |
143 | | - |
144 | | - context "when authentication fails on authenticate request" do |
145 | | - before do |
146 | | - stub_authenticate(status: 401, body: any_json(status: 401)) |
147 | | - end |
148 | 134 |
|
149 | 135 | it "will raise unathenticated error immediately" do |
150 | | - expect(connection.user_resource).to receive(:authenticate).once.and_call_original |
151 | | - |
152 | 136 | expect { connection.request(path: "/funds") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful (401 Unauthorized): Unauthorized") |
153 | 137 | end |
154 | 138 | end |
155 | 139 |
|
156 | 140 | context "when not successful" do |
157 | 141 | before do |
158 | 142 | stub_funds(status: 511, body: "") |
159 | | - stub_authenticate |
160 | 143 | end |
161 | 144 |
|
162 | 145 | it "raises Error::Request" do |
|
185 | 168 |
|
186 | 169 | context "not successful" do |
187 | 170 | it "raises error if response is not 200" do |
188 | | - stub_authenticate |
189 | 171 | stub_funds(status: 500, body: any_json(status: 500)) |
190 | 172 | expect { connection.request_and_parse(path: "/funds") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful (500 Internal Server Error): Internal Server Error") |
191 | 173 | end |
|
207 | 189 |
|
208 | 190 | context "200 status but success = false" do |
209 | 191 | it "raises Error::Request" do |
210 | | - stub_authenticate |
211 | 192 | stub_contributions_find(parent_id: 30, description: "error") |
212 | 193 | expect { connection.request_and_parse(path: "/contributions/30") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful: Error: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: '429955534343434'") |
213 | 194 | end |
|
0 commit comments