defra_ruby_mocks 2.4.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/defra_ruby_mocks/govpay_controller.rb +33 -3
- data/app/services/defra_ruby_mocks/companies_house_service.rb +1 -3
- data/app/services/defra_ruby_mocks/govpay_create_payment_service.rb +20 -20
- data/app/services/defra_ruby_mocks/govpay_get_payment_service.rb +50 -50
- data/app/services/defra_ruby_mocks/govpay_refund_details_service.rb +6 -6
- data/app/services/defra_ruby_mocks/govpay_request_refund_service.rb +4 -4
- data/config/routes.rb +6 -1
- data/lib/defra_ruby_mocks/version.rb +1 -1
- data/lib/defra_ruby_mocks.rb +0 -6
- metadata +12 -209
- data/app/jobs/defra_ruby_mocks/application_job.rb +0 -6
- data/app/jobs/defra_ruby_mocks/govpay_payment_callback_job.rb +0 -17
- data/spec/defra_ruby_mocks_spec.rb +0 -44
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/config/application.rb +0 -27
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -38
- data/spec/dummy/config/environments/production.rb +0 -76
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +0 -10
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -9
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -4
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/log/test.log +0 -2013
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/examples.txt +0 -68
- data/spec/fixtures/files/govpay/create_payment_created_response.json +0 -24
- data/spec/fixtures/files/govpay/create_payment_error_response.json +0 -5
- data/spec/fixtures/files/govpay/get_payment_response_cancelled.json +0 -61
- data/spec/fixtures/files/govpay/get_payment_response_created.json +0 -73
- data/spec/fixtures/files/govpay/get_payment_response_error.json +0 -5
- data/spec/fixtures/files/govpay/get_payment_response_failure.json +0 -9
- data/spec/fixtures/files/govpay/get_payment_response_not_found.json +0 -4
- data/spec/fixtures/files/govpay/get_payment_response_submitted.json +0 -75
- data/spec/fixtures/files/govpay/get_payment_response_success.json +0 -62
- data/spec/lib/configuration_spec.rb +0 -75
- data/spec/rails_helper.rb +0 -46
- data/spec/requests/company_spec.rb +0 -91
- data/spec/requests/govpay_spec.rb +0 -170
- data/spec/requests/officers_spec.rb +0 -37
- data/spec/services/companies_house_service_spec.rb +0 -69
- data/spec/services/govpay_create_payment_service_spec.rb +0 -44
- data/spec/services/govpay_get_payment_service_spec.rb +0 -30
- data/spec/services/govpay_refund_details_service_spec.rb +0 -58
- data/spec/services/govpay_request_refund_service_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -86
- data/spec/support/helpers/configuration.rb +0 -17
- data/spec/support/helpers/helpers.rb +0 -13
- data/spec/support/helpers/waste_carriers_engine.rb +0 -10
- data/spec/support/helpers/xml_matchers.rb +0 -19
- data/spec/support/pry.rb +0 -7
- data/spec/support/simplecov.rb +0 -17
@@ -1,75 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DefraRubyMocks
|
4
|
-
RSpec.describe Configuration do
|
5
|
-
let(:subject) { described_class.new }
|
6
|
-
|
7
|
-
describe "#enable=" do
|
8
|
-
context "when passed true as boolean" do
|
9
|
-
it "sets enable to 'true'" do
|
10
|
-
subject.enable = true
|
11
|
-
|
12
|
-
expect(subject.enabled?).to be(true)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when passed false as a boolean" do
|
17
|
-
it "sets enable to 'false'" do
|
18
|
-
subject.enable = false
|
19
|
-
|
20
|
-
expect(subject.enabled?).to be(false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when passed true as string" do
|
25
|
-
it "sets enable to 'true'" do
|
26
|
-
subject.enable = "true"
|
27
|
-
|
28
|
-
expect(subject.enabled?).to be(true)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when passed false as a string" do
|
33
|
-
it "sets enable to 'false'" do
|
34
|
-
subject.enable = "false"
|
35
|
-
|
36
|
-
expect(subject.enabled?).to be(false)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#delay=" do
|
42
|
-
context "when passed 200 as an integer" do
|
43
|
-
it "sets delay to 200" do
|
44
|
-
subject.delay = 200
|
45
|
-
|
46
|
-
expect(subject.delay).to be(200)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when passed 200 as a string" do
|
51
|
-
it "sets delay to 200" do
|
52
|
-
subject.delay = "200"
|
53
|
-
|
54
|
-
expect(subject.delay).to be(200)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when passed a string that's not a number" do
|
59
|
-
it "sets delay to its default" do
|
60
|
-
subject.delay = ""
|
61
|
-
|
62
|
-
expect(subject.delay).to be(Configuration::DEFAULT_DELAY)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "when passed nil" do
|
67
|
-
it "sets delay to its default" do
|
68
|
-
subject.delay = nil
|
69
|
-
|
70
|
-
expect(subject.delay).to be(Configuration::DEFAULT_DELAY)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
data/spec/rails_helper.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
4
|
-
require "spec_helper"
|
5
|
-
ENV["RAILS_ENV"] ||= "test"
|
6
|
-
require File.expand_path("dummy/config/environment", __dir__)
|
7
|
-
|
8
|
-
# Prevent database truncation if the environment is production
|
9
|
-
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
10
|
-
require "rspec/rails"
|
11
|
-
# Add additional requires below this line. Rails is not loaded until this point!
|
12
|
-
|
13
|
-
# Requires supporting ruby files with custom matchers and macros, etc, in
|
14
|
-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
15
|
-
# run as spec files by default. This means that files in spec/support that end
|
16
|
-
# in _spec.rb will both be required and run as specs, causing the specs to be
|
17
|
-
# run twice. It is recommended that you do not name files matching this glob to
|
18
|
-
# end with _spec.rb. You can configure this pattern with the --pattern
|
19
|
-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
20
|
-
#
|
21
|
-
# We make an exception for simplecov because that will already have been
|
22
|
-
# required and run at the very top of spec_helper.rb
|
23
|
-
support_files = Dir["./spec/support/**/*.rb"].reject { |file| file == "./spec/support/simplecov.rb" }
|
24
|
-
support_files.each { |f| require f }
|
25
|
-
|
26
|
-
RSpec.configure do |config|
|
27
|
-
# RSpec Rails can automatically mix in different behaviours to your tests
|
28
|
-
# based on their file location, for example enabling you to call `get` and
|
29
|
-
# `post` in specs under `spec/controllers`.
|
30
|
-
#
|
31
|
-
# You can disable this behaviour by removing the line below, and instead
|
32
|
-
# explicitly tag your specs with their type, e.g.:
|
33
|
-
#
|
34
|
-
# RSpec.describe UsersController, :type => :controller do
|
35
|
-
# # ...
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# The different available types are documented in the features, such as in
|
39
|
-
# https://relishapp.com/rspec/rspec-rails/docs
|
40
|
-
config.infer_spec_type_from_file_location!
|
41
|
-
|
42
|
-
# Filter lines from Rails gems in backtraces.
|
43
|
-
config.filter_rails_from_backtrace!
|
44
|
-
# arbitrary gems may also be filtered via:
|
45
|
-
# config.filter_gems_from_backtrace("gem name")
|
46
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
RSpec.describe "Company", type: :request do
|
7
|
-
after(:all) { Helpers::Configuration.reset_for_tests }
|
8
|
-
|
9
|
-
let(:path) { "/defra_ruby_mocks/company" }
|
10
|
-
|
11
|
-
context "when mocks are enabled" do
|
12
|
-
before(:each) { Helpers::Configuration.prep_for_tests }
|
13
|
-
|
14
|
-
context "when the company number is 99999999 for not found" do
|
15
|
-
let(:company_number) { "99999999" }
|
16
|
-
|
17
|
-
it "returns a JSON response with a code of 404" do
|
18
|
-
get "#{path}/#{company_number}"
|
19
|
-
content = JSON.parse(response.body)
|
20
|
-
|
21
|
-
expect(response.media_type).to eq("application/json")
|
22
|
-
expect(response.code).to eq("404")
|
23
|
-
expect(content).to include("errors")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when the company number is from the 'specials' list" do
|
28
|
-
let(:company_number) { "05868270" }
|
29
|
-
|
30
|
-
it "returns a JSON response with a 200 code and a status that isn't 'active'" do
|
31
|
-
get "#{path}/#{company_number}"
|
32
|
-
|
33
|
-
expect(response.media_type).to eq("application/json")
|
34
|
-
expect(response.code).to eq("200")
|
35
|
-
expect(JSON.parse(response.body).deep_symbolize_keys).to eq(
|
36
|
-
company_name: "Acme Industries",
|
37
|
-
company_status: "dissolved",
|
38
|
-
type: "ltd",
|
39
|
-
registered_office_address: {
|
40
|
-
address_line_1: "10 Downing St",
|
41
|
-
address_line_2: "Horizon House",
|
42
|
-
locality: "Bristol",
|
43
|
-
postal_code: "BS1 5AH"
|
44
|
-
}
|
45
|
-
)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when the company number is not from the 'specials' list" do
|
50
|
-
context "and it is valid" do
|
51
|
-
let(:company_number) { "SC247974" }
|
52
|
-
|
53
|
-
it "returns a JSON response with a 200 code and a status of 'active'" do
|
54
|
-
get "#{path}/#{company_number}"
|
55
|
-
company_status = JSON.parse(response.body)["company_status"]
|
56
|
-
company_type = JSON.parse(response.body)["type"]
|
57
|
-
|
58
|
-
expect(response.media_type).to eq("application/json")
|
59
|
-
expect(response.code).to eq("200")
|
60
|
-
expect(company_status).to eq("active")
|
61
|
-
expect(company_type).to eq("ltd")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "and it is not valid" do
|
66
|
-
let(:company_number) { "foo" }
|
67
|
-
|
68
|
-
it "returns a JSON response with a 404 code" do
|
69
|
-
get "#{path}/#{company_number}"
|
70
|
-
content = JSON.parse(response.body)
|
71
|
-
|
72
|
-
expect(response.media_type).to eq("application/json")
|
73
|
-
expect(response.code).to eq("404")
|
74
|
-
expect(content).to include("errors")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "when mocks are disabled" do
|
81
|
-
before(:all) { DefraRubyMocks.configuration.enable = false }
|
82
|
-
|
83
|
-
let(:company_number) { "SC247974" }
|
84
|
-
|
85
|
-
it "cannot load the page" do
|
86
|
-
expect { get "#{path}/#{company_number}" }.to raise_error(ActionController::RoutingError)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
RSpec.describe "Govpay", type: :request do
|
7
|
-
after(:all) { Helpers::Configuration.reset_for_tests }
|
8
|
-
|
9
|
-
context "when mocks are enabled" do
|
10
|
-
before(:each) do
|
11
|
-
Helpers::Configuration.prep_for_tests
|
12
|
-
DefraRubyMocks.configure do |config|
|
13
|
-
config.govpay_domain = "http://localhost:3000/defra_ruby_mocks"
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
context "#create_payment" do
|
19
|
-
let(:path) { "/defra_ruby_mocks/govpay/v1/payments" }
|
20
|
-
# Use an example from the Govpay documentation
|
21
|
-
let(:payment_request) do
|
22
|
-
{
|
23
|
-
amount: 14_500,
|
24
|
-
reference: "12345",
|
25
|
-
description: "Pay your council tax",
|
26
|
-
return_url: "https://your.service.gov.uk/completed"
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when the request is valid" do
|
31
|
-
|
32
|
-
it "returns a valid success response" do
|
33
|
-
post path, params: payment_request.as_json
|
34
|
-
|
35
|
-
expect(response.media_type).to eq("application/json")
|
36
|
-
expect(response.code).to eq("200")
|
37
|
-
response_json = JSON.parse(response.body)
|
38
|
-
expect(response_json["reference"]).to eq payment_request[:reference]
|
39
|
-
expect(response_json["amount"]).to eq payment_request[:amount]
|
40
|
-
expect(response_json["description"]).to eq payment_request[:description]
|
41
|
-
expect(response_json["_links"]["next_url"]["href"]).to eq payment_request[:return_url]
|
42
|
-
end
|
43
|
-
|
44
|
-
it "enqueues a job to perform the payment callback" do
|
45
|
-
ActiveJob::Base.queue_adapter = :test
|
46
|
-
expect { post path, params: payment_request.as_json }.to have_enqueued_job(GovpayPaymentCallbackJob)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when the request is missing a mandatory parameter" do
|
51
|
-
before { payment_request[:amount] = nil }
|
52
|
-
|
53
|
-
it "returns a HTTP 500 response" do
|
54
|
-
post path, params: payment_request.as_json
|
55
|
-
|
56
|
-
expect(response.code).to eq "500"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#payment_details" do
|
62
|
-
let(:path) { "/defra_ruby_mocks/govpay/v1/payments/#{payment_id}" }
|
63
|
-
|
64
|
-
context "when the payment id is valid" do
|
65
|
-
before do
|
66
|
-
allow(GovpayGetPaymentService).to receive(:run)
|
67
|
-
.with(payment_id)
|
68
|
-
.and_return(JSON.parse(File.read("spec/fixtures/files/govpay/get_payment_response_success.json")))
|
69
|
-
end
|
70
|
-
|
71
|
-
let(:payment_id) { "12345678901234567890123456" }
|
72
|
-
|
73
|
-
it "returns a valid success response" do
|
74
|
-
get path
|
75
|
-
|
76
|
-
expect(response.code).to eq "200"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "when the payment id is not valid" do
|
81
|
-
before do
|
82
|
-
allow(GovpayGetPaymentService).to receive(:run)
|
83
|
-
.with(payment_id)
|
84
|
-
.and_return(JSON.parse(File.read("spec/fixtures/files/govpay/get_payment_response_error.json")))
|
85
|
-
end
|
86
|
-
|
87
|
-
let(:payment_id) { "0" }
|
88
|
-
|
89
|
-
it "returns a 422 response" do
|
90
|
-
get path
|
91
|
-
|
92
|
-
expect(response.code).to eq "422"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#create_refund" do
|
98
|
-
let(:payment_id) { "12345678901234567890123456" }
|
99
|
-
let(:path) { "/defra_ruby_mocks/govpay/v1/payments/#{payment_id}/refunds" }
|
100
|
-
let(:refund_request) do
|
101
|
-
{
|
102
|
-
"amount": 2000,
|
103
|
-
"refund_amount_available": 5000
|
104
|
-
}
|
105
|
-
end
|
106
|
-
|
107
|
-
context "when the request is missing a mandatory parameter" do
|
108
|
-
before { refund_request[:refund_amount_available] = nil }
|
109
|
-
|
110
|
-
it "returns a HTTP 500 response" do
|
111
|
-
post path, params: refund_request.as_json
|
112
|
-
|
113
|
-
expect(response.code).to eq "500"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "with a valid request" do
|
118
|
-
it "returns a valid success response" do
|
119
|
-
post path, params: refund_request.as_json
|
120
|
-
|
121
|
-
expect(response.code).to eq "200"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "#refund_details" do
|
127
|
-
let(:payment_id) { "12345678901234567890123456" }
|
128
|
-
let(:refund_id) { "j6se0f2o427g28g8yg3u3i" }
|
129
|
-
let(:path) { "/defra_ruby_mocks/govpay/v1/payments/#{payment_id}/refunds/#{refund_id}" }
|
130
|
-
|
131
|
-
context "with a valid request" do
|
132
|
-
it "returns a valid success response" do
|
133
|
-
get path
|
134
|
-
|
135
|
-
expect(response.code).to eq "200"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "when mocks are disabled" do
|
142
|
-
before(:each) { DefraRubyMocks.configuration.enable = false }
|
143
|
-
let(:payment_id) { Faker::Alphanumeric.alphanumeric(number: 26) }
|
144
|
-
|
145
|
-
context "POST #govpay_payments" do
|
146
|
-
let(:path) { "/defra_ruby_mocks/govpay/payments" }
|
147
|
-
|
148
|
-
it "cannot load the page" do
|
149
|
-
expect { post path }.to raise_error(ActionController::RoutingError)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context "GET #govpay_payments" do
|
154
|
-
let(:path) { "/defra_ruby_mocks/govpay/payments/#{payment_id}" }
|
155
|
-
|
156
|
-
it "cannot load the page" do
|
157
|
-
expect { get path }.to raise_error(ActionController::RoutingError)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context "#govpay_refunds" do
|
162
|
-
let(:path) { "/defra_ruby_mocks/govpay/#{payment_id}/refunds" }
|
163
|
-
|
164
|
-
it "cannot load the page" do
|
165
|
-
expect { post path }.to raise_error(ActionController::RoutingError)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
RSpec.describe "Officers", type: :request do
|
7
|
-
after(:all) { Helpers::Configuration.reset_for_tests }
|
8
|
-
|
9
|
-
let(:path) { "/defra_ruby_mocks/company/company-no/officers" }
|
10
|
-
|
11
|
-
context "when mocks are enabled" do
|
12
|
-
before(:each) { Helpers::Configuration.prep_for_tests }
|
13
|
-
|
14
|
-
it "returns a JSON response" do
|
15
|
-
get path
|
16
|
-
|
17
|
-
expect(response.media_type).to eq("application/json")
|
18
|
-
expect(response.code).to eq("200")
|
19
|
-
|
20
|
-
expect(JSON.parse(response.body).deep_symbolize_keys[:items][0]).to eq(
|
21
|
-
{
|
22
|
-
name: "APPLE, Alice",
|
23
|
-
officer_role: "director"
|
24
|
-
}
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when mocks are disabled" do
|
30
|
-
before(:all) { DefraRubyMocks.configuration.enable = false }
|
31
|
-
|
32
|
-
it "cannot load the page" do
|
33
|
-
expect { get path }.to raise_error(ActionController::RoutingError)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
RSpec.describe CompaniesHouseService do
|
7
|
-
describe ".run" do
|
8
|
-
subject { described_class.run(company_number) }
|
9
|
-
|
10
|
-
context "when the company number is 99999999 for not found" do
|
11
|
-
let(:company_number) { "99999999" }
|
12
|
-
|
13
|
-
it "raises a NotFoundError" do
|
14
|
-
expect { subject }.to raise_error(NotFoundError)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when the company number is from the 'specials' list" do
|
19
|
-
specials = CompaniesHouseService.special_company_numbers
|
20
|
-
|
21
|
-
specials.each do |company_number, status|
|
22
|
-
context "and the number is #{company_number}" do
|
23
|
-
let(:company_number) { company_number }
|
24
|
-
|
25
|
-
it "returns a company_status of '#{status}'" do
|
26
|
-
expect(subject.company_status).to eq(status)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns a company_type of 'ltd'" do
|
30
|
-
expect(subject.company_type).to eq("ltd")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when the company is an LLP" do
|
37
|
-
CompaniesHouseService.llp_company_numbers.each do |company_number|
|
38
|
-
let(:company_number) { company_number }
|
39
|
-
|
40
|
-
it "returns a company_status of 'active'" do
|
41
|
-
expect(subject.company_status).to eq("active")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns a company_type of 'llp'" do
|
45
|
-
expect(subject.company_type).to eq("llp")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when the company number is not from the 'specials' list" do
|
51
|
-
context "and it is valid" do
|
52
|
-
let(:company_number) { "SC247974" }
|
53
|
-
|
54
|
-
it "returns a company_status of 'active'" do
|
55
|
-
expect(subject.company_status).to eq("active")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "and it is not valid" do
|
60
|
-
let(:company_number) { "foo" }
|
61
|
-
|
62
|
-
it "raises a NotFoundError" do
|
63
|
-
expect { subject }.to raise_error(NotFoundError)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
|
7
|
-
RSpec.describe GovpayCreatePaymentService do
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
Helpers::Configuration.prep_for_tests
|
11
|
-
DefraRubyMocks.configure do |config|
|
12
|
-
config.govpay_domain = "http://localhost:3000/defra_ruby_mocks"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:amount) { Faker::Number.number(digits: 4) }
|
17
|
-
let(:description) { Faker::Lorem.sentence }
|
18
|
-
let(:return_url) { Faker::Internet.url }
|
19
|
-
|
20
|
-
describe ".run" do
|
21
|
-
|
22
|
-
subject { described_class.run(amount: amount, description: description, return_url: return_url).deep_symbolize_keys }
|
23
|
-
|
24
|
-
context "for a valid payment request" do
|
25
|
-
|
26
|
-
it "returns a payment response with the order amount" do
|
27
|
-
expect(subject[:amount]).to eq(amount)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns a payment response with the description" do
|
31
|
-
expect(subject[:description]).to eq(description)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns a payment response with the return_url" do
|
35
|
-
expect(subject[:_links][:next_url][:href]).to eq(return_url)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "returns the expected status" do
|
39
|
-
expect(subject[:state][:status]).to eq("created")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
|
7
|
-
RSpec.describe GovpayGetPaymentService do
|
8
|
-
before { Helpers::Configuration.prep_for_tests }
|
9
|
-
|
10
|
-
let(:order_value) { Faker::Number.number(digits: 4) }
|
11
|
-
let(:payment_id) { SecureRandom.hex(26) }
|
12
|
-
|
13
|
-
# Note that the service currently supports only success responses.
|
14
|
-
describe ".run" do
|
15
|
-
|
16
|
-
subject { described_class.run(payment_id: payment_id, amount: order_value).deep_symbolize_keys }
|
17
|
-
|
18
|
-
context "when the payment is successful" do
|
19
|
-
|
20
|
-
it "returns a payment with the order amount" do
|
21
|
-
expect(subject[:amount]).to eq(order_value)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns the expected status" do
|
25
|
-
expect(subject[:state][:status]).to eq("success")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
|
7
|
-
RSpec.describe GovpayRefundDetailsService do
|
8
|
-
let(:payment_id) { SecureRandom.hex(26) }
|
9
|
-
let(:refund_id) { SecureRandom.hex(22) }
|
10
|
-
|
11
|
-
before { Helpers::Configuration.prep_for_tests }
|
12
|
-
|
13
|
-
# Note that the service currently supports only success responses.
|
14
|
-
describe ".run" do
|
15
|
-
let(:create_request_time) { Time.zone.now }
|
16
|
-
let(:submitted_success_lag) { "10" }
|
17
|
-
|
18
|
-
subject { described_class.run(payment_id: payment_id, refund_id: refund_id).deep_symbolize_keys }
|
19
|
-
|
20
|
-
# the service shoud return "submitted" for up to GOVPAY_REFUND_SUBMITTED_SUCCESS_LAG seconds, "success" thereafter
|
21
|
-
before do
|
22
|
-
Timecop.freeze(create_request_time)
|
23
|
-
allow(ENV).to receive(:fetch).with("GOVPAY_REFUND_SUBMITTED_SUCCESS_LAG", any_args).and_return(submitted_success_lag)
|
24
|
-
FileUtils.rm_rf("#{Dir.tmpdir}/govpay_request_refund_service_last_run_time")
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when no refund timestamp file exists" do
|
28
|
-
it { expect(subject[:status]).to eq "success" }
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when a refund has been requested" do
|
32
|
-
before do
|
33
|
-
GovpayRequestRefundService.run(payment_id: payment_id, amount: 100, refund_amount_available: 100).deep_symbolize_keys
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when less than 10 seconds has elapsed since the last create request" do
|
37
|
-
before { Timecop.freeze(create_request_time + (submitted_success_lag.to_i - 8).seconds) }
|
38
|
-
|
39
|
-
it { expect(subject[:status]).to eq "submitted" }
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when 10 seconds has elapsed since the last create request" do
|
43
|
-
before { Timecop.freeze(create_request_time + (submitted_success_lag.to_i + 8).seconds) }
|
44
|
-
|
45
|
-
it { expect(subject[:status]).to eq "success" }
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when GOVPAY_REFUND_SUBMITTED_SUCCESS_LAG is not set" do
|
49
|
-
let(:submitted_success_lag) { nil }
|
50
|
-
|
51
|
-
before { Timecop.freeze(create_request_time + 1.hour) }
|
52
|
-
|
53
|
-
it { expect(subject[:status]).to eq "success" }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
|
7
|
-
RSpec.describe GovpayRequestRefundService do
|
8
|
-
let(:payment_id) { SecureRandom.hex(26) }
|
9
|
-
let(:amount) { 2000 }
|
10
|
-
let(:refund_amount_available) { amount }
|
11
|
-
|
12
|
-
before { Helpers::Configuration.prep_for_tests }
|
13
|
-
|
14
|
-
# Note that the service currently supports only "submitted" responses.
|
15
|
-
describe ".run" do
|
16
|
-
|
17
|
-
subject { described_class.run(payment_id: payment_id, amount: amount, refund_amount_available: refund_amount_available).deep_symbolize_keys }
|
18
|
-
|
19
|
-
context "when the refund has been successfully submitted" do
|
20
|
-
|
21
|
-
it "returns a response with the expected status" do
|
22
|
-
expect(subject[:status]).to eq("submitted")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns a response with the expected amount" do
|
26
|
-
expect(subject[:amount]).to eq(amount)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|