companies_house_input_gateway 0.0.6

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/lib/base.rb +9 -0
  3. data/lib/companies_house_input_gateway/client.rb +46 -0
  4. data/lib/companies_house_input_gateway/config.rb +35 -0
  5. data/lib/companies_house_input_gateway/constants.rb +21 -0
  6. data/lib/companies_house_input_gateway/errors/api_error.rb +18 -0
  7. data/lib/companies_house_input_gateway/errors/companies_house_gateway_error.rb +20 -0
  8. data/lib/companies_house_input_gateway/errors/invalid_request_error.rb +12 -0
  9. data/lib/companies_house_input_gateway/errors/invalid_response_error.rb +6 -0
  10. data/lib/companies_house_input_gateway/form_validator.rb +29 -0
  11. data/lib/companies_house_input_gateway/forms/form_abstract_builder.rb +61 -0
  12. data/lib/companies_house_input_gateway/forms/form_company_data_request.rb +20 -0
  13. data/lib/companies_house_input_gateway/forms/form_confirmation_statement.rb +21 -0
  14. data/lib/companies_house_input_gateway/forms/form_get_submission_status.rb +21 -0
  15. data/lib/companies_house_input_gateway/forms/form_returnof_allotment_shares.rb +21 -0
  16. data/lib/companies_house_input_gateway/forms/form_submission.rb +39 -0
  17. data/lib/companies_house_input_gateway/middleware/check_response.rb +30 -0
  18. data/lib/companies_house_input_gateway/request.rb +57 -0
  19. data/lib/companies_house_input_gateway/requests/abstract_performer.rb +52 -0
  20. data/lib/companies_house_input_gateway/requests/company_data_request.rb +9 -0
  21. data/lib/companies_house_input_gateway/requests/confirmation_statement.rb +11 -0
  22. data/lib/companies_house_input_gateway/requests/get_submission_status.rb +9 -0
  23. data/lib/companies_house_input_gateway/requests/returnof_allotment_shares.rb +11 -0
  24. data/lib/companies_house_input_gateway/util.rb +28 -0
  25. data/lib/companies_house_input_gateway/validations/company_data_request.rb +20 -0
  26. data/lib/companies_house_input_gateway/validations/confirmation_statement.rb +96 -0
  27. data/lib/companies_house_input_gateway/validations/form_submission.rb +23 -0
  28. data/lib/companies_house_input_gateway/validations/get_submission_status.rb +24 -0
  29. data/lib/companies_house_input_gateway/validations/returnof_allotment_shares.rb +41 -0
  30. data/lib/companies_house_input_gateway/version.rb +5 -0
  31. data/lib/companies_house_input_gateway/xml_forms_binder.rb +81 -0
  32. data/lib/companies_house_input_gateway.rb +76 -0
  33. data/spec/client_spec.rb +59 -0
  34. data/spec/companies_house_input_gateway_spec.rb +47 -0
  35. data/spec/data_samples.rb +147 -0
  36. data/spec/fixtures/bad_response.xml +35 -0
  37. data/spec/fixtures/response_company_data_request.xml +330 -0
  38. data/spec/fixtures/response_confirmation_statement.xml +28 -0
  39. data/spec/fixtures/response_get_submission_status.xml +40 -0
  40. data/spec/fixtures/response_returnof_allotment_shares.xml +28 -0
  41. data/spec/form_validator_spec.rb +61 -0
  42. data/spec/request_spec.rb +132 -0
  43. data/spec/spec_helper.rb +32 -0
  44. metadata +206 -0
@@ -0,0 +1,330 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope http://xmlgw.companieshouse.gov.uk/v2-1/schema/Egov_ch-v2-0.xsd" xmlns="http://www.govtalk.gov.uk/CM/envelope" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
3
+ <EnvelopeVersion>1.0</EnvelopeVersion>
4
+ <Header>
5
+ <MessageDetails>
6
+ <Class>CompanyDataRequest</Class>
7
+ <Qualifier>response</Qualifier>
8
+ <TransactionID>1</TransactionID>
9
+ <GatewayTest>1</GatewayTest>
10
+ <GatewayTimestamp>2020-10-28T09:59:08-00:00</GatewayTimestamp>
11
+ </MessageDetails>
12
+ <SenderDetails>
13
+ <IDAuthentication>
14
+ <SenderID>b55c5f7d59c2e225ec3dddc17544555d</SenderID>
15
+ <Authentication>
16
+ <Method>CHMD5</Method>
17
+ <Value></Value>
18
+ </Authentication>
19
+ </IDAuthentication>
20
+ <EmailAddress>roman.bihun@globacap.com</EmailAddress>
21
+ </SenderDetails>
22
+ </Header>
23
+ <GovTalkDetails>
24
+ <Keys/>
25
+ </GovTalkDetails>
26
+ <Body>
27
+ <CompanyData>
28
+ <CompanyNumber>03176906</CompanyNumber>
29
+ <CompanyName>MILLENNIUM STADIUM PLC</CompanyName>
30
+ <CompanyCategory>PLC</CompanyCategory>
31
+ <Jurisdiction>EW</Jurisdiction>
32
+ <TradingOnMarket>false</TradingOnMarket>
33
+ <DTR5Applies>false</DTR5Applies>
34
+ <PSCExemptAsTradingOnRegulatedMarket>false</PSCExemptAsTradingOnRegulatedMarket>
35
+ <PSCExemptAsSharesAdmittedOnMarket>false</PSCExemptAsSharesAdmittedOnMarket>
36
+ <PSCExemptAsTradingOnUKRegulatedMarket>false</PSCExemptAsTradingOnUKRegulatedMarket>
37
+ <MadeUpDate>2020-10-28</MadeUpDate>
38
+ <NextDueDate></NextDueDate>
39
+ <RegisteredOfficeAddress>
40
+ <Premise></Premise>
41
+ <Street>Millennium Stadium</Street>
42
+ <Thoroughfare>Westgate Street</Thoroughfare>
43
+ <PostTown>Cardiff</PostTown>
44
+ <Country>UNDEF</Country>
45
+ <Postcode>CF10 1NS</Postcode>
46
+ </RegisteredOfficeAddress>
47
+ <SICCodes>
48
+ <SICCode>9261</SICCode>
49
+ </SICCodes>
50
+ <Officers>
51
+ <Director>
52
+ <Person>
53
+ <Forename>Maldwyn</Forename>
54
+ <Surname>BEYNON</Surname>
55
+ <ServiceAddress>
56
+ <Address>
57
+ <Premise>6</Premise>
58
+ <Street>Birch Grove</Street>
59
+ <PostTown>Brynmawr</PostTown>
60
+ <County>Gwent</County>
61
+ <Postcode>NP23 4TD</Postcode>
62
+ </Address>
63
+ </ServiceAddress>
64
+ <DOB>1932-12-03</DOB>
65
+ <Nationality>British</Nationality>
66
+ <Occupation>Financial Arranger</Occupation>
67
+ <CountryOfResidence></CountryOfResidence>
68
+ </Person>
69
+ <AppointmentDate>2001-08-02</AppointmentDate>
70
+ </Director>
71
+ <Director>
72
+ <Person>
73
+ <Forename>David</Forename>
74
+ <Forename>George</Forename>
75
+ <Surname>COLLINS</Surname>
76
+ <ServiceAddress>
77
+ <Address>
78
+ <Premise>157</Premise>
79
+ <Street>King George V Drive East</Street>
80
+ <PostTown>Cardiff</PostTown>
81
+ <County>South Glamorgan</County>
82
+ <Postcode>CF14 4EN</Postcode>
83
+ </Address>
84
+ </ServiceAddress>
85
+ <DOB>1945-01-05</DOB>
86
+ <Nationality>British</Nationality>
87
+ <Occupation>Secretary General</Occupation>
88
+ <CountryOfResidence></CountryOfResidence>
89
+ </Person>
90
+ <AppointmentDate>2008-12-01</AppointmentDate>
91
+ </Director>
92
+ <Director>
93
+ <Person>
94
+ <Forename>Byron</Forename>
95
+ <Surname>DAVIES</Surname>
96
+ <ServiceAddress>
97
+ <Address>
98
+ <Premise></Premise>
99
+ <Street>The Cottage</Street>
100
+ <Thoroughfare>Ystradowen</Thoroughfare>
101
+ <PostTown>Cowbridge</PostTown>
102
+ <County>South Glamorgan</County>
103
+ <Postcode>CF71 7SZ</Postcode>
104
+ </Address>
105
+ </ServiceAddress>
106
+ <DOB>1947-04-23</DOB>
107
+ <Nationality>British</Nationality>
108
+ <Occupation>Chief Executive Cardiff Cc</Occupation>
109
+ <CountryOfResidence></CountryOfResidence>
110
+ </Person>
111
+ <AppointmentDate>1996-11-20</AppointmentDate>
112
+ </Director>
113
+ <Director>
114
+ <Person>
115
+ <Forename>Martin</Forename>
116
+ <Forename>Rodney</Forename>
117
+ <Surname>DAVIES</Surname>
118
+ <ServiceAddress>
119
+ <Address>
120
+ <Premise></Premise>
121
+ <Street>Ferndale</Street>
122
+ <Thoroughfare>Ty Draw Road Lisvane</Thoroughfare>
123
+ <PostTown>Cardiff</PostTown>
124
+ <County>South Glamorgan</County>
125
+ <Postcode>CF14 0PF</Postcode>
126
+ </Address>
127
+ </ServiceAddress>
128
+ <DOB>1942-05-17</DOB>
129
+ <Nationality>British</Nationality>
130
+ <Occupation>Retired Chartered Accountants</Occupation>
131
+ <CountryOfResidence></CountryOfResidence>
132
+ </Person>
133
+ <AppointmentDate>2003-08-07</AppointmentDate>
134
+ </Director>
135
+ <Director>
136
+ <Person>
137
+ <Forename>Geraint</Forename>
138
+ <Surname>EDWARDS</Surname>
139
+ <ServiceAddress>
140
+ <Address>
141
+ <Premise>6</Premise>
142
+ <Street>Hendremawr Close</Street>
143
+ <Thoroughfare>Sketty</Thoroughfare>
144
+ <PostTown>Swansea</PostTown>
145
+ <County>West Glamorgan</County>
146
+ <Postcode>SA2 9ND</Postcode>
147
+ </Address>
148
+ </ServiceAddress>
149
+ <DOB>1940-09-21</DOB>
150
+ <Nationality>British</Nationality>
151
+ <Occupation>Retired Engineer</Occupation>
152
+ <CountryOfResidence></CountryOfResidence>
153
+ </Person>
154
+ <AppointmentDate>2006-12-28</AppointmentDate>
155
+ </Director>
156
+ <Director>
157
+ <Person>
158
+ <Forename>Kenneth</Forename>
159
+ <Forename>James</Forename>
160
+ <Surname>HEWITT</Surname>
161
+ <ServiceAddress>
162
+ <Address>
163
+ <Premise></Premise>
164
+ <Street>Green Meadows</Street>
165
+ <Thoroughfare>Llanfihangel Crucorney</Thoroughfare>
166
+ <PostTown>Abergavenny</PostTown>
167
+ <County>Monmouthshire</County>
168
+ <Postcode>NP7 7LB</Postcode>
169
+ </Address>
170
+ </ServiceAddress>
171
+ <DOB>1936-07-09</DOB>
172
+ <Nationality>British</Nationality>
173
+ <Occupation>Retired Headteacher</Occupation>
174
+ <CountryOfResidence></CountryOfResidence>
175
+ </Person>
176
+ <AppointmentDate>1996-11-20</AppointmentDate>
177
+ </Director>
178
+ <Director>
179
+ <Person>
180
+ <Title>Cllr</Title>
181
+ <Forename>Nigel</Forename>
182
+ <Surname>HOWELLS</Surname>
183
+ <ServiceAddress>
184
+ <Address>
185
+ <Premise>59</Premise>
186
+ <Street>Cecil Street</Street>
187
+ <PostTown>Cardiff</PostTown>
188
+ <County>South Glamorgan</County>
189
+ <Postcode>CF24 1NW</Postcode>
190
+ </Address>
191
+ </ServiceAddress>
192
+ <DOB>1966-08-11</DOB>
193
+ <Nationality>British</Nationality>
194
+ <Occupation>Chartered Accountant</Occupation>
195
+ <CountryOfResidence></CountryOfResidence>
196
+ </Person>
197
+ <AppointmentDate>2004-05-17</AppointmentDate>
198
+ </Director>
199
+ <Director>
200
+ <Person>
201
+ <Forename>David</Forename>
202
+ <Forename>Francis</Forename>
203
+ <Surname>PICKERING</Surname>
204
+ <ServiceAddress>
205
+ <Address>
206
+ <Premise>18</Premise>
207
+ <Street>Queen Anne Square</Street>
208
+ <Thoroughfare>Cathays</Thoroughfare>
209
+ <PostTown>Cardiff</PostTown>
210
+ <Postcode>CF10 3ED</Postcode>
211
+ </Address>
212
+ </ServiceAddress>
213
+ <DOB>1960-12-16</DOB>
214
+ <Nationality>British</Nationality>
215
+ <Occupation>Company Director</Occupation>
216
+ <CountryOfResidence></CountryOfResidence>
217
+ </Person>
218
+ <AppointmentDate>1998-10-21</AppointmentDate>
219
+ </Director>
220
+ <Director>
221
+ <Person>
222
+ <Forename>Joanne</Forename>
223
+ <Forename>Sheila</Forename>
224
+ <Surname>STANFORD</Surname>
225
+ <ServiceAddress>
226
+ <Address>
227
+ <Premise>41</Premise>
228
+ <Street>Heol Croes Faen</Street>
229
+ <PostTown>Porthcawl</PostTown>
230
+ <County>Glamorgan</County>
231
+ <Postcode>CF36 3SW</Postcode>
232
+ </Address>
233
+ </ServiceAddress>
234
+ <DOB>1965-02-15</DOB>
235
+ <Nationality>British</Nationality>
236
+ <Occupation>Group It Director</Occupation>
237
+ <CountryOfResidence></CountryOfResidence>
238
+ </Person>
239
+ <AppointmentDate>2008-12-01</AppointmentDate>
240
+ </Director>
241
+ <Director>
242
+ <Person>
243
+ <Forename>Roy</Forename>
244
+ <Forename>John</Forename>
245
+ <Surname>THOMAS</Surname>
246
+ <ServiceAddress>
247
+ <Address>
248
+ <Premise>68</Premise>
249
+ <Street>Ryder Street</Street>
250
+ <PostTown>Cardiff</PostTown>
251
+ <Postcode>CF11 9BU</Postcode>
252
+ </Address>
253
+ </ServiceAddress>
254
+ <DOB>1962-12-17</DOB>
255
+ <Nationality>British</Nationality>
256
+ <Occupation>Lawyer</Occupation>
257
+ <CountryOfResidence></CountryOfResidence>
258
+ </Person>
259
+ <AppointmentDate>2008-12-01</AppointmentDate>
260
+ </Director>
261
+ <Secretary>
262
+ <Person>
263
+ <Forename>Richard</Forename>
264
+ <Forename>Stephen</Forename>
265
+ <Surname>PHILLIPS</Surname>
266
+ <ServiceAddress>
267
+ <Address>
268
+ <Premise></Premise>
269
+ <Street>BEDWEN Newtown</Street>
270
+ <PostTown>Ammanford</PostTown>
271
+ <County>Carmarthenshire</County>
272
+ <Postcode>SA18 3TE</Postcode>
273
+ </Address>
274
+ </ServiceAddress>
275
+ </Person>
276
+ <AppointmentDate>2009-08-27</AppointmentDate>
277
+ </Secretary>
278
+ </Officers>
279
+ <PSCs>
280
+ </PSCs>
281
+ <StatementOfCapital>
282
+ <Capital>
283
+ <TotalNumberOfIssuedShares>50001</TotalNumberOfIssuedShares>
284
+ <ShareCurrency>GBP</ShareCurrency>
285
+ <TotalAggregateNominalValue>50001</TotalAggregateNominalValue>
286
+ <Shares>
287
+ <ShareClass>Ordinary</ShareClass>
288
+ <NumShares>50000</NumShares>
289
+ <AmountPaidDuePerShare>0.000</AmountPaidDuePerShare>
290
+ <AmountUnpaidPerShare>0.000</AmountUnpaidPerShare>
291
+ <AggregateNominalValue>50000</AggregateNominalValue>
292
+ </Shares>
293
+ <Shares>
294
+ <ShareClass>Special</ShareClass>
295
+ <NumShares>1</NumShares>
296
+ <AmountPaidDuePerShare>0.000</AmountPaidDuePerShare>
297
+ <AmountUnpaidPerShare>0.000</AmountUnpaidPerShare>
298
+ <AggregateNominalValue>1</AggregateNominalValue>
299
+ </Shares>
300
+ </Capital>
301
+ </StatementOfCapital>
302
+ <Shareholdings>
303
+ <ShareClass>Special</ShareClass>
304
+ <NumberHeld>1</NumberHeld>
305
+ <Shareholders>
306
+ <Name>
307
+ <Surname>COUNTY COUNCIL OF THE CITY &amp; COUNTY OFCARDIFF</Surname>
308
+ </Name>
309
+ <Address>
310
+ <Premise></Premise>
311
+ <PostTown></PostTown>
312
+ </Address>
313
+ </Shareholders>
314
+ </Shareholdings>
315
+ <Shareholdings>
316
+ <ShareClass>Ordinary</ShareClass>
317
+ <NumberHeld>50000</NumberHeld>
318
+ <Shareholders>
319
+ <Name>
320
+ <Surname>WELSH RUGBY UNION LTD</Surname>
321
+ </Name>
322
+ <Address>
323
+ <Premise></Premise>
324
+ <PostTown></PostTown>
325
+ </Address>
326
+ </Shareholders>
327
+ </Shareholdings>
328
+ </CompanyData>
329
+ </Body>
330
+ </GovTalkMessage>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope http://xmlgw.companieshouse.gov.uk/v2-1/schema/Egov_ch-v2-0.xsd" xmlns="http://www.govtalk.gov.uk/CM/envelope" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
3
+ <EnvelopeVersion>1.0</EnvelopeVersion>
4
+ <Header>
5
+ <MessageDetails>
6
+ <Class>ConfirmationStatement</Class>
7
+ <Qualifier>response</Qualifier>
8
+ <TransactionID>2</TransactionID>
9
+ <GatewayTest>3</GatewayTest>
10
+ <GatewayTimestamp>2020-10-14T22:52:33-00:00</GatewayTimestamp>
11
+ </MessageDetails>
12
+ <SenderDetails>
13
+ <IDAuthentication>
14
+ <SenderID>b55c5f7d59c2e225ec3dddc17544555d</SenderID>
15
+ <Authentication>
16
+ <Method>CHMD5</Method>
17
+ <Value></Value>
18
+ </Authentication>
19
+ </IDAuthentication>
20
+ <EmailAddress>roman.bihun@globacap.com</EmailAddress>
21
+ </SenderDetails>
22
+ </Header>
23
+ <GovTalkDetails>
24
+ <Keys/>
25
+ </GovTalkDetails>
26
+ <Body>
27
+ </Body>
28
+ </GovTalkMessage>
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope http://xmlgw.companieshouse.gov.uk/v2-1/schema/Egov_ch-v2-0.xsd" xmlns="http://www.govtalk.gov.uk/CM/envelope" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
3
+ <EnvelopeVersion>1.0</EnvelopeVersion>
4
+ <Header>
5
+ <MessageDetails>
6
+ <Class>GetSubmissionStatus</Class>
7
+ <Qualifier>response</Qualifier>
8
+ <TransactionID>1</TransactionID>
9
+ <GatewayTest>1</GatewayTest>
10
+ <GatewayTimestamp>2020-10-14T22:53:30-00:00</GatewayTimestamp>
11
+ </MessageDetails>
12
+ <SenderDetails>
13
+ <IDAuthentication>
14
+ <SenderID>b55c5f7d59c2e225ec3dddc17544555d</SenderID>
15
+ <Authentication>
16
+ <Method>CHMD5</Method>
17
+ <Value></Value>
18
+ </Authentication>
19
+ </IDAuthentication>
20
+ </SenderDetails>
21
+ </Header>
22
+ <GovTalkDetails>
23
+ <Keys/>
24
+ </GovTalkDetails>
25
+ <Body>
26
+ <SubmissionStatus>
27
+ <Status>
28
+ <SubmissionNumber>100086</SubmissionNumber>
29
+ <StatusCode>ACCEPT</StatusCode>
30
+ <CompanyNumber>11111111</CompanyNumber>
31
+ <Rejections>
32
+ </Rejections>
33
+ <Examiner>
34
+ <Telephone>Fred Blogs</Telephone>
35
+ <Comment>Accepted submission</Comment>
36
+ </Examiner>
37
+ </Status>
38
+ </SubmissionStatus>
39
+ </Body>
40
+ </GovTalkMessage>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope http://xmlgw.companieshouse.gov.uk/v2-1/schema/Egov_ch-v2-0.xsd" xmlns="http://www.govtalk.gov.uk/CM/envelope" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
3
+ <EnvelopeVersion>1.0</EnvelopeVersion>
4
+ <Header>
5
+ <MessageDetails>
6
+ <Class>ReturnOfAllotmentShares</Class>
7
+ <Qualifier>response</Qualifier>
8
+ <TransactionID>1</TransactionID>
9
+ <GatewayTest>1</GatewayTest>
10
+ <GatewayTimestamp>2020-10-14T22:32:15-00:00</GatewayTimestamp>
11
+ </MessageDetails>
12
+ <SenderDetails>
13
+ <IDAuthentication>
14
+ <SenderID>b55c5f7d59c2e225ec3dddc17544555d</SenderID>
15
+ <Authentication>
16
+ <Method>CHMD5</Method>
17
+ <Value></Value>
18
+ </Authentication>
19
+ </IDAuthentication>
20
+ <EmailAddress>roman.bihun@globacap.com</EmailAddress>
21
+ </SenderDetails>
22
+ </Header>
23
+ <GovTalkDetails>
24
+ <Keys/>
25
+ </GovTalkDetails>
26
+ <Body>
27
+ </Body>
28
+ </GovTalkMessage>
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe CompaniesHouseInputGateway::FormValidator do
6
+ let(:request_data) { REQUEST_DATA[request_type][:request_data] }
7
+ let(:request_class) { CompaniesHouseInputGateway::Util.camelize(request_type) }
8
+ let(:validation) { described_class.validate(request_data, request_class) }
9
+
10
+ context 'success' do
11
+ describe 'get_submission_status' do
12
+ let(:request_type) { :get_submission_status }
13
+
14
+ it 'makes a get_submission_status validation' do
15
+ expect(validation.success?).to be_truthy
16
+ end
17
+ end
18
+
19
+ describe 'company_data_request' do
20
+ let(:request_type) { :company_data_request }
21
+
22
+ it 'makes a company_data_request validation' do
23
+ expect(validation.success?).to be_truthy
24
+ end
25
+ end
26
+
27
+ describe 'returnof_allotment_shares' do
28
+ let(:request_type) { :returnof_allotment_shares }
29
+ it 'makes a returnof_allotment_shares validation' do
30
+ expect(validation.success?).to be_truthy
31
+ end
32
+
33
+ context 'without end_period_shares_allotted' do
34
+ let(:request_data) { super().reject { |k, _v| %i[end_period_shares_allotted].include? k } }
35
+
36
+ it { expect(validation.success?).to be_truthy }
37
+ end
38
+ end
39
+
40
+ describe 'confirmation_statement' do
41
+ let(:request_type) { :confirmation_statement }
42
+ it 'makes a confirmation_statement validation' do
43
+ expect(validation.success?).to be_truthy
44
+ end
45
+ end
46
+
47
+ describe 'form_submission' do
48
+ let(:request_type) { :form_submission }
49
+ let(:request_class) { CompaniesHouseInputGateway::Util.camelize(request_type) }
50
+ let(:validation) do
51
+ described_class.validate(
52
+ REQUEST_DATA[:returnof_allotment_shares][:submission_data],
53
+ request_class
54
+ )
55
+ end
56
+ it 'makes a confirmation_statement validation' do
57
+ expect(validation.success?).to be_truthy
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe CompaniesHouseInputGateway::Request do
6
+ let(:request) { described_class.new(connection, config) }
7
+ let(:config) { create_configuration }
8
+ let(:connection) do
9
+ CompaniesHouseInputGateway::Client.new(config).send(:connection)
10
+ end
11
+
12
+ let(:response_hash) { { status: status, body: body } }
13
+ let(:status) { 200 }
14
+ # let(:body) { load_fixture("response_get_submission_status.xml") }
15
+ let(:body) { load_fixture("response_#{request_type}.xml") }
16
+
17
+ before do
18
+ stub_request(:post, config[:api_endpoint]).to_return(response_hash)
19
+ end
20
+
21
+ let(:request_data) { REQUEST_DATA[request_type] }
22
+
23
+ describe '#perform' do
24
+ describe 'get_submission_status' do
25
+ let(:request_type) { :get_submission_status }
26
+ subject(:perform_check) { request.perform(request_type, request_data, false) }
27
+
28
+ it 'makes submission request' do
29
+ perform_check
30
+ expect(a_request(:post, config[:api_endpoint])).to have_been_made
31
+ end
32
+ end
33
+
34
+ describe 'company_data_request' do
35
+ let(:request_type) { :company_data_request }
36
+ subject(:perform_check) { request.perform(request_type, request_data, false) }
37
+
38
+ it 'makes submission request' do
39
+ perform_check
40
+ expect(a_request(:post, config[:api_endpoint])).to have_been_made
41
+ end
42
+ end
43
+
44
+ describe 'returnof_allotment_shares' do
45
+ let(:request_type) { :returnof_allotment_shares }
46
+ subject(:perform_check) { request.perform(request_type, request_data, true) }
47
+
48
+ it 'makes submission request' do
49
+ perform_check
50
+ expect(a_request(:post, config[:api_endpoint])).to have_been_made
51
+ end
52
+ end
53
+
54
+ describe 'confirmation_statement' do
55
+ let(:request_type) { :confirmation_statement }
56
+ subject(:perform_check) { request.perform(request_type, request_data, true) }
57
+
58
+ it 'makes submission request' do
59
+ perform_check
60
+ expect(a_request(:post, config[:api_endpoint])).to have_been_made
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#perform' do
66
+ let(:request_type) { :get_submission_status }
67
+ subject(:perform_check) { request.perform(request_type, request_data, false) }
68
+
69
+ it 'makes submission request' do
70
+ perform_check
71
+ expect(a_request(:post, config[:api_endpoint])).to have_been_made
72
+ end
73
+
74
+ context 'when the config[:raw] is true' do
75
+ before { config[:raw] = true }
76
+ it { is_expected.to be_a Faraday::Response }
77
+
78
+ describe '#body' do
79
+ subject { super().body }
80
+ it { should be_a String }
81
+ end
82
+ end
83
+
84
+ context 'when the config[:raw] is false' do
85
+ it { is_expected.to be_a Hash }
86
+ it { is_expected.to include 'GovTalkMessage' }
87
+
88
+ context 'errors' do
89
+ context '500' do
90
+ let(:status) { 500 }
91
+
92
+ it 'wraps the error' do
93
+ expect { perform_check }
94
+ .to raise_error CompaniesHouseInputGateway::CompaniesHouseGatewayError
95
+ end
96
+ end
97
+
98
+ context '400' do
99
+ let(:status) { 400 }
100
+
101
+ it 'wraps the error' do
102
+ expect { perform_check }
103
+ .to raise_error CompaniesHouseInputGateway::CompaniesHouseGatewayError
104
+ end
105
+ end
106
+
107
+ context '200 with an error from Companies House' do
108
+ let(:body) { load_fixture('bad_response.xml') }
109
+
110
+ it 'wraps the error' do
111
+ expect { perform_check }
112
+ .to raise_error CompaniesHouseInputGateway::APIError do |error|
113
+ expect(error.error_code).to eq('604')
114
+ expect(error.message).to eq('Error text')
115
+ end
116
+ end
117
+ end
118
+
119
+ context '200 with unexpected XML' do
120
+ let(:body) do
121
+ builder = Nokogiri::XML::Builder.new { |xml| xml.TopLevel }
122
+ builder.doc.to_xml
123
+ end
124
+
125
+ it 'wraps the error' do
126
+ expect { perform_check }.to raise_error CompaniesHouseInputGateway::InvalidResponseError
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/companies_house_input_gateway'
4
+ require 'webmock/rspec'
5
+ require 'data_samples'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with(:rspec) { |mocks| mocks.verify_partial_doubles = true }
9
+ config.raise_errors_for_deprecations!
10
+ config.include WebMock::API
11
+ end
12
+
13
+ def configure_companies_house_input_gateway
14
+ CompaniesHouseInputGateway.configure { |config| config[:sender_id] = 'Grey' }
15
+ end
16
+
17
+ def load_fixture(*filename)
18
+ File.open(fixture_path(filename)).read
19
+ end
20
+
21
+ def fixture_path(*filename)
22
+ File.join('spec', 'fixtures', *filename)
23
+ end
24
+
25
+ def create_configuration
26
+ CompaniesHouseInputGateway.configure do |config|
27
+ config[:sender_id] = '49066960777'
28
+ config[:password] = 'Y194XM32RRW'
29
+ config[:gateway] = 1
30
+ config[:email] = 'email@some.com'
31
+ end
32
+ end