gandi_v5 0.5.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +69 -5
  3. data/LICENSE.md +2 -6
  4. data/README.md +67 -18
  5. data/lib/gandi_v5.rb +137 -70
  6. data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
  7. data/lib/gandi_v5/data.rb +3 -2
  8. data/lib/gandi_v5/data/converter.rb +3 -2
  9. data/lib/gandi_v5/data/converter/array_of.rb +3 -2
  10. data/lib/gandi_v5/data/converter/integer.rb +3 -2
  11. data/lib/gandi_v5/data/converter/symbol.rb +3 -2
  12. data/lib/gandi_v5/data/converter/time.rb +3 -2
  13. data/lib/gandi_v5/domain.rb +16 -17
  14. data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
  15. data/lib/gandi_v5/domain/contact.rb +5 -5
  16. data/lib/gandi_v5/domain/tld.rb +2 -2
  17. data/lib/gandi_v5/domain/transfer_in.rb +170 -0
  18. data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
  19. data/lib/gandi_v5/email.rb +1 -0
  20. data/lib/gandi_v5/email/forward.rb +2 -8
  21. data/lib/gandi_v5/email/mailbox.rb +4 -10
  22. data/lib/gandi_v5/email/slot.rb +11 -3
  23. data/lib/gandi_v5/error/gandi_error.rb +1 -0
  24. data/lib/gandi_v5/live_dns.rb +2 -12
  25. data/lib/gandi_v5/live_dns/domain.rb +340 -29
  26. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +120 -0
  27. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  28. data/lib/gandi_v5/live_dns/domain/snapshot.rb +111 -0
  29. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +74 -0
  30. data/lib/gandi_v5/sharing_space.rb +27 -0
  31. data/lib/gandi_v5/simple_hosting.rb +13 -0
  32. data/lib/gandi_v5/simple_hosting/instance.rb +245 -0
  33. data/lib/gandi_v5/simple_hosting/instance/application.rb +45 -0
  34. data/lib/gandi_v5/simple_hosting/instance/database.rb +20 -0
  35. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  36. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +22 -0
  37. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
  38. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +75 -0
  39. data/lib/gandi_v5/version.rb +1 -1
  40. data/spec/.rubocop.yml +9 -9
  41. data/spec/features/list_domain_renewals_spec.rb +16 -0
  42. data/spec/features/list_email_addresses_spec.rb +39 -0
  43. data/spec/fixtures/bodies/GandiV5_Domain/fetch.yml +8 -0
  44. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
  45. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
  46. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  47. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  48. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  49. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  50. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  51. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  52. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  53. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  54. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  55. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  56. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  57. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  58. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  59. data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
  60. data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
  61. data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
  62. data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
  63. data/spec/units/gandi_v5/domain_spec.rb +13 -39
  64. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  65. data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
  66. data/spec/units/gandi_v5/email/slot_spec.rb +10 -2
  67. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  68. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  69. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  70. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  71. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  72. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  73. data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
  74. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  75. data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
  76. data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
  77. data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
  78. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  79. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
  80. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
  81. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  82. data/spec/units/gandi_v5_spec.rb +111 -14
  83. metadata +174 -53
  84. data/.gitignore +0 -26
  85. data/.rspec +0 -3
  86. data/.rubocop.yml +0 -30
  87. data/.travis.yml +0 -38
  88. data/FUNDING.yml +0 -10
  89. data/Gemfile +0 -6
  90. data/Guardfile +0 -39
  91. data/Rakefile +0 -3
  92. data/bin/console +0 -13
  93. data/gandi_v5.gemspec +0 -42
  94. data/lib/gandi_v5/domain/sharing_space.rb +0 -21
  95. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  96. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  97. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  98. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  99. data/spec/features/domain_spec.rb +0 -45
  100. data/spec/features/livedns_domain_spec.rb +0 -8
  101. data/spec/features/livedns_zone_spec.rb +0 -44
  102. data/spec/features/mailbox_spec.rb +0 -18
  103. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  104. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  105. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  106. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  107. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  108. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  109. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  110. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  111. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  112. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  113. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
  114. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  115. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -13,18 +13,6 @@ describe GandiV5::LiveDNS do
13
13
  expect(described_class.domains).to be returns
14
14
  end
15
15
 
16
- it '.zone' do
17
- returns = double GandiV5::LiveDNS::Zone
18
- expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid').and_return(returns)
19
- expect(described_class.zone('zone-uuid')).to be returns
20
- end
21
-
22
- it '.zones' do
23
- returns = double Array
24
- expect(GandiV5::LiveDNS::Zone).to receive(:list).and_return(returns)
25
- expect(described_class.zones).to be returns
26
- end
27
-
28
16
  describe '.require_valid_record_type' do
29
17
  it 'Does nothing for valid type' do
30
18
  expect { described_class.require_valid_record_type 'A' }.to_not raise_error
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SharingSpace do
4
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::Application do
4
+ describe 'Helper methods' do
5
+ context 'being_created' do
6
+ subject { described_class.new status: :being_created }
7
+ its('being_created?') { should be true }
8
+ its('cancelled?') { should be false }
9
+ its('running?') { should be false }
10
+ its('error?') { should be false }
11
+ end
12
+
13
+ context 'cancelled' do
14
+ subject { described_class.new status: :cancelled }
15
+ its('being_created?') { should be false }
16
+ its('cancelled?') { should be true }
17
+ its('running?') { should be false }
18
+ its('error?') { should be false }
19
+ end
20
+
21
+ context 'running' do
22
+ subject { described_class.new status: :running }
23
+ its('being_created?') { should be false }
24
+ its('cancelled?') { should be false }
25
+ its('running?') { should be true }
26
+ its('error?') { should be false }
27
+ end
28
+
29
+ context 'error' do
30
+ subject { described_class.new status: :error }
31
+ its('being_created?') { should be false }
32
+ its('cancelled?') { should be false }
33
+ its('running?') { should be false }
34
+ its('error?') { should be true }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::Database do
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::Language do
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::Upgrade do
4
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone do
4
+ describe 'Helper methods' do
5
+ context 'altered' do
6
+ subject { described_class.new status: :altered }
7
+ its('altered?') { should be true }
8
+ its('livedns_conflict?') { should be false }
9
+ its('livedns_done?') { should be false }
10
+ its('livedns_error?') { should be false }
11
+ its('unknown?') { should be false }
12
+ end
13
+
14
+ context 'altered' do
15
+ subject { described_class.new status: :livedns_conflict }
16
+ its('altered?') { should be false }
17
+ its('livedns_conflict?') { should be true }
18
+ its('livedns_done?') { should be false }
19
+ its('livedns_error?') { should be false }
20
+ its('unknown?') { should be false }
21
+ end
22
+
23
+ context 'livedns_done' do
24
+ subject { described_class.new status: :livedns_done }
25
+ its('altered?') { should be false }
26
+ its('livedns_conflict?') { should be false }
27
+ its('livedns_done?') { should be true }
28
+ its('livedns_error?') { should be false }
29
+ its('unknown?') { should be false }
30
+ end
31
+
32
+ context 'livedns_error' do
33
+ subject { described_class.new status: :livedns_error }
34
+ its('altered?') { should be false }
35
+ its('livedns_conflict?') { should be false }
36
+ its('livedns_done?') { should be false }
37
+ its('livedns_error?') { should be true }
38
+ its('unknown?') { should be false }
39
+ end
40
+
41
+ context 'unknown' do
42
+ subject { described_class.new status: :unknown }
43
+ its('altered?') { should be false }
44
+ its('livedns_conflict?') { should be false }
45
+ its('livedns_done?') { should be false }
46
+ its('livedns_error?') { should be false }
47
+ its('unknown?') { should be true }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,199 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::VirtualHost do
4
+ let :body_list do
5
+ YAML.load_file(
6
+ File.expand_path(
7
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance_VirtualHost', 'list.yml')
8
+ )
9
+ )
10
+ end
11
+ let :body_fetch do
12
+ YAML.load_file(
13
+ File.expand_path(
14
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance_VirtualHost', 'fetch.yml')
15
+ )
16
+ )
17
+ end
18
+
19
+ subject do
20
+ described_class.new instance_uuid: 'instance-uuid', fqdn: 'vh.example.com'
21
+ end
22
+
23
+ it '#refresh' do
24
+ url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
25
+ expect(GandiV5).to receive(:get).with(url)
26
+ .and_return([nil, body_fetch])
27
+ subject.refresh
28
+ expect(subject.linked_dns_zone.cname).to_not be nil
29
+ end
30
+
31
+ describe 'Helper methods' do
32
+ describe 'Status' do
33
+ context 'being_created' do
34
+ subject { described_class.new status: :being_created }
35
+ its('being_created?') { should be true }
36
+ its('running?') { should be false }
37
+ its('being_deleted?') { should be false }
38
+ its('locked?') { should be false }
39
+ its('waiting_ownership?') { should be false }
40
+ its('ownership_validated?') { should be false }
41
+ its('validation_failed?') { should be false }
42
+ end
43
+ context 'running' do
44
+ subject { described_class.new status: :running }
45
+ its('being_created?') { should be false }
46
+ its('running?') { should be true }
47
+ its('being_deleted?') { should be false }
48
+ its('locked?') { should be false }
49
+ its('waiting_ownership?') { should be false }
50
+ its('ownership_validated?') { should be false }
51
+ its('validation_failed?') { should be false }
52
+ end
53
+ context 'being_deleted' do
54
+ subject { described_class.new status: :being_deleted }
55
+ its('being_created?') { should be false }
56
+ its('running?') { should be false }
57
+ its('being_deleted?') { should be true }
58
+ its('locked?') { should be false }
59
+ its('waiting_ownership?') { should be false }
60
+ its('ownership_validated?') { should be false }
61
+ its('validation_failed?') { should be false }
62
+ end
63
+ context 'locked' do
64
+ subject { described_class.new status: :locked }
65
+ its('being_created?') { should be false }
66
+ its('running?') { should be false }
67
+ its('being_deleted?') { should be false }
68
+ its('locked?') { should be true }
69
+ its('waiting_ownership?') { should be false }
70
+ its('ownership_validated?') { should be false }
71
+ its('validation_failed?') { should be false }
72
+ end
73
+ context 'waiting_ownership' do
74
+ subject { described_class.new status: :waiting_ownership }
75
+ its('being_created?') { should be false }
76
+ its('running?') { should be false }
77
+ its('being_deleted?') { should be false }
78
+ its('locked?') { should be false }
79
+ its('waiting_ownership?') { should be true }
80
+ its('ownership_validated?') { should be false }
81
+ its('validation_failed?') { should be false }
82
+ end
83
+ context 'ownership_validated' do
84
+ subject { described_class.new status: :ownership_validated }
85
+ its('being_created?') { should be false }
86
+ its('running?') { should be false }
87
+ its('being_deleted?') { should be false }
88
+ its('locked?') { should be false }
89
+ its('waiting_ownership?') { should be false }
90
+ its('ownership_validated?') { should be true }
91
+ its('validation_failed?') { should be false }
92
+ end
93
+ context 'validation_failed' do
94
+ subject { described_class.new status: :validation_failed }
95
+ its('being_created?') { should be false }
96
+ its('running?') { should be false }
97
+ its('being_deleted?') { should be false }
98
+ its('locked?') { should be false }
99
+ its('waiting_ownership?') { should be false }
100
+ its('ownership_validated?') { should be false }
101
+ its('validation_failed?') { should be true }
102
+ end
103
+ end
104
+
105
+ describe 'HTTP(S)' do
106
+ context 'HTTP_only' do
107
+ subject { described_class.new https_strategy: :http_only }
108
+ its('http_only?') { should be true }
109
+ its('http_and_https?') { should be false }
110
+ its('redirect_http_to_https?') { should be false }
111
+ its('http?') { should be true }
112
+ its('https?') { should be false }
113
+ end
114
+ context 'HTTP_and_HTTPS' do
115
+ subject { described_class.new https_strategy: :http_and_https }
116
+ its('http_only?') { should be false }
117
+ its('http_and_https?') { should be true }
118
+ its('redirect_http_to_https?') { should be false }
119
+ its('http?') { should be true }
120
+ its('https?') { should be true }
121
+ end
122
+ context 'redirect_HTTP_to_HTTPS' do
123
+ subject { described_class.new https_strategy: :redirect_http_to_https }
124
+ its('http_only?') { should be false }
125
+ its('http_and_https?') { should be false }
126
+ its('redirect_http_to_https?') { should be true }
127
+ its('http?') { should be false }
128
+ its('https?') { should be false }
129
+ end
130
+ end
131
+ end
132
+
133
+ describe '.list' do
134
+ subject { described_class.list('instance-uuid') }
135
+ let(:url) { 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts' }
136
+
137
+ describe 'With default parameters' do
138
+ before :each do
139
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
140
+ .and_yield(body_list)
141
+ end
142
+
143
+ its('count') { should eq 1 }
144
+ its('first.created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56, 0) }
145
+ its('first.fqdn') { should eq 'vh.example.com' }
146
+ its('first.is_a_test_virtual_host') { should be false }
147
+ its('first.linked_dns_zone.allow_alteration') { should be true }
148
+ its('first.linked_dns_zone.status') { should eq :unknown }
149
+ its('first.linked_dns_zone.last_checked_at') { should eq Time.new(2020, 2, 3, 23, 45, 56, 0) }
150
+ its('first.status') { should eq :running }
151
+ its('first.application.name') { should eq 'app-name' }
152
+ its('first.application.status') { should eq :being_created }
153
+ its('first.application.parameters') { should eq({}) }
154
+ its('first.certificates') { should eq({ 'cert-id' => true }) }
155
+ its('first.https_strategy') { should eq :redirect_http_to_https }
156
+ end
157
+
158
+ describe 'Passes optional query params' do
159
+ %i[fqdn status sort_by].each do |param|
160
+ it param do
161
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { param => 'value' })
162
+ .and_return([nil, []])
163
+ described_class.list('instance-uuid', param => 'value')
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ describe '.fetch' do
170
+ subject { described_class.fetch 'instance-uuid', 'vh.example.com' }
171
+
172
+ before :each do
173
+ url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
174
+ expect(GandiV5).to receive(:get).with(url)
175
+ .and_return([nil, body_fetch])
176
+ end
177
+
178
+ its('created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56, 0) }
179
+ its('fqdn') { should eq 'vh.example.com' }
180
+ its('is_a_test_virtual_host') { should be false }
181
+ its('linked_dns_zone.allow_alteration') { should be true }
182
+ its('linked_dns_zone.cname') { should eq 'cn' }
183
+ its('linked_dns_zone.domain') { should eq 'example.com' }
184
+ its('linked_dns_zone.ipv4') { should eq '1.2.3.4' }
185
+ its('linked_dns_zone.ipv6') { should eq '1:2::3:4' }
186
+ its('linked_dns_zone.is_alterable') { should be true }
187
+ its('linked_dns_zone.is_root') { should be true }
188
+ its('linked_dns_zone.key') { should eq 'www' }
189
+ its('linked_dns_zone.txt') { should eq 'abcd1234' }
190
+ its('linked_dns_zone.status') { should eq :unknown }
191
+ its('linked_dns_zone.last_checked_at') { should eq Time.new(2020, 2, 3, 23, 45, 56, 0) }
192
+ its('status') { should eq :running }
193
+ its('application.name') { should eq 'app-name' }
194
+ its('application.status') { should eq :being_created }
195
+ its('application.parameters') { should eq({}) }
196
+ its('certificates') { should eq({ 'cert-id' => true }) }
197
+ its('https_strategy') { should eq :redirect_http_to_https }
198
+ end
199
+ end
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance do
4
+ let :body_list do
5
+ YAML.load_file(
6
+ File.expand_path(
7
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance', 'list.yml')
8
+ )
9
+ )
10
+ end
11
+ let :body_fetch do
12
+ YAML.load_file(
13
+ File.expand_path(
14
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance', 'fetch.yml')
15
+ )
16
+ )
17
+ end
18
+
19
+ subject do
20
+ described_class.new uuid: 'instance-uuid'
21
+ end
22
+
23
+ describe 'Actions' do
24
+ let(:url) { 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/action' }
25
+
26
+ %i[restart console reset_database_password].each do |action|
27
+ it ".#{action}" do
28
+ expect(GandiV5).to receive(:post).with(url, "{\"action\":\"#{action}\"}")
29
+ .and_return([nil, 'Confirmation message'])
30
+ expect(subject.send(action)).to eq 'Confirmation message'
31
+ end
32
+ end
33
+ end
34
+
35
+ it '#refresh' do
36
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/simplehosting/instances/instance-uuid')
37
+ .and_return([nil, body_fetch])
38
+ subject.refresh
39
+ expect(subject.access_information).to_not be nil
40
+ end
41
+
42
+ describe 'Helper methods' do
43
+ describe 'Status' do
44
+ context 'waiting_bill' do
45
+ subject { described_class.new status: :waiting_bill }
46
+ its('waiting_bill?') { should be true }
47
+ its('being_created?') { should be false }
48
+ its('active?') { should be false }
49
+ its('paused?') { should be false }
50
+ its('locked?') { should be false }
51
+ its('being_deleted?') { should be false }
52
+ end
53
+ context 'being_created' do
54
+ subject { described_class.new status: :being_created }
55
+ its('waiting_bill?') { should be false }
56
+ its('being_created?') { should be true }
57
+ its('active?') { should be false }
58
+ its('paused?') { should be false }
59
+ its('locked?') { should be false }
60
+ its('being_deleted?') { should be false }
61
+ end
62
+ context 'active' do
63
+ subject { described_class.new status: :active }
64
+ its('waiting_bill?') { should be false }
65
+ its('being_created?') { should be false }
66
+ its('active?') { should be true }
67
+ its('paused?') { should be false }
68
+ its('locked?') { should be false }
69
+ its('being_deleted?') { should be false }
70
+ end
71
+ context 'paused' do
72
+ subject { described_class.new status: :paused }
73
+ its('waiting_bill?') { should be false }
74
+ its('being_created?') { should be false }
75
+ its('active?') { should be false }
76
+ its('paused?') { should be true }
77
+ its('locked?') { should be false }
78
+ its('being_deleted?') { should be false }
79
+ end
80
+ context 'locked' do
81
+ subject { described_class.new status: :locked }
82
+ its('waiting_bill?') { should be false }
83
+ its('being_created?') { should be false }
84
+ its('active?') { should be false }
85
+ its('paused?') { should be false }
86
+ its('locked?') { should be true }
87
+ its('being_deleted?') { should be false }
88
+ end
89
+ context 'being_deleted' do
90
+ subject { described_class.new status: :being_deleted }
91
+ its('waiting_bill?') { should be false }
92
+ its('being_created?') { should be false }
93
+ its('active?') { should be false }
94
+ its('paused?') { should be false }
95
+ its('locked?') { should be false }
96
+ its('being_deleted?') { should be true }
97
+ end
98
+ end
99
+ end
100
+
101
+ describe '.list' do
102
+ subject { described_class.list }
103
+ let(:url) { 'https://api.gandi.net/v5/simplehosting/instances' }
104
+
105
+ describe 'With default parameters' do
106
+ before :each do
107
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
108
+ .and_yield(body_list)
109
+ end
110
+
111
+ its('count') { should eq 1 }
112
+ its('first.created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56) }
113
+ its('first.database.name') { should eq 'database name' }
114
+ its('first.database.status') { should eq 'database status' }
115
+ its('first.database.version') { should eq 'database version' }
116
+ its('first.data_center') { should eq 'FR-SD5' }
117
+ its('first.expire_at') { should eq Time.new(2021, 1, 2, 12, 34, 56) }
118
+ its('first.uuid') { should eq 'instance-uuid' }
119
+ its('first.language.name') { should eq 'ruby' }
120
+ its('first.language.single_application') { should be true }
121
+ its('first.language.status') { should eq 'great' }
122
+ its('first.language.version') { should eq '2.7' }
123
+ its('first.name') { should eq 'instance name' }
124
+ its('first.sharing_space.uuid') { should eq 'sharing-space-uuid' }
125
+ its('first.sharing_space.name') { should eq 'sharing space name' }
126
+ its('first.size') { should eq 's+' }
127
+ its('first.snapshot_enabled') { should be true }
128
+ its('first.status') { should eq 'active' }
129
+ its('first.storage') { should eq({ base: '20 GB', additional: '10 GB', total: '30 GB' }) }
130
+ its('first.auto_renew') { should eq '1 m' }
131
+ end
132
+
133
+ describe 'Passes optional query params' do
134
+ %i[sharing_id name fqdn size status sort_by].each do |param|
135
+ it param do
136
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { param => 'value' })
137
+ .and_return([nil, []])
138
+ described_class.list(param => 'value')
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ describe '.fetch' do
145
+ subject { described_class.fetch 'instance-uuid' }
146
+
147
+ before :each do
148
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/simplehosting/instances/instance-uuid')
149
+ .and_return([nil, body_fetch])
150
+ end
151
+
152
+ its('access_information') { should be_a Hash }
153
+ its('created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56, 0) }
154
+ its('database.name') { should eq 'database name' }
155
+ its('database.status') { should eq 'database status' }
156
+ its('database.version') { should eq 'database version' }
157
+ its('data_center') { should eq 'FR-SD5' }
158
+ its('expire_at') { should eq Time.new(2021, 1, 2, 12, 34, 56, 0) }
159
+ its('uuid') { should eq 'instance-uuid' }
160
+ its('is_trial') { should be false }
161
+ its('language.name') { should eq 'ruby' }
162
+ its('language.single_application') { should be true }
163
+ its('language.status') { should eq 'great' }
164
+ its('language.version') { should eq '2.7' }
165
+ its('name') { should eq 'instance name' }
166
+ its('sharing_space.uuid') { should eq 'sharing-space-uuid' }
167
+ its('sharing_space.name') { should eq 'sharing space name' }
168
+ its('size') { should eq 's+' }
169
+ its('snapshot_enabled') { should be true }
170
+ its('status') { should eq 'active' }
171
+ its('storage') { should eq({ base: '20 GB', additional: '10 GB', total: '30 GB' }) }
172
+ its('virtual_hosts.first.fqdn') { should eq 'vhost1.example.com' }
173
+ its('auto_renew') { should eq '1 m' }
174
+ its('compatible_applications.first.name') { should eq 'compatable name' }
175
+ its('compatible_applications.first.parameters') { should be_a Hash }
176
+ its('password_updated_at') { should eq Time.new(2020, 6, 2, 12, 34, 56, 0) }
177
+ its('upgrade_to.first.name') { should eq 'upgrade to name' }
178
+ its('upgrade_to.first.status') { should eq 'upgrade to status' }
179
+ its('upgrade_to.first.type') { should eq 'database' }
180
+ its('upgrade_to.first.version') { should eq 'upgrade to version' }
181
+ end
182
+ end