Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 17:30:29 +01:00
API: add mocked request spec
Dieser Commit ist enthalten in:
Ursprung
6056351b7c
Commit
5a424e8e3d
5 geänderte Dateien mit 39 neuen und 0 gelöschten Zeilen
|
@ -13,6 +13,9 @@ describe CustomWizard::Action do
|
||||||
let(:add_to_group) { get_wizard_fixture("actions/add_to_group") }
|
let(:add_to_group) { get_wizard_fixture("actions/add_to_group") }
|
||||||
let(:send_message) { get_wizard_fixture("actions/send_message") }
|
let(:send_message) { get_wizard_fixture("actions/send_message") }
|
||||||
let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") }
|
let(:send_message_multi) { get_wizard_fixture("actions/send_message_multi") }
|
||||||
|
let(:api_test_endpoint) { get_wizard_fixture("endpoints/test_endpoint") }
|
||||||
|
let(:api_test_endpoint_body) { get_wizard_fixture("endpoints/test_endpoint_body")}
|
||||||
|
let(:api_test_no_authorization) { get_wizard_fixture("api/no_authorization")}
|
||||||
|
|
||||||
def update_template(template)
|
def update_template(template)
|
||||||
CustomWizard::Template.save(template, skip_jobs: true)
|
CustomWizard::Template.save(template, skip_jobs: true)
|
||||||
|
@ -265,5 +268,29 @@ 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
|
||||||
|
stub_request(:put, "https://myexternalapi.com/update").
|
||||||
|
with(
|
||||||
|
body: "some_body",
|
||||||
|
headers: {
|
||||||
|
'Host'=>'myexternalapi.com'
|
||||||
|
}).
|
||||||
|
to_return(status: 200, body: "success", 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
|
||||||
|
byebug
|
||||||
|
expect(result).to eq('success')
|
||||||
|
expect(log_entry.status).to eq('SUCCESS')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
3
spec/fixtures/api/no_authorization.json
gevendort
Normale Datei
3
spec/fixtures/api/no_authorization.json
gevendort
Normale Datei
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"auth_type": "none"
|
||||||
|
}
|
5
spec/fixtures/endpoints/test_endpoint.json
gevendort
Normale Datei
5
spec/fixtures/endpoints/test_endpoint.json
gevendort
Normale Datei
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"method": "PUT",
|
||||||
|
"url": "https://myexternalapi.com/update",
|
||||||
|
"success_codes": [200]
|
||||||
|
}
|
3
spec/fixtures/endpoints/test_endpoint_body.json
gevendort
Normale Datei
3
spec/fixtures/endpoints/test_endpoint_body.json
gevendort
Normale Datei
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"data": "some_data"
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ require 'oj'
|
||||||
Oj.default_options = Oj.default_options.merge(cache_str: -1)
|
Oj.default_options = Oj.default_options.merge(cache_str: -1)
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
require 'webmock/rspec'
|
||||||
|
|
||||||
def get_wizard_fixture(path)
|
def get_wizard_fixture(path)
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
|
|
Laden …
In neuem Issue referenzieren