defra_ruby_mocks 2.0.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -5
- data/app/controllers/defra_ruby_mocks/company_controller.rb +8 -1
- data/app/controllers/defra_ruby_mocks/worldpay_controller.rb +1 -0
- data/app/services/defra_ruby_mocks/companies_house_service.rb +12 -2
- data/app/views/defra_ruby_mocks/company/officers.json.erb +26 -0
- data/app/views/defra_ruby_mocks/company/show.json.erb +10 -1
- data/config/routes.rb +8 -3
- data/lib/defra_ruby_mocks/configuration.rb +1 -2
- data/lib/defra_ruby_mocks/version.rb +1 -1
- data/spec/dummy/log/test.log +2607 -0
- data/spec/examples.txt +114 -0
- data/spec/requests/company_spec.rb +13 -2
- data/spec/requests/officers_spec.rb +37 -0
- data/spec/requests/worldpay_spec.rb +3 -3
- data/spec/services/companies_house_service_spec.rb +28 -6
- data/spec/services/worldpay_response_service_spec.rb +0 -1
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8db113c494c3e74f9f41a01055afcab1a917708e5ba35997d7f9dcd6829f342
|
4
|
+
data.tar.gz: 6790a0a43812ae7eda27aa51096a846b1b0bda32ca2229a8c55c1bed9e3277cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50a22b6011b95c82f65a20033d90e0b7622381e64aa9175a328a26e27b519203a2f5a72e7e2effa247514b130a675a5390144e7d68bee270315d6c74b62dc525
|
7
|
+
data.tar.gz: 3df174fcab0e99ede6b049ba26aecfb36530a476dfb2a1c5e9f7ac688cc662fca18478fa23c5d30f58fbdf1ca8d404d2f8b586078d1ba38ea0090ae88735df52
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# Defra Ruby Mocks
|
2
2
|
|
3
|
-
|
3
|
+
![Build Status](https://github.com/DEFRA/defra-ruby-mocks/workflows/CI/badge.svg?branch=main)
|
4
4
|
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-mocks&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-mocks)
|
5
5
|
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-mocks&metric=coverage)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-mocks)
|
6
|
-
[![security](https://hakiri.io/github/DEFRA/defra-ruby-mocks/main.svg)](https://hakiri.io/github/DEFRA/defra-ruby-mocks/main)
|
7
6
|
[![Licence](https://img.shields.io/badge/Licence-OGLv3-blue.svg)](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3)
|
8
7
|
|
9
8
|
A Rails Engine used by the [Ruby services team](https://github.com/DEFRA/ruby-services-team) in their digital services.
|
@@ -71,14 +70,38 @@ The project currently mocks the following services.
|
|
71
70
|
|
72
71
|
When mounted into an app you can make requests to `/mocks/company/[company number]` to get a response that matches what our apps expect.
|
73
72
|
|
74
|
-
This is an important distinction to note. When our apps like the [Waste Exemptions front office](https://github.com/DEFRA/waste-exemptions-front-office) make a real request to Companies House, they get a lot more information back in the JSON reponse. However the only
|
73
|
+
This is an important distinction to note. When our apps like the [Waste Exemptions front office](https://github.com/DEFRA/waste-exemptions-front-office) make a real request to Companies House, they get a lot more information back in the JSON reponse. However the only things they are interested in are the value of `"company_name"`, `"company_status"`, `"company_type"` and `"registered_office"`, .
|
75
74
|
|
76
|
-
So rather than maintain a lot of unused JSON data, the mock just returns
|
75
|
+
So rather than maintain a lot of unused JSON data, the mock just returns those bits of the JSON.
|
77
76
|
|
78
77
|
```bash
|
79
78
|
curl http://localhost:3000/mocks/company/SC123456
|
80
79
|
{
|
81
|
-
"
|
80
|
+
"company_name": "Acme Industries",
|
81
|
+
"company_status": "active",
|
82
|
+
"company_type": "ltd",
|
83
|
+
"registered_office_address": {
|
84
|
+
"address_line_1": "10 Downing St",
|
85
|
+
"address_line_2": "Horizon House",
|
86
|
+
"locality": "Bristol",
|
87
|
+
"postal_code": "BS1 5AH"
|
88
|
+
}
|
89
|
+
}
|
90
|
+
```
|
91
|
+
|
92
|
+
Additionally, an Officers endpoint is available at `/mocks/company/[company number]/officers`. This returns a list of partial Officer data, eg:
|
93
|
+
```bash
|
94
|
+
curl http://localhost:3000/mocks/company/SC123456/officers
|
95
|
+
{
|
96
|
+
"items": [
|
97
|
+
{
|
98
|
+
"name": "APPLE, Alice",
|
99
|
+
"officer_role": "director"
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"name": "BANANA, Bob",
|
103
|
+
"officer_role": "director"
|
104
|
+
},...
|
82
105
|
}
|
83
106
|
```
|
84
107
|
|
@@ -99,6 +122,11 @@ The exceptions to this are the 'special' numbers listed below. Use them if you a
|
|
99
122
|
- `33333333` will return `"open"`
|
100
123
|
- `22222222` will return `"closed"`
|
101
124
|
|
125
|
+
Additionally, an `"active"` LLP company can be retrieved by using the following registration numbers:
|
126
|
+
|
127
|
+
- `XX999999`
|
128
|
+
- `YY999999`
|
129
|
+
|
102
130
|
The list of possible statuses was taken from
|
103
131
|
|
104
132
|
- [Companies House API](https://developer.companieshouse.gov.uk/api/docs/company/company_number/companyProfile-resource.html)
|
@@ -6,13 +6,20 @@ module DefraRubyMocks
|
|
6
6
|
before_action :set_default_response_format
|
7
7
|
|
8
8
|
def show
|
9
|
-
|
9
|
+
service = CompaniesHouseService.run(params[:id])
|
10
|
+
|
11
|
+
@company_status = service.company_status
|
12
|
+
@company_type = service.company_type
|
10
13
|
|
11
14
|
respond_to :json
|
12
15
|
rescue NotFoundError
|
13
16
|
render "not_found", status: 404
|
14
17
|
end
|
15
18
|
|
19
|
+
def officers
|
20
|
+
respond_to :json
|
21
|
+
end
|
22
|
+
|
16
23
|
private
|
17
24
|
|
18
25
|
def set_default_response_format
|
@@ -31,15 +31,22 @@ module DefraRubyMocks
|
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
+
def self.llp_company_numbers
|
35
|
+
%w[XX999999 YY999999]
|
36
|
+
end
|
37
|
+
|
34
38
|
def run(company_number)
|
35
39
|
raise NotFoundError unless valid_company_number?(company_number)
|
36
40
|
raise NotFoundError if company_number == NOT_FOUND
|
37
41
|
|
38
|
-
|
42
|
+
@company_status = specials[company_number] || "active"
|
43
|
+
@company_type = llps.include?(company_number) ? "llp" : "ltd"
|
39
44
|
|
40
|
-
|
45
|
+
self
|
41
46
|
end
|
42
47
|
|
48
|
+
attr_reader :company_status, :company_type
|
49
|
+
|
43
50
|
private
|
44
51
|
|
45
52
|
def valid_company_number?(company_number)
|
@@ -50,5 +57,8 @@ module DefraRubyMocks
|
|
50
57
|
self.class.special_company_numbers
|
51
58
|
end
|
52
59
|
|
60
|
+
def llps
|
61
|
+
self.class.llp_company_numbers
|
62
|
+
end
|
53
63
|
end
|
54
64
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// https://developer-specs.company-information.service.gov.uk/companies-house-public-data-api/resources/officerlist
|
2
|
+
{
|
3
|
+
"items": [
|
4
|
+
{
|
5
|
+
"name": "APPLE, Alice",
|
6
|
+
"officer_role": "director"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"name": "BANANA, Bob",
|
10
|
+
"officer_role": "director"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"name": "CARROT, Charlie",
|
14
|
+
"officer_role": "director",
|
15
|
+
"resigned_on": "2020-01-21"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"name": "DONUT, Dave Dickie",
|
19
|
+
"officer_role": "llp-member"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"name": "ENDIVE, Eve Marie",
|
23
|
+
"officer_role": "llp-designated-member"
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}
|
@@ -1,3 +1,12 @@
|
|
1
|
+
// https://developer-specs.company-information.service.gov.uk/companies-house-public-data-api/resources/companyprofile
|
1
2
|
{
|
2
|
-
"
|
3
|
+
"company_name": "Acme Industries",
|
4
|
+
"company_status": "<%= @company_status %>",
|
5
|
+
"type": "<%= @company_type %>",
|
6
|
+
"registered_office_address": {
|
7
|
+
"address_line_1": "10 Downing St",
|
8
|
+
"address_line_2": "Horizon House",
|
9
|
+
"locality": "Bristol",
|
10
|
+
"postal_code": "BS1 5AH"
|
11
|
+
}
|
3
12
|
}
|
data/config/routes.rb
CHANGED
@@ -6,11 +6,16 @@ DefraRubyMocks::Engine.routes.draw do
|
|
6
6
|
as: "company",
|
7
7
|
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
8
8
|
|
9
|
-
get "/
|
10
|
-
to: "
|
11
|
-
as: "
|
9
|
+
get "/company/:id/officers",
|
10
|
+
to: "company#officers",
|
11
|
+
as: "company_officers",
|
12
12
|
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
13
13
|
|
14
|
+
post "/worldpay/payments-service",
|
15
|
+
to: "worldpay#payments_service",
|
16
|
+
as: "worldpay_payments_service",
|
17
|
+
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
18
|
+
|
14
19
|
get "/worldpay/dispatcher",
|
15
20
|
to: "worldpay#dispatcher",
|
16
21
|
as: "worldpay_dispatcher",
|
@@ -5,8 +5,7 @@ module DefraRubyMocks
|
|
5
5
|
|
6
6
|
DEFAULT_DELAY = 1000
|
7
7
|
|
8
|
-
attr_accessor :worldpay_admin_code, :worldpay_mac_secret
|
9
|
-
attr_accessor :worldpay_merchant_code, :worldpay_domain
|
8
|
+
attr_accessor :worldpay_admin_code, :worldpay_mac_secret, :worldpay_merchant_code, :worldpay_domain
|
10
9
|
attr_reader :delay
|
11
10
|
|
12
11
|
def initialize
|