@@ -3,11 +3,13 @@ import { InitParams } from '../src/@types/InitParams';
33import {
44 InfoDNSRecordsResponse ,
55 InfoDNSZoneResponse ,
6+ UpdateDNSRecordsResponse ,
67} from '../src/@types/Responses' ;
78import { INVALID_FORMAT_ERROR , NOT_INITIALIZED_ERROR } from '../src/constants' ;
89import {
910 createEmptyInfoDnsRecordsResponse ,
1011 createEmptyInfoDnsZoneResponse ,
12+ createEmptyUpdateDnsRecordsResponse ,
1113 givenSessionId ,
1214 mockLoginResponse ,
1315} from './testUtils' ;
@@ -116,4 +118,50 @@ describe('exported functions', () => {
116118 ) . rejects . toThrow ( NOT_INITIALIZED_ERROR ) ;
117119 } ) ;
118120 } ) ;
121+
122+ describe ( 'updateDnsRecords tests' , ( ) => {
123+ it ( 'should correctly update dns records' , async ( ) => {
124+ const netcupApi = new NetcupApi ( ) ;
125+ mockLoginResponse ( netcupApi . restApi ) ;
126+ await netcupApi . init ( givenAuthData ) ;
127+ const givenDnsRecordsUpdate : UpdateDNSRecordsResponse = {
128+ ...createEmptyUpdateDnsRecordsResponse ( ) ,
129+ responsedata : {
130+ dnsrecords : [
131+ {
132+ id : '' ,
133+ deleterecord : false ,
134+ hostname : 'test' ,
135+ priority : '' ,
136+ state : 'yes' ,
137+ type : 'A' ,
138+ destination : '@' ,
139+ } ,
140+ ] ,
141+ } ,
142+ } ;
143+
144+ jest
145+ . spyOn ( netcupApi . restApi , 'updateDnsRecords' )
146+ . mockReturnValue ( Promise . resolve ( givenDnsRecordsUpdate ) ) ;
147+ const updateDnsRecordsResult = await netcupApi . updateDnsRecords ( {
148+ dnsrecordset : {
149+ dnsrecords : [ ] ,
150+ } ,
151+ domainname : 'test.domain.com' ,
152+ } ) ;
153+ expect ( updateDnsRecordsResult ) . toEqual ( givenDnsRecordsUpdate ) ;
154+ } ) ;
155+
156+ it ( 'should throw error on update dns records without auth' , async ( ) => {
157+ await expect ( ( ) =>
158+ new NetcupApi ( ) . updateDnsRecords ( {
159+ dnsrecordset : {
160+ dnsrecords : [ ] ,
161+ } ,
162+ domainname : '' ,
163+ } ) ,
164+ ) . rejects . toThrow ( NOT_INITIALIZED_ERROR ) ;
165+ } ) ;
166+ } ) ;
119167} ) ;
0 commit comments