gandi_v5 0.3.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +56 -2
  4. data/.travis.yml +6 -1
  5. data/CHANGELOG.md +61 -0
  6. data/LICENSE.md +2 -6
  7. data/README.md +15 -9
  8. data/gandi_v5.gemspec +2 -2
  9. data/lib/gandi_v5.rb +40 -14
  10. data/lib/gandi_v5/data.rb +1 -2
  11. data/lib/gandi_v5/data/converter/integer.rb +26 -0
  12. data/lib/gandi_v5/domain.rb +13 -14
  13. data/lib/gandi_v5/email/forward.rb +2 -8
  14. data/lib/gandi_v5/email/mailbox.rb +57 -11
  15. data/lib/gandi_v5/email/slot.rb +11 -3
  16. data/lib/gandi_v5/live_dns.rb +0 -12
  17. data/lib/gandi_v5/live_dns/domain.rb +313 -29
  18. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
  19. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  20. data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
  21. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
  22. data/lib/gandi_v5/organization.rb +10 -0
  23. data/lib/gandi_v5/organization/customer.rb +90 -0
  24. data/lib/gandi_v5/sharing_space.rb +27 -0
  25. data/lib/gandi_v5/simple_hosting.rb +12 -0
  26. data/lib/gandi_v5/simple_hosting/instance.rb +242 -0
  27. data/lib/gandi_v5/simple_hosting/instance/application.rb +44 -0
  28. data/lib/gandi_v5/simple_hosting/instance/database.rb +19 -0
  29. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  30. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +21 -0
  31. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
  32. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +74 -0
  33. data/lib/gandi_v5/version.rb +1 -1
  34. data/spec/.rubocop.yml +56 -2
  35. data/spec/fixtures/bodies/GandiV5_Domain/fetch.yml +8 -0
  36. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  37. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  38. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  39. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  40. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  41. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  42. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  43. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  44. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  45. data/spec/fixtures/bodies/GandiV5_Organization_Customer/list.yml +8 -0
  46. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  47. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  48. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  49. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  50. data/spec/units/gandi_v5/data/converter/integer_spec.rb +16 -0
  51. data/spec/units/gandi_v5/domain_spec.rb +53 -43
  52. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  53. data/spec/units/gandi_v5/email/mailbox_spec.rb +119 -37
  54. data/spec/units/gandi_v5/email/slot_spec.rb +10 -2
  55. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  56. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  57. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  58. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  59. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  60. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  61. data/spec/units/gandi_v5/organization/customer_spec.rb +81 -0
  62. data/spec/units/gandi_v5/organization_spec.rb +14 -0
  63. data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
  64. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  65. data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
  66. data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
  67. data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
  68. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  69. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
  70. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
  71. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  72. data/spec/units/gandi_v5_spec.rb +139 -30
  73. metadata +50 -31
  74. data/lib/gandi_v5/domain/sharing_space.rb +0 -21
  75. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  76. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  77. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  78. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  79. data/spec/features/domain_spec.rb +0 -45
  80. data/spec/features/livedns_domain_spec.rb +0 -8
  81. data/spec/features/livedns_zone_spec.rb +0 -45
  82. data/spec/features/mailbox_spec.rb +0 -18
  83. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  84. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  85. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  86. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  87. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  88. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  89. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  90. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  91. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  92. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  93. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
  94. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  95. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class SimpleHosting
5
+ class Instance
6
+ class VirtualHost
7
+ # @!attribute [r] allow_zone_alteration
8
+ # @return [Boolean]
9
+ # @!attribute [r] cname
10
+ # @return [String]
11
+ # @!attribute [r] domain
12
+ # @return [String]
13
+ # @!attribute [r] ipv4
14
+ # @return [String]
15
+ # @!attribute [r] ipv6
16
+ # @return [String]
17
+ # @!attribute [r] is_alterable
18
+ # @return [Boolean]
19
+ # @!attribute [r] is_root
20
+ # @return [Boolean]
21
+ # @!attribute [r] key
22
+ # @return [String]
23
+ # @!attribute [r] txt
24
+ # @return [String]
25
+ # @!attribute [r] last_checked_at
26
+ # @return [Time]
27
+ # @!attribute [r] status
28
+ # @return [Symbol] :altered, :livedns_conflict, :livedns_done, :livedns_error, :unknown
29
+ class LinkedDnsZone
30
+ include GandiV5::Data
31
+
32
+ members :allow_alteration, :is_alterable, :last_checked_at,
33
+ :cname, :domain, :is_root, :ipv4, :ipv6, :key, :txt
34
+
35
+ member(
36
+ :status,
37
+ gandi_key: 'last_checked_status',
38
+ converter: GandiV5::Data::Converter::Symbol
39
+ )
40
+
41
+ # Check if the linked zone is currently in an altered state
42
+ # @return [Boolean]
43
+ def altered?
44
+ status == :altered
45
+ end
46
+
47
+ # Check if the linked zone is currently in a conflicted state
48
+ # @return [Boolean]
49
+ def livedns_conflict?
50
+ status == :livedns_conflict
51
+ end
52
+
53
+ # Check if the linked zone has been updated
54
+ # @return [Boolean]
55
+ def livedns_done?
56
+ status == :livedns_done
57
+ end
58
+
59
+ # Check if the linked zone had an error updating
60
+ # @return [Boolean]
61
+ def livedns_error?
62
+ status == :livedns_error
63
+ end
64
+
65
+ # Check if the linked zone is in an unknown state
66
+ # @return [Boolean]
67
+ def unknown?
68
+ status == :unknown
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GandiV5
4
- VERSION = '0.3.0'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -1,4 +1,58 @@
1
+ require:
2
+ - rubocop-performance
3
+ AllCops:
4
+ TargetRubyVersion: 2.6.0
5
+ Layout/EmptyLinesAroundAttributeAccessor:
6
+ Enabled: true
7
+ Layout/LineLength:
8
+ Max: 125
9
+ Layout/SpaceAroundMethodCallOperator:
10
+ Enabled: true
11
+ Lint/DeprecatedOpenSSLConstant:
12
+ Enabled: true
13
+ Lint/MixedRegexpCaptureTypes:
14
+ Enabled: true
15
+ Lint/RaiseException:
16
+ Enabled: true
17
+ Lint/StructNewOverride:
18
+ Enabled: true
1
19
  Metrics/BlockLength:
2
20
  Max: 750
3
- Metrics/LineLength:
4
- Max: 125
21
+ Performance/AncestorsInclude:
22
+ Enabled: true
23
+ Performance/BigDecimalWithNumericArgument:
24
+ Enabled: true
25
+ Performance/RedundantSortBlock:
26
+ Enabled: true
27
+ Performance/RedundantStringChars:
28
+ Enabled: true
29
+ Performance/ReverseFirst:
30
+ Enabled: true
31
+ Performance/SortReverse:
32
+ Enabled: true
33
+ Performance/Squeeze:
34
+ Enabled: true
35
+ Performance/StringInclude:
36
+ Enabled: true
37
+ Style/AccessorGrouping:
38
+ Enabled: true
39
+ Style/BisectedAttrAccessor:
40
+ Enabled: true
41
+ Style/ExponentialNotation:
42
+ Enabled: true
43
+ Style/HashEachMethods:
44
+ Enabled: true
45
+ Style/HashTransformKeys:
46
+ Enabled: true
47
+ Style/HashTransformValues:
48
+ Enabled: true
49
+ Style/RedundantAssignment:
50
+ Enabled: true
51
+ Style/RedundantFetchBlock:
52
+ Enabled: true
53
+ Style/RedundantRegexpCharacterClass:
54
+ Enabled: true
55
+ Style/RedundantRegexpEscape:
56
+ Enabled: true
57
+ Style/SlicingWithRange:
58
+ Enabled: true
@@ -35,3 +35,11 @@ contacts:
35
35
  services:
36
36
  - gandilivedns
37
37
  - dnssec
38
+ sharing_space:
39
+ id: SHARING-UUID
40
+ name: User
41
+ type: user
42
+ reseller: true
43
+ sharing_space:
44
+ id: RESELLER-UUID
45
+ name: Reseller
@@ -1,4 +1,3 @@
1
1
  ---
2
- zonedata: /zones/zone-uuid/recprds
3
2
  fqdn: example.com
4
- zone: /zones/zone-uuid
3
+ automatic_snapshots: true
@@ -0,0 +1,3 @@
1
+ ---
2
+ - id: key-uuid
3
+ key_name: key-name
@@ -0,0 +1,3 @@
1
+ ---
2
+ - a.example.com
3
+ - b.example.com
@@ -0,0 +1,12 @@
1
+ ---
2
+ id: key-uuid
3
+ status: status
4
+ fqdn: example.com
5
+ algorithm: 2
6
+ algorithm_name: Diffie-Hellman
7
+ deleted: false
8
+ ds: ds-record
9
+ flags: 256
10
+ fingerprint: fp
11
+ public_key: pub-key
12
+ tag: tag
@@ -0,0 +1,9 @@
1
+ ---
2
+ - id: key-uuid
3
+ status: status
4
+ fqdn: example.com
5
+ algorithm: 2
6
+ algorithm_name: Diffie-Hellman
7
+ deleted: false
8
+ ds: ds-record
9
+ flags: 256
@@ -1,7 +1,8 @@
1
1
  ---
2
- date_created: '2016-12-16T16:51:26Z'
3
- uuid: snapshot-uuid
4
- zone_uuid: zone-uuid
2
+ created_at: '2016-12-16T16:51:26Z'
3
+ id: snapshot-uuid
4
+ name: snapshot-name
5
+ automatic: true
5
6
  zone_data:
6
7
  - rrset_type: A
7
8
  rrset_ttl: 10800
@@ -0,0 +1,5 @@
1
+ ---
2
+ - id: snapshot-uuid
3
+ name: snapshot-name
4
+ automatic: true
5
+ created_at: '2016-12-16T16:51:26Z'
@@ -0,0 +1,9 @@
1
+ ---
2
+ id: key-uuid
3
+ key_name: key-name
4
+ secret: key-secret
5
+ config_samples:
6
+ bind: bind-sample
7
+ knot: knot-sample
8
+ nsd: nsd-sample
9
+ powerdns: powerdns-sample
@@ -0,0 +1,4 @@
1
+ ---
2
+ - id: key-uuid
3
+ key_name: key-name
4
+ secret: key-secret
@@ -0,0 +1,8 @@
1
+ ---
2
+ - id: customer-uuid
3
+ name: FirstLast
4
+ firstname: First
5
+ lastname: Last
6
+ email: first.last@example.com
7
+ type: individual
8
+ orgname: Org
@@ -0,0 +1,80 @@
1
+ ---
2
+ access_information:
3
+ admin_url: admin.example.com/
4
+ database:
5
+ admins:
6
+ - type: phpMyAdmin
7
+ url: admin.example.com/phpmyadmin
8
+ username: database admin username
9
+ host: database.example.com
10
+ port: 1234
11
+ socket: /socket/for/database
12
+ deploy:
13
+ - cli:
14
+ init: cli init string
15
+ git:
16
+ deploy: git deploy string
17
+ remote: git remote string
18
+ url: git url string
19
+ sftp:
20
+ directory: sftp directory
21
+ document_root: sftp document root
22
+ server: sftp server
23
+ url: sftp url
24
+ vhost:
25
+ fqdn: example.com
26
+ href: link/to/href/details/virtualhost-uuid
27
+ user: A user
28
+ available_upgrade: false
29
+ console:
30
+ enabled: true
31
+ url: console.example.com/
32
+ created_at: 2020-01-02T12:34:56+00
33
+ database:
34
+ name: database name
35
+ status: database status
36
+ version: database version
37
+ datacenter:
38
+ code: FR-SD5
39
+ name: SD5
40
+ region: FR
41
+ expire_at: 2021-01-02T12:34:56+00
42
+ id: instance-uuid
43
+ is_trial: false
44
+ language:
45
+ name: ruby
46
+ single_application: true
47
+ status: great
48
+ version: "2.7"
49
+ name: instance name
50
+ sharing_space:
51
+ id: sharing-space-uuid
52
+ name: sharing space name
53
+ size: s+
54
+ snapshot_enabled: true
55
+ status: active
56
+ storage:
57
+ additional:
58
+ unit: GB
59
+ value: 10
60
+ base:
61
+ unit: GB
62
+ value: 20
63
+ total:
64
+ unit: GB
65
+ value: 30
66
+ vhosts:
67
+ - fqdn: vhost1.example.com
68
+ href: link/to.vhost/details
69
+ autorenew:
70
+ duration: 1
71
+ duration_type: m
72
+ compatible_applications:
73
+ - name: compatable name
74
+ parameters: {}
75
+ password_updated_at: 2020-06-02T12:34:56+00
76
+ upgrade_to:
77
+ - name: upgrade to name
78
+ status: upgrade to status
79
+ type: database
80
+ version: upgrade to version
@@ -0,0 +1,38 @@
1
+ ---
2
+ - available_upgrade: true
3
+ created_at: 2020-01-02T12:34:56+00
4
+ database:
5
+ name: database name
6
+ status: database status
7
+ version: database version
8
+ datacenter:
9
+ code: FR-SD5
10
+ name: SD5
11
+ region: FR
12
+ expire_at: 2021-01-02T12:34:56+00
13
+ id: instance-uuid
14
+ language:
15
+ name: ruby
16
+ single_application: true
17
+ status: great
18
+ version: "2.7"
19
+ name: instance name
20
+ sharing_space:
21
+ id: sharing-space-uuid
22
+ name: sharing space name
23
+ size: s+
24
+ snapshot_enabled: true
25
+ status: active
26
+ storage:
27
+ additional:
28
+ unit: GB
29
+ value: 10
30
+ base:
31
+ unit: GB
32
+ value: 20
33
+ total:
34
+ unit: GB
35
+ value: 30
36
+ autorenew:
37
+ duration: 1
38
+ duration_type: m
@@ -0,0 +1,26 @@
1
+ ---
2
+ created_at: 2020-01-02T12:34:56+00
3
+ fqdn: vh.example.com
4
+ is_a_test_vhost: false
5
+ linked_dns_zone:
6
+ allow_alteration: true
7
+ cname: cn
8
+ domain: example.com
9
+ ipv4: 1.2.3.4
10
+ ipv6: 1:2::3:4
11
+ is_alterable: true
12
+ is_root: true
13
+ key: www
14
+ txt: abcd1234
15
+ last_checked_status: unknown
16
+ last_checked_at: 2020-02-03T23:45:56+00
17
+ status: running
18
+ application:
19
+ name: app-name
20
+ status: being_created
21
+ parameters: {}
22
+ certificates:
23
+ - href: example.com
24
+ id: cert-id
25
+ pending: true
26
+ https_strategy: redirect_HTTP_to_HTTPS
@@ -0,0 +1,18 @@
1
+ ---
2
+ - created_at: 2020-01-02T12:34:56+00
3
+ fqdn: vh.example.com
4
+ is_a_test_vhost: false
5
+ linked_dns_zone:
6
+ allow_alteration: true
7
+ last_checked_status: unknown
8
+ last_checked_at: 2020-02-03T23:45:56+00
9
+ status: running
10
+ application:
11
+ name: app-name
12
+ status: being_created
13
+ parameters: {}
14
+ certificates:
15
+ - href: example.com
16
+ id: cert-id
17
+ pending: true
18
+ https_strategy: redirect_HTTP_to_HTTPS
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::Data::Converter::Integer do
4
+ it '.from_gandi' do
5
+ expect(described_class.from_gandi('123')).to eq 123
6
+ end
7
+
8
+ it '.to_gandi' do
9
+ expect(described_class.to_gandi(123)).to eq '123'
10
+ end
11
+
12
+ it 'nil value' do
13
+ expect(described_class.from_gandi(nil)).to be nil
14
+ expect(described_class.to_gandi(nil)).to be nil
15
+ end
16
+ end
@@ -5,14 +5,14 @@ describe GandiV5::Domain do
5
5
 
6
6
  describe '.list' do
7
7
  let(:body_fixture) { File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain', 'list.yml')) }
8
+ let(:url) { 'https://api.gandi.net/v5/domain/domains' }
8
9
 
9
10
  describe 'With default values' do
10
11
  subject { described_class.list }
11
12
 
12
13
  before :each do
13
- headers = { params: { page: 1, per_page: 100 } }
14
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers)
15
- .and_return([nil, YAML.load_file(body_fixture)])
14
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
15
+ .and_yield(YAML.load_file(body_fixture))
16
16
  end
17
17
 
18
18
  its('count') { should eq 1 }
@@ -44,42 +44,11 @@ describe GandiV5::Domain do
44
44
  its('first.contacts?') { should be false }
45
45
  end
46
46
 
47
- it 'Keeps fetching until no more to get' do
48
- headers1 = { params: { page: 1, per_page: 1 } }
49
- headers2 = { params: { page: 2, per_page: 1 } }
50
- # https://github.com/rubocop-hq/rubocop/issues/7088
51
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers1)
52
- .ordered
53
- .and_return([nil, YAML.load_file(body_fixture)])
54
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers2)
55
- .ordered
56
- .and_return([nil, []])
57
-
58
- expect(described_class.list(per_page: 1).count).to eq 1
59
- end
60
-
61
- it 'Given a range as page number' do
62
- headers1 = { params: { page: 1, per_page: 1 } }
63
- headers2 = { params: { page: 2, per_page: 1 } }
64
- # https://github.com/rubocop-hq/rubocop/issues/7088
65
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers1)
66
- .ordered
67
- .and_return([nil, YAML.load_file(body_fixture)])
68
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers2)
69
- .ordered
70
- .and_return([nil, []])
71
-
72
- expect(described_class.list(page: (1..2), per_page: 1).count).to eq 1
73
- end
74
-
75
47
  describe 'Passes optional query params' do
76
- %i[fqdn page per_page sort_by tld].each do |param|
48
+ %i[fqdn sort_by tld resellee_id].each do |param|
77
49
  it param.to_s do
78
- param = { param => 5 }
79
- headers = { params: { page: 1, per_page: 100 }.merge(param) }
80
- expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/domains', headers)
81
- .and_return([nil, []])
82
- expect(described_class.list(**param)).to eq []
50
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { param => 5 })
51
+ expect(described_class.list(param => 5)).to eq []
83
52
  end
84
53
  end
85
54
  end
@@ -108,7 +77,12 @@ describe GandiV5::Domain do
108
77
  its('domain_owner') { should be_nil }
109
78
  its('name_servers') { should match_array %w[192.168.0.1 192.168.0.2] }
110
79
  its('services') { should match_array %i[gandilivedns dnssec] }
111
- its('sharing_space') { should be_nil }
80
+ its('sharing_space.uuid') { should eq 'SHARING-UUID' }
81
+ its('sharing_space.name') { should eq 'User' }
82
+ its('sharing_space.type') { should eq 'user' }
83
+ its('sharing_space.reseller') { should be true }
84
+ its('sharing_space.reseller_details.uuid') { should eq 'RESELLER-UUID' }
85
+ its('sharing_space.reseller_details.name') { should eq 'Reseller' }
112
86
  its('dates.created_at') { should eq Time.new(2011, 2, 21, 10, 39, 0) }
113
87
  its('dates.registry_created_at') { should eq Time.new(2003, 3, 12, 12, 2, 11) }
114
88
  its('dates.registry_ends_at') { should eq Time.new(2020, 3, 12, 12, 2, 11) }
@@ -268,7 +242,7 @@ describe GandiV5::Domain do
268
242
  its('domain_owner') { should be_nil }
269
243
  its('name_servers') { should match_array %w[192.168.0.1 192.168.0.2] }
270
244
  its('services') { should match_array %i[gandilivedns dnssec] }
271
- its('sharing_space') { should be_nil }
245
+ its('sharing_space') { should_not be_nil }
272
246
  its('dates.created_at') { should eq Time.new(2011, 2, 21, 10, 39, 0) }
273
247
  its('dates.registry_created_at') { should eq Time.new(2003, 3, 12, 12, 2, 11) }
274
248
  its('dates.registry_ends_at') { should eq Time.new(2020, 3, 12, 12, 2, 11) }
@@ -373,10 +347,46 @@ describe GandiV5::Domain do
373
347
  its('durations') { should match_array [1, 2] }
374
348
  end
375
349
 
376
- it '#renew_for' do
377
- expect(GandiV5).to receive(:post).with('https://api.gandi.net/v5/domain/domains/example.com/renew', '{"duration":2}')
378
- .and_return([nil, { 'message' => 'Confirmation message.' }])
379
- expect(subject.renew_for(2)).to eq 'Confirmation message.'
350
+ describe '#renew_for' do
351
+ it 'Defaults to 1 year and current user' do
352
+ expect(GandiV5).to receive(:post).with(
353
+ 'https://api.gandi.net/v5/domain/domains/example.com/renew',
354
+ '{"duration":1}',
355
+ 'Dry-Run': 0
356
+ )
357
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
358
+ expect(subject.renew_for).to eq 'Confirmation message.'
359
+ end
360
+
361
+ it 'With provided duration' do
362
+ expect(GandiV5).to receive(:post).with(
363
+ 'https://api.gandi.net/v5/domain/domains/example.com/renew',
364
+ '{"duration":2}',
365
+ 'Dry-Run': 0
366
+ )
367
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
368
+ expect(subject.renew_for(2)).to eq 'Confirmation message.'
369
+ end
370
+
371
+ it 'With provided sharing_id' do
372
+ expect(GandiV5).to receive(:post).with(
373
+ 'https://api.gandi.net/v5/domain/domains/example.com/renew?sharing_id=def',
374
+ '{"duration":1}',
375
+ 'Dry-Run': 0
376
+ )
377
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
378
+ expect(subject.renew_for(sharing_id: 'def')).to eq 'Confirmation message.'
379
+ end
380
+
381
+ it 'Does a dry run' do
382
+ expect(GandiV5).to receive(:post).with(
383
+ 'https://api.gandi.net/v5/domain/domains/example.com/renew',
384
+ '{"duration":1}',
385
+ 'Dry-Run': 1
386
+ )
387
+ .and_return([nil, { 'status' => 'success' }])
388
+ expect(subject.renew_for(dry_run: true)).to eq('status' => 'success')
389
+ end
380
390
  end
381
391
 
382
392
  describe '#renewal_price' do