Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-26 02:50:28 +01:00
Add failing API call test
Dieser Commit ist enthalten in:
Ursprung
3e2907abc2
Commit
e5fbc408f5
1 geänderte Dateien mit 24 neuen und 1 gelöschten Zeilen
|
@ -269,7 +269,7 @@ describe CustomWizard::Action do
|
||||||
expect(group.users.first.username).to eq('angus')
|
expect(group.users.first.username).to eq('angus')
|
||||||
end
|
end
|
||||||
|
|
||||||
it '#send_to_api' do
|
it '#send_to_api successful' do
|
||||||
stub_request(:put, "https://myexternalapi.com/update").
|
stub_request(:put, "https://myexternalapi.com/update").
|
||||||
with(
|
with(
|
||||||
body: "some_body",
|
body: "some_body",
|
||||||
|
@ -291,6 +291,29 @@ describe CustomWizard::Action do
|
||||||
expect(result).to eq('success')
|
expect(result).to eq('success')
|
||||||
expect(log_entry.status).to eq('SUCCESS')
|
expect(log_entry.status).to eq('SUCCESS')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it '#send_to_api failure' do
|
||||||
|
stub_request(:put, "https://myexternalapi.com/update").
|
||||||
|
with(
|
||||||
|
body: "some_body",
|
||||||
|
headers: {
|
||||||
|
'Host'=>'myexternalapi.com'
|
||||||
|
}).
|
||||||
|
to_return(status: 500, body: "failure", headers: {})
|
||||||
|
|
||||||
|
new_api = CustomWizard::Api.new("my_api")
|
||||||
|
CustomWizard::Api.set("my_api", title: "Mocked external api")
|
||||||
|
CustomWizard::Api::Authorization.set("my_api", api_test_no_authorization)
|
||||||
|
CustomWizard::Api::Endpoint.new("my_api")
|
||||||
|
CustomWizard::Api::Endpoint.set("my_api", api_test_endpoint)
|
||||||
|
endpoint_id = CustomWizard::Api::Endpoint.list("my_api").first.id
|
||||||
|
|
||||||
|
result = CustomWizard::Api::Endpoint.request("my_api", endpoint_id, "some_body")
|
||||||
|
log_entry = CustomWizard::Api::LogEntry.list("my_api").first
|
||||||
|
|
||||||
|
expect(result).to eq('failure')
|
||||||
|
expect(log_entry.status).to eq('FAILURE')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren