defra_ruby_mocks 2.1.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2400c544251ae5e153675efe7553c5fab5f1f7f85d22070dcc3ad638d57f37c4
4
- data.tar.gz: 0a0f9539751608fe818abb95441827cb870454221f6adf2560a3ea10a4bcad88
3
+ metadata.gz: 234acb79fe01017da60fcef23605cd3ff4506fefb54765f29cbe707533016ba2
4
+ data.tar.gz: 4a52336dbd39d3c03ffab8b96f7d1c4b90ca83af1dca3ffb72973635f85d40e1
5
5
  SHA512:
6
- metadata.gz: db8efa881a745c8b16c36b60d24ad7e2edc29a1ff237b060013289801be216e93e3af808b34f49aeddff80eb0855d9217b956c35080c72f83c84a243f98ccde3
7
- data.tar.gz: da2b9925edb39db3c89b8794a8bc184550cb5972affaf2978f8ea3c9302a6ab7d1d84dbf6c74bbebaa47f864cb17c369a1e4fa216ed6a15ec508b66ccc500d3e
6
+ metadata.gz: 6f5256bb6536f34b6d7aa373bd02f6ba9e7c200cbfcf7c344d5f0ab127d960ba3768c73b3c150a6b4c3d46e2c405d76dd4f5ea8ab784ad9f22a852db8a330414
7
+ data.tar.gz: da3cfafbe7aa6939ca4cec698f00b982b004da1cf39bfcb97e26d72a4b219e9e6df88cea29effadfa3ccfbbb9bbbf6bb058671cd34db71b80fe9ab607e98f5ee
data/README.md CHANGED
@@ -3,7 +3,6 @@
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 thing they are interested in is the value of `"company_status"`.
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 that bit of the JSON.
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
- "company_status": "active"
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
- @status = CompaniesHouseService.run(params[:id])
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
@@ -2,6 +2,7 @@
2
2
 
3
3
  module DefraRubyMocks
4
4
  class WorldpayController < ::DefraRubyMocks::ApplicationController
5
+ protect_from_forgery with: :exception, except: [:payments_service]
5
6
 
6
7
  before_action :set_default_response_format
7
8
 
@@ -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
- return specials[company_number] if specials.key?(company_number)
42
+ @company_status = specials[company_number] || "active"
43
+ @company_type = llps.include?(company_number) ? "llp" : "ltd"
39
44
 
40
- "active"
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
@@ -46,9 +46,9 @@ module DefraRubyMocks
46
46
 
47
47
  def company_name
48
48
  if resource.class.to_s == "WasteCarriersEngine::OrderCopyCardsRegistration"
49
- locate_original_registration(resource.reg_identifier).company_name.downcase
49
+ locate_original_registration(resource.reg_identifier).company_name&.downcase
50
50
  else
51
- resource.company_name.downcase
51
+ resource.company_name&.downcase
52
52
  end
53
53
  end
54
54
  end
@@ -65,6 +65,8 @@ module DefraRubyMocks
65
65
  end
66
66
 
67
67
  def payment_status
68
+ return :AUTHORISED unless @resource.company_name
69
+
68
70
  return :REFUSED if @resource.company_name.include?("reject")
69
71
  return :STUCK if @resource.company_name.include?("stuck")
70
72
  return :SENT_FOR_AUTHORISATION if @resource.company_name.include?("pending")
@@ -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
- "company_status": "<%= @status %>"
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 "/worldpay/payments-service",
10
- to: "worldpay#payments_service",
11
- as: "worldpay_payments_service",
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMocks
4
- VERSION = "2.1.0"
4
+ VERSION = "2.3.1"
5
5
  end