@@ -75,4 +75,162 @@ Describe 'Domeneshop context and auth flow' {
7575 $Credential.UserName -eq ' token'
7676 }
7777 }
78+
79+ It ' Get-DomeneshopDomain can get a domain by ID' {
80+ Mock Resolve-DomeneshopContext {
81+ [pscustomobject ]@ {
82+ ID = ' demo'
83+ Token = ' token'
84+ Secret = ConvertTo-SecureString - AsPlainText ' secret' - Force
85+ ApiBaseUri = ' https://api.domeneshop.no/v0'
86+ }
87+ }
88+ Mock Invoke-DomeneshopApiRequest { @ {} }
89+
90+ { Get-DomeneshopDomain - Context ' demo' - DomainID 42 } | Should -Not - Throw
91+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
92+ $Method -eq ' Get' -and
93+ $Uri -eq ' https://api.domeneshop.no/v0/domains/42'
94+ }
95+ }
96+
97+ It ' Get-DomeneshopDnsRecord builds list query and endpoint' {
98+ Mock Resolve-DomeneshopContext {
99+ [pscustomobject ]@ {
100+ ID = ' demo'
101+ Token = ' token'
102+ Secret = ConvertTo-SecureString - AsPlainText ' secret' - Force
103+ ApiBaseUri = ' https://api.domeneshop.no/v0'
104+ }
105+ }
106+ Mock Invoke-DomeneshopApiRequest { @ () }
107+
108+ Get-DomeneshopDnsRecord - DomainID 9 - Host ' www' - Type ' A' - Data ' 127.0.0.1'
109+
110+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
111+ $Method -eq ' Get' -and
112+ $Uri -eq ' https://api.domeneshop.no/v0/domains/9/dns?host=www&type=A&data=127.0.0.1'
113+ }
114+ }
115+
116+ It ' Get-DomeneshopDnsRecord can get record by ID' {
117+ Mock Resolve-DomeneshopContext {
118+ [pscustomobject ]@ {
119+ ID = ' demo'
120+ Token = ' token'
121+ Secret = ConvertTo-SecureString - AsPlainText ' secret' - Force
122+ ApiBaseUri = ' https://api.domeneshop.no/v0'
123+ }
124+ }
125+ Mock Invoke-DomeneshopApiRequest { @ {} }
126+
127+ Get-DomeneshopDnsRecord - DomainID 9 - RecordID 3
128+
129+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
130+ $Method -eq ' Get' -and
131+ $Uri -eq ' https://api.domeneshop.no/v0/domains/9/dns/3'
132+ }
133+ }
134+
135+ It ' DNS mutating commands call expected endpoints' {
136+ Mock Resolve-DomeneshopContext {
137+ [pscustomobject ]@ {
138+ ID = ' demo'
139+ Token = ' token'
140+ Secret = ConvertTo-SecureString - AsPlainText ' secret' - Force
141+ ApiBaseUri = ' https://api.domeneshop.no/v0'
142+ }
143+ }
144+ Mock Invoke-DomeneshopApiRequest { @ {} }
145+
146+ $record = @ { host = ' www' ; type = ' A' ; data = ' 127.0.0.1' }
147+ Add-DomeneshopDnsRecord - DomainID 9 - Record $record
148+ Set-DomeneshopDnsRecord - DomainID 9 - RecordID 3 - Record $record
149+ Remove-DomeneshopDnsRecord - DomainID 9 - RecordID 3 - Confirm:$false
150+
151+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
152+ $Method -eq ' Post' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/dns'
153+ }
154+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
155+ $Method -eq ' Put' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/dns/3'
156+ }
157+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
158+ $Method -eq ' Delete' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/dns/3'
159+ }
160+ }
161+
162+ It ' Forward commands call expected endpoints' {
163+ Mock Resolve-DomeneshopContext {
164+ [pscustomobject ]@ {
165+ ID = ' demo'
166+ Token = ' token'
167+ Secret = ConvertTo-SecureString - AsPlainText ' secret' - Force
168+ ApiBaseUri = ' https://api.domeneshop.no/v0'
169+ }
170+ }
171+ Mock Invoke-DomeneshopApiRequest { @ {} }
172+
173+ $forward = @ { host = ' www' ; url = ' https://example.net' }
174+ Get-DomeneshopForward - DomainID 9
175+ Get-DomeneshopForward - DomainID 9 - Host ' www'
176+ Add-DomeneshopForward - DomainID 9 - Forward $forward
177+ Set-DomeneshopForward - DomainID 9 - Host ' www' - Forward $forward
178+ Remove-DomeneshopForward - DomainID 9 - Host ' www' - Confirm:$false
179+
180+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
181+ $Method -eq ' Get' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/forwards/'
182+ }
183+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
184+ $Method -eq ' Get' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/forwards/www'
185+ }
186+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
187+ $Method -eq ' Post' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/forwards/'
188+ }
189+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
190+ $Method -eq ' Put' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/forwards/www'
191+ }
192+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
193+ $Method -eq ' Delete' -and $Uri -eq ' https://api.domeneshop.no/v0/domains/9/forwards/www'
194+ }
195+ }
196+
197+ It ' Get-DomeneshopInvoice supports list and by ID' {
198+ Mock Resolve-DomeneshopContext {
199+ [pscustomobject ]@ {
200+ ID = ' demo'
201+ Token = ' token'
202+ Secret = ConvertTo-SecureString - AsPlainText ' secret' - Force
203+ ApiBaseUri = ' https://api.domeneshop.no/v0'
204+ }
205+ }
206+ Mock Invoke-DomeneshopApiRequest { @ () }
207+
208+ Get-DomeneshopInvoice
209+ Get-DomeneshopInvoice - InvoiceID 7
210+
211+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
212+ $Method -eq ' Get' -and $Uri -eq ' https://api.domeneshop.no/v0/invoices'
213+ }
214+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
215+ $Method -eq ' Get' -and $Uri -eq ' https://api.domeneshop.no/v0/invoices/7'
216+ }
217+ }
218+
219+ It ' Update-DomeneshopDdns builds hostname and myip query' {
220+ Mock Resolve-DomeneshopContext {
221+ [pscustomobject ]@ {
222+ ID = ' demo'
223+ Token = ' token'
224+ Secret = ConvertTo-SecureString - AsPlainText ' secret' - Force
225+ ApiBaseUri = ' https://api.domeneshop.no/v0'
226+ }
227+ }
228+ Mock Invoke-DomeneshopApiRequest { @ {} }
229+
230+ Update-DomeneshopDdns - Hostname ' home.example.com' - MyIP ' 1.2.3.4'
231+
232+ Should - Invoke Invoke-DomeneshopApiRequest - Times 1 - Exactly - ParameterFilter {
233+ $Method -eq ' Get' -and $Uri -eq ' https://api.domeneshop.no/v0/dyndns/update?hostname=home.example.com&myip=1.2.3.4'
234+ }
235+ }
78236}
0 commit comments