2018-07-27 10:18:29 -04:00
/ *
* Copyright 2018 Comcast Cable Communications Management , LLC
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* /
describe ( 'BatchChange' , function ( ) {
beforeEach ( function ( ) {
2019-11-04 11:00:14 -05:00
module ( 'dns-change' ) ,
2018-07-27 10:18:29 -04:00
module ( 'service.utility' ) ,
2019-02-06 16:21:43 -05:00
module ( 'service.paging' ) ,
2019-02-20 16:25:30 -05:00
module ( 'service.groups' )
2018-07-27 10:18:29 -04:00
} ) ;
var deferred ;
2019-11-04 11:00:14 -05:00
describe ( 'Controller: DnsChangeDetailController' , function ( ) {
2018-07-27 10:18:29 -04:00
beforeEach ( function ( ) {
module ( 'ngMock' )
} ) ;
2019-11-04 11:00:14 -05:00
beforeEach ( inject ( function ( $rootScope , $controller , $q , dnsChangeService , pagingService , utilityService ) {
2018-07-27 10:18:29 -04:00
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
2019-11-04 11:00:14 -05:00
this . controller = $controller ( 'DnsChangeDetailController' , { '$scope' : this . scope } ) ;
2018-07-27 10:18:29 -04:00
deferred = $q . defer ( ) ;
2019-11-04 11:00:14 -05:00
spyOn ( dnsChangeService , 'getBatchChange' ) . and . returnValue ( deferred . promise ) ;
spyOn ( dnsChangeService , 'approveBatchChange' ) . and . returnValue ( deferred . promise ) ;
spyOn ( dnsChangeService , 'rejectBatchChange' ) . and . returnValue ( deferred . promise ) ;
2018-07-27 10:18:29 -04:00
} ) ) ;
describe ( '$scope.getBatchChange' , function ( ) {
2019-11-04 11:00:14 -05:00
it ( 'should resolve the promise' , inject ( function ( dnsChangeService ) {
2018-07-27 10:18:29 -04:00
this . scope . getBatchChange ( "17350028-b2b8-428d-9f10-dbb518a0364d" ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . getBatchChange ) . toHaveBeenCalled ( ) ;
expect ( dnsChangeService . getBatchChange ) . toHaveBeenCalledWith ( "17350028-b2b8-428d-9f10-dbb518a0364d" ) ;
2018-07-27 10:18:29 -04:00
var mockBatchChange = {
userId : "17350028-b2b8-428d-9f10-dbb518a0364d" ,
userName : "bwrigh833" ,
comments : "this is a test comment." ,
createdTimestamp : "2018-05-09T14:20:50Z" ,
changes : [ { zoneId : "937191c4-b1fd-4ab5-abb4-9553a65b44ab" , zoneName : "old-vinyldns2." , recordName : "test1" , inputName : "test1.old-vinyldns2." , type : "A" , ttl : 200 , record : { address : "1.1.1.1" } , status : "Pending" , id : "c29d33e4-9bee-4417-a99b-6e815fdeb748" , changeType : "Add" } ] ,
status : "Pending" ,
id : "921e70fa-9bec-48eb-a520-a8e6106158e2"
} ;
deferred . resolve ( { data : mockBatchChange } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . batch ) . toEqual ( mockBatchChange ) ;
} ) ) ;
2019-11-04 11:00:14 -05:00
it ( 'should reject the promise' , inject ( function ( dnsChangeService ) {
2018-07-27 10:18:29 -04:00
this . scope . getBatchChange ( "nonExistentBatchChange" ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . getBatchChange ) . toHaveBeenCalled ( ) ;
expect ( dnsChangeService . getBatchChange ) . toHaveBeenCalledWith ( "nonExistentBatchChange" ) ;
2018-07-27 10:18:29 -04:00
deferred . reject ( { data : "Batch change with id wow cannot be found" , status : 404 } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . batch ) . toEqual ( { } ) ;
expect ( this . scope . alerts ) . toEqual ( [ { type : 'danger' , content : 'HTTP 404 (undefined): Batch change with id wow cannot be found' } ] ) ;
} ) ) ;
} ) ;
2019-08-14 14:34:50 -04:00
describe ( '$scope.confirmApprove' , function ( ) {
2019-11-04 11:00:14 -05:00
it ( 'should resolve the promise' , inject ( function ( dnsChangeService ) {
2019-08-14 14:34:50 -04:00
this . scope . confirmApprove ( "17350028-b2b8-428d-9f10-dbb518a0364d" , "great" ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . approveBatchChange ) . toHaveBeenCalled ( ) ;
2019-08-14 14:34:50 -04:00
deferred . resolve ( { data : { reviewComment : "great" } } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . reviewConfirmationMsg ) . toEqual ( null ) ;
expect ( this . scope . reviewType ) . toEqual ( null ) ;
} ) ) ;
2019-11-04 11:00:14 -05:00
it ( 'should reject the promise' , inject ( function ( dnsChangeService ) {
2019-08-14 14:34:50 -04:00
this . scope . confirmApprove ( "notPendingBatchChange" , "great" ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . approveBatchChange ) . toHaveBeenCalled ( ) ;
2019-08-14 14:34:50 -04:00
var errorData = { data : [ { changeType : "Add" , inputName : "onofe.ok." , type : "A" , ttl : 7200 , record : { address : "1.1.1.1" } } ,
{ changeType : "Add" , inputName : "wfonef.wfoefn." , type : "A" , ttl : 7200 , record : { address : "1.1.1.1" } , errors : [ 'Zone Discovery Failed: zone for "wfonef.wfoefn." doesn\'t exists' ] } ] }
deferred . reject ( { data : errorData , status : 400 } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . alerts ) . toEqual ( [ { type : 'danger' , content : "HTTP 400 (undefined): Issues still remain, cannot approve DNS Change. Resolve all outstanding issues or reject the DNS Change." } ] ) ;
} ) ) ;
} ) ;
describe ( '$scope.confirmReject' , function ( ) {
2019-11-04 11:00:14 -05:00
it ( 'should resolve the promise' , inject ( function ( dnsChangeService ) {
2019-08-14 14:34:50 -04:00
this . scope . confirmReject ( "17350028-b2b8-428d-9f10-dbb518a0364d" , "great" ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . rejectBatchChange ) . toHaveBeenCalled ( ) ;
2019-08-14 14:34:50 -04:00
deferred . resolve ( { data : { reviewComment : "no bueno" } } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . reviewConfirmationMsg ) . toEqual ( null ) ;
expect ( this . scope . reviewType ) . toEqual ( null ) ;
} ) ) ;
2019-11-04 11:00:14 -05:00
it ( 'should reject the promise' , inject ( function ( dnsChangeService ) {
2019-08-14 14:34:50 -04:00
this . scope . confirmReject ( "notPendingBatchChange" , "no bueno" ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . rejectBatchChange ) . toHaveBeenCalled ( ) ;
2019-08-14 14:34:50 -04:00
deferred . reject ( { data : "Batch change with id notPendingBatchChange is not pending review." , status : 400 } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . alerts ) . toEqual ( [ { type : 'danger' , content : 'HTTP 400 (undefined): Batch change with id notPendingBatchChange is not pending review.' } ] ) ;
} ) ) ;
} ) ;
2018-07-27 10:18:29 -04:00
} ) ;
2019-11-04 11:00:14 -05:00
describe ( 'Controller: DnsChangeNewController' , function ( ) {
2019-08-21 10:41:54 -04:00
var tomorrow = moment ( ) . startOf ( 'hour' ) . add ( 1 , 'day' ) . format ( 'LL hh:mm A' ) ;
2018-07-27 10:18:29 -04:00
beforeEach ( function ( ) {
module ( 'ngMock' )
} ) ;
2019-11-04 11:00:14 -05:00
beforeEach ( inject ( function ( $rootScope , $controller , $q , dnsChangeService , utilityService , groupsService ) {
2018-07-27 10:18:29 -04:00
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
2019-02-06 16:21:43 -05:00
this . groupsService = groupsService ;
2018-07-27 10:18:29 -04:00
this . scope . newBatch = { comments : "" , changes : [ { changeType : "Add" , type : "A" , ttl : 200 } ] } ;
2019-02-06 16:21:43 -05:00
this . scope . myGroups = { } ;
2018-07-27 10:18:29 -04:00
deferred = $q . defer ( ) ;
2019-11-04 11:00:14 -05:00
spyOn ( dnsChangeService , 'createBatchChange' ) . and . returnValue ( deferred . promise ) ;
2019-08-21 14:26:51 -04:00
groupsService . getGroups = function ( ) {
2019-02-06 16:21:43 -05:00
return $q . when ( {
data : {
groups : "all my groups"
}
} ) ;
} ;
2019-11-04 11:00:14 -05:00
this . controller = $controller ( 'DnsChangeNewController' , { '$scope' : this . scope } ) ;
2018-07-27 10:18:29 -04:00
} ) ) ;
2019-11-04 11:00:14 -05:00
it ( "test that we properly get user's groups when loading DnsChangeNewController" , function ( ) {
2019-02-06 16:21:43 -05:00
this . scope . $digest ( ) ;
expect ( this . scope . myGroups ) . toBe ( "all my groups" ) ;
} ) ;
2019-11-04 11:00:14 -05:00
it ( "test that we set a default scheduledTime when loading DnsChangeNewController" , function ( ) {
2019-08-21 10:41:54 -04:00
this . scope . $digest ( ) ;
expect ( this . scope . newBatch . scheduledTime ) . toBe ( tomorrow ) ;
} ) ;
2018-07-27 10:18:29 -04:00
describe ( '$scope.addSingleChange' , function ( ) {
it ( 'adds a change to the changes array' , function ( ) {
this . scope . addSingleChange ( ) ;
2019-08-21 10:41:54 -04:00
expect ( this . scope . newBatch ) . toEqual ( { comments : "" , changes : [ { changeType : "Add" , type : "A+PTR" } , { changeType : "Add" , type : "A+PTR" } ] , scheduledTime : tomorrow } )
2018-07-27 10:18:29 -04:00
} ) ;
} ) ;
describe ( '$scope.deleteSingleChange' , function ( ) {
it ( 'removes a change from the changes array' , function ( ) {
this . scope . deleteSingleChange ( 0 ) ;
2019-08-21 10:41:54 -04:00
expect ( this . scope . newBatch ) . toEqual ( { comments : "" , changes : [ ] , scheduledTime : tomorrow } )
2018-07-27 10:18:29 -04:00
} ) ;
} ) ;
2019-05-07 11:03:55 -04:00
describe ( '$scope.uploadCSV' , function ( ) {
beforeEach ( inject ( function ( $compile ) {
2019-06-03 16:44:45 -04:00
var formInput = $ ( '<ng-form name="createBatchChangeForm">' +
'<input type="file" id="batchChangeCsv" ng-model="csvInput" name="batchChangeCsv" class="batchChangeCsv" batch-change-file>' +
2019-05-07 11:03:55 -04:00
'</ng-form>' ) ;
2019-06-03 16:44:45 -04:00
$ ( document . body ) . append ( formInput ) ;
$compile ( formInput ) ( this . scope ) ;
2019-05-07 11:03:55 -04:00
this . scope . $digest ( ) ;
} ) ) ;
it ( 'parses a CSV file' , function ( done ) {
var fileBlob = new Blob ( [ "Change Type,Record Type,Input Name,TTL,Record Data\nAdd,A+PTR,test.example.,200,1.1.1.1" ] , { type : 'text/csv' } ) ;
var batchChange = this . scope . newBatch ;
this . scope . uploadCSV ( fileBlob ) ;
setTimeout ( function ( ) {
expect ( batchChange . changes . length ) . toEqual ( 1 ) ;
2019-08-21 10:41:54 -04:00
expect ( batchChange ) . toEqual ( { comments : "" , changes : [ { changeType : "Add" , type : "A+PTR" , inputName : "test.example." , ttl : 200 , record : { address : "1.1.1.1" } } ] , scheduledTime : tomorrow } ) ;
2019-05-07 11:03:55 -04:00
done ( ) ;
} , 2000 ) ;
} )
it ( 'is case insensitive' , function ( done ) {
var fileBlob = new Blob ( [ "Change Type,Record Type,Input Name,TTL,Record Data\nadd,a+pTR,test.example.,200,1.1.1.1" ] , { type : 'text/csv' } ) ;
var batchChange = this . scope . newBatch ;
this . scope . uploadCSV ( fileBlob ) ;
setTimeout ( function ( ) {
expect ( batchChange . changes . length ) . toEqual ( 1 )
2019-08-21 10:41:54 -04:00
expect ( batchChange ) . toEqual ( { comments : "" , changes : [ { changeType : "Add" , type : "A+PTR" , inputName : "test.example." , ttl : 200 , record : { address : "1.1.1.1" } } ] , scheduledTime : tomorrow } ) ;
2019-05-07 11:03:55 -04:00
done ( ) ;
} , 1000 ) ;
} )
2019-09-30 13:03:47 -04:00
it ( 'handles "delete" change type' , function ( done ) {
var fileBlob = new Blob ( [ "Change Type,Record Type,Input Name,TTL,Record Data\nDelete,A+PTR,test.example.,200,1.1.1.1" ] , { type : 'text/csv' } ) ;
2019-05-07 11:03:55 -04:00
var batchChange = this . scope . newBatch ;
this . scope . uploadCSV ( fileBlob ) ;
setTimeout ( function ( ) {
expect ( batchChange . changes . length ) . toEqual ( 1 )
2019-08-21 10:41:54 -04:00
expect ( batchChange ) . toEqual ( { comments : "" , changes : [ { changeType : "DeleteRecordSet" , type : "A+PTR" , inputName : "test.example." , ttl : 200 , record : { address : "1.1.1.1" } } ] , scheduledTime : tomorrow } ) ;
2019-05-07 11:03:55 -04:00
done ( ) ;
} , 1000 ) ;
} )
it ( 'handles whitespace' , function ( done ) {
2019-09-30 13:03:47 -04:00
var fileBlob = new Blob ( [ "Change Type,Record Type,Input Name,TTL,Record Data\nDelete, A+PTR ,test.example. ,200,1.1.1.1" ] , { type : 'text/csv' } ) ;
2019-05-07 11:03:55 -04:00
var batchChange = this . scope . newBatch ;
this . scope . uploadCSV ( fileBlob ) ;
setTimeout ( function ( ) {
expect ( batchChange . changes . length ) . toEqual ( 1 )
2019-08-21 10:41:54 -04:00
expect ( batchChange ) . toEqual ( { comments : "" , changes : [ { changeType : "DeleteRecordSet" , type : "A+PTR" , inputName : "test.example." , ttl : 200 , record : { address : "1.1.1.1" } } ] , scheduledTime : tomorrow } ) ;
2019-05-07 11:03:55 -04:00
done ( ) ;
} , 1000 ) ;
} )
2019-06-03 16:44:45 -04:00
it ( 'fails if the first line is not the header row' , function ( done ) {
2019-05-07 11:03:55 -04:00
var fileBlob = new Blob ( [ "Delete,A+PTR,test.example.,,1.1.1.1\nAdd,A+PTR,test.add.,200,1.1.1.1" ] , { type : 'text/csv' } ) ;
var batchChange = this . scope . newBatch ;
this . scope . uploadCSV ( fileBlob ) ;
2019-06-03 16:44:45 -04:00
var alerts = this . scope . alerts ;
2019-05-07 11:03:55 -04:00
setTimeout ( function ( ) {
expect ( batchChange . changes . length ) . toEqual ( 1 )
2019-08-21 10:41:54 -04:00
expect ( batchChange ) . toEqual ( { comments : "" , changes : [ { changeType : "Add" , type : "A+PTR" } ] , scheduledTime : tomorrow } ) ;
2019-05-07 11:03:55 -04:00
done ( ) ;
} , 1000 ) ;
} )
it ( 'does not include empty lines' , function ( done ) {
2019-09-30 13:03:47 -04:00
var fileBlob = new Blob ( [ "Change Type,Record Type,Input Name,TTL,Record Data\n,,,,,\nDelete,A+PTR,test.example.,200,1.1.1.1" ] , { type : 'text/csv' } ) ;
2019-05-07 11:03:55 -04:00
var batchChange = this . scope . newBatch ;
this . scope . uploadCSV ( fileBlob ) ;
setTimeout ( function ( ) {
expect ( batchChange . changes . length ) . toEqual ( 1 )
2019-08-21 10:41:54 -04:00
expect ( batchChange ) . toEqual ( { comments : "" , changes : [ { changeType : "DeleteRecordSet" , type : "A+PTR" , inputName : "test.example." , ttl : 200 , record : { address : "1.1.1.1" } } ] , scheduledTime : tomorrow } ) ;
2019-05-07 11:03:55 -04:00
done ( ) ;
} , 1000 ) ;
} )
it ( 'does not import non-CSV format files' , function ( ) {
2019-06-03 16:44:45 -04:00
var newFile = new Blob ( [ ] , { type : 'any' } ) ;
2019-05-07 11:03:55 -04:00
this . scope . uploadCSV ( newFile ) ;
2019-08-21 10:41:54 -04:00
expect ( this . scope . newBatch ) . toEqual ( { comments : "" , changes : [ { changeType : "Add" , type : "A+PTR" } ] , scheduledTime : tomorrow } ) ;
2019-05-07 11:03:55 -04:00
} ) ;
} ) ;
2018-07-27 10:18:29 -04:00
describe ( '$scope.createBatchChange' , function ( ) {
2019-11-04 11:00:14 -05:00
it ( 'should resolve the promise' , inject ( function ( dnsChangeService ) {
2018-07-27 10:18:29 -04:00
this . scope . newBatch = {
comments : "this is a comment." ,
changes : [ { changeType : "Add" , type : "A" , ttl : 200 , record : { address : "1.1.1.2" } } ]
} ;
this . scope . createBatchChange ( ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . createBatchChange ) . toHaveBeenCalled ( ) ;
2018-07-27 10:18:29 -04:00
var mockBatchChange = {
userId : "17350028-b2b8-428d-9f10-dbb518a0364d" ,
userName : "bwrigh833" ,
comments : "this is a test comment." ,
createdTimestamp : "2018-05-09T14:20:50Z" ,
changes : [ { zoneId : "937191c4-b1fd-4ab5-abb4-9553a65b44ab" , zoneName : "old-vinyldns2." , recordName : "test1" , inputName : "test1.old-vinyldns2." , type : "A" , ttl : 200 , record : { address : "1.1.1.1" } , status : "Pending" , id : "c29d33e4-9bee-4417-a99b-6e815fdeb748" , changeType : "Add" } ] ,
status : "Pending" ,
id : "921e70fa-9bec-48eb-a520-a8e6106158e2"
} ;
deferred . resolve ( { data : mockBatchChange } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . batch ) . toEqual ( mockBatchChange ) ;
} ) ) ;
it ( 'should reject the promise' , inject ( function ( batchChangeService ) {
this . scope . newBatch = {
comments : "zone not found." ,
changes : [ { changeType : "Add" , inputName : 'blah.dummy.' , type : "A" , ttl : 200 , record : { address : "1.1.1.2" } } ]
} ;
this . scope . createBatchChange ( ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . createBatchChange ) . toHaveBeenCalled ( ) ;
2018-07-27 10:18:29 -04:00
deferred . reject ( { config : { data : this . scope . newBatch } , data : [ { changeType : "Add" , inputName : 'blah.dummy.' , type : "A" , ttl : 200 , record : { address : "1.1.1.2" } , errors : [ 'Zone for "blah.dummy." does not exist in Vinyl.' ] } ] , status : 400 } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . batch ) . toEqual ( { } ) ;
expect ( this . scope . newBatch ) . toEqual ( {
comments : "zone not found." ,
changes : [ { changeType : "Add" , inputName : 'blah.dummy.' , type : "A" , ttl : 200 , record : { address : "1.1.1.2" } , errors : [ 'Zone for "blah.dummy." does not exist in Vinyl.' ] } ]
} ) ;
expect ( this . scope . alerts ) . toEqual ( [ { type : 'danger' , content : 'Errors found. Please correct and submit again.' } ] ) ;
} ) ) ;
2019-08-21 10:41:54 -04:00
2019-11-04 11:00:14 -05:00
it ( 'should format the batch change data' , inject ( function ( dnsChangeService ) {
2019-08-21 10:41:54 -04:00
this . scope . newBatch = {
comments : "this is a comment." ,
changes : [ { changeType : "Add" , inputName : 'blah.dummy.' , type : "A+PTR" , ttl : 200 , record : { address : "1.1.1.2" } } ] ,
scheduledTime : tomorrow ,
} ;
this . scope . createBatchChange ( ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . createBatchChange ) . toHaveBeenCalled ( ) ;
2019-08-21 10:41:54 -04:00
deferred . resolve ( { data : { } } ) ;
this . rootScope . $apply ( ) ;
expect ( this . scope . newBatch . ownerGroupId ) . toBeUndefined ( ) ;
expect ( this . scope . newBatch . scheduledTime ) . toBeUndefined ( ) ;
expect ( this . scope . newBatch . changes ) . toEqual ( [
{ changeType : "Add" , inputName : 'blah.dummy.' , type : "A" , ttl : 200 , record : { address : "1.1.1.2" } } ,
{ changeType : "Add" , inputName : '1.1.1.2' , type : "PTR" , ttl : 200 , record : { ptrdname : "blah.dummy." } }
] ) ;
} ) ) ;
2018-07-27 10:18:29 -04:00
} ) ;
} ) ;
2019-11-04 11:00:14 -05:00
describe ( 'Controller: DnsChangesController' , function ( ) {
2018-07-27 10:18:29 -04:00
beforeEach ( function ( ) {
module ( 'ngMock' )
} ) ;
2019-11-04 11:00:14 -05:00
beforeEach ( inject ( function ( $rootScope , $controller , $q , dnsChangeService , utilityService ) {
2018-07-27 10:18:29 -04:00
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
2019-11-04 11:00:14 -05:00
this . controller = $controller ( 'DnsChangesController' , { '$scope' : this . scope } ) ;
2018-07-27 10:18:29 -04:00
deferred = $q . defer ( ) ;
2019-11-04 11:00:14 -05:00
spyOn ( dnsChangeService , 'getBatchChanges' ) . and . returnValue ( deferred . promise ) ;
2018-07-27 10:18:29 -04:00
} ) ) ;
describe ( '$scope.getBatchChanges' , function ( ) {
2019-11-04 11:00:14 -05:00
it ( 'should resolve the promise' , inject ( function ( dnsChangeService ) {
2018-07-27 10:18:29 -04:00
this . scope . getBatchChanges ( )
. then ( function ( response ) {
expect ( response . data . batchChanges ) . toBe ( mockBatchChanges )
} ) ;
2019-11-04 11:00:14 -05:00
expect ( dnsChangeService . getBatchChanges ) . toHaveBeenCalled ( ) ;
2018-07-27 10:18:29 -04:00
var mockBatchChanges = {
comments : "this is hopefully a full failure" ,
createdTimestamp : "Fri May 18 2018 15:01:41" ,
id : "5bcfd2fe-81d8-4eae-897f-aa8a7c9cbc00" ,
singleChangeCount : 1 ,
status : "Failed" ,
userId : "17350028-b2b8-428d-9f10-dbb518a0364d" ,
userName : "bwrigh833"
} ;
deferred . resolve ( { data : { batchChanges : mockBatchChanges } } ) ;
this . rootScope . $apply ( ) ;
} ) ) ;
} ) ;
} ) ;
describe ( 'Service: batchChange' , function ( ) {
beforeEach ( inject ( function ( $httpBackend , batchChangeService ) {
2019-11-04 11:00:14 -05:00
this . dnsChangeService = batchChangeService ;
2018-07-27 10:18:29 -04:00
this . $httpBackend = $httpBackend ;
} ) ) ;
it ( 'http backend gets called properly when getting a batch changes' , function ( ) {
2019-08-07 12:18:17 -04:00
this . $httpBackend . expectGET ( '/api/dnschanges/123' ) . respond ( 'batch change returned' ) ;
2019-11-04 11:00:14 -05:00
this . dnsChangeService . getBatchChange ( '123' )
2018-07-27 10:18:29 -04:00
. then ( function ( response ) {
expect ( response . data ) . toBe ( 'batch change returned' ) ;
} ) ;
this . $httpBackend . flush ( ) ;
} ) ;
it ( 'http backend gets called properly when creating a batch change' , function ( ) {
2019-08-07 12:18:17 -04:00
this . $httpBackend . expectPOST ( '/api/dnschanges' ) . respond ( 'batch change created' ) ;
2019-11-04 11:00:14 -05:00
this . dnsChangeService . createBatchChange ( { comments : "" , changes : [ { changeType : "Add" , type : "A" , ttl : 200 } ] } )
2018-07-27 10:18:29 -04:00
. then ( function ( response ) {
expect ( response . data ) . toBe ( 'batch change created' ) ;
} ) ;
this . $httpBackend . flush ( ) ;
} ) ;
2019-08-14 14:34:50 -04:00
it ( 'http backend gets called properly when approving a batch change' , function ( ) {
this . $httpBackend . expectPOST ( '/api/dnschanges/123/approve' ) . respond ( 'batch change created' ) ;
2019-11-04 11:00:14 -05:00
this . dnsChangeService . approveBatchChange ( "123" , "good" )
2019-08-14 14:34:50 -04:00
. then ( function ( response ) {
expect ( response . data ) . toBe ( 'batch change created' ) ;
} ) ;
this . $httpBackend . flush ( ) ;
} ) ;
it ( 'http backend gets called properly when rejecting a batch change' , function ( ) {
this . $httpBackend . expectPOST ( '/api/dnschanges/123/reject' ) . respond ( 'batch change created' ) ;
2019-11-04 11:00:14 -05:00
this . dnsChangeService . rejectBatchChange ( "123" , "bad" )
2019-08-14 14:34:50 -04:00
. then ( function ( response ) {
expect ( response . data ) . toBe ( 'batch change created' ) ;
} ) ;
this . $httpBackend . flush ( ) ;
} ) ;
2018-07-27 10:18:29 -04:00
} ) ;
describe ( 'Directive: FQDN validation' , function ( ) {
var form ;
beforeEach ( inject ( function ( $compile , $rootScope ) {
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
var element = angular . element (
'<form name="form">' +
'<input ng-model="change.cname" name="cname" fqdn />' +
'</form>'
) ;
this . scope . change = { fqdn : null } ;
$compile ( element ) ( this . scope ) ;
form = this . scope . form ;
} ) ) ;
it ( 'passes with at least one dot' , function ( ) {
form . cname . $setViewValue ( 'test.com' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toEqual ( 'test.com' ) ;
expect ( form . cname . $valid ) . toBe ( true ) ;
} ) ;
it ( 'passes with trailing dot' , function ( ) {
form . cname . $setViewValue ( 'test.' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toEqual ( 'test.' ) ;
expect ( form . cname . $valid ) . toBe ( true ) ;
} ) ;
it ( 'fails without any dots' , function ( ) {
form . cname . $setViewValue ( 'invalidfqdn' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toBeUndefined ( ) ;
expect ( form . cname . $valid ) . toBe ( false ) ;
} ) ;
} ) ;
2019-11-19 11:33:09 -05:00
describe ( 'Directive: Invalid IPv4 validation for CNAME record data' , function ( ) {
var form ;
beforeEach ( inject ( function ( $compile , $rootScope ) {
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
var element = angular . element (
'<form name="form">' +
'<input ng-model="change.cname" name="cname" invalidip />' +
'</form>'
) ;
this . scope . change = { fqdn : null } ;
$compile ( element ) ( this . scope ) ;
form = this . scope . form ;
} ) ) ;
it ( 'fails with an IPV4 address' , function ( ) {
form . cname . $setViewValue ( '1.1.1.1' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toBeUndefined ( ) ;
expect ( form . cname . $valid ) . toBe ( false ) ;
} ) ;
it ( 'fails with an IPV4 address and a trailing dot' , function ( ) {
form . cname . $setViewValue ( 'test.' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toBeUndefined ( ) ;
expect ( form . cname . $valid ) . toBe ( false ) ;
} ) ;
it ( 'passes if not given an IPV4 address' , function ( ) {
form . cname . $setViewValue ( 'notanIP' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toEqual ( 'notanIP' ) ;
expect ( form . cname . $valid ) . toBe ( true ) ;
} ) ;
} ) ;
describe ( 'Directive: combined CNAME record data validations' , function ( ) {
var form ;
beforeEach ( inject ( function ( $compile , $rootScope ) {
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
var element = angular . element (
'<form name="form">' +
'<input ng-model="change.cname" name="cname" fqdn invalidip />' +
'</form>'
) ;
this . scope . change = { fqdn : null } ;
$compile ( element ) ( this . scope ) ;
form = this . scope . form ;
} ) ) ;
it ( 'passes with at least one dot and not an IP Address' , function ( ) {
form . cname . $setViewValue ( 'test.com' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toEqual ( 'test.com' ) ;
expect ( form . cname . $valid ) . toBe ( false ) ;
} ) ;
it ( 'fails with an IP Address' , function ( ) {
form . cname . $setViewValue ( '1.1.1.1' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toBeUndefined ( ) ;
expect ( form . cname . $valid ) . toBe ( false ) ;
} ) ;
it ( 'fails without at least one dot' , function ( ) {
form . cname . $setViewValue ( 'testcom' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . cname ) . toBeUndefined ( ) ;
expect ( form . cname . $valid ) . toBe ( false ) ;
} ) ;
2021-11-02 17:06:24 -04:00
} ) ;
2019-11-19 11:33:09 -05:00
2018-07-27 10:18:29 -04:00
describe ( 'Directive: IPv4 validation' , function ( ) {
var form ;
beforeEach ( inject ( function ( $compile , $rootScope ) {
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
var element = angular . element (
'<form name="form">' +
'<input ng-model="change.address" name="address" ipv4 />' +
'</form>'
) ;
this . scope . change = { address : null } ;
$compile ( element ) ( this . scope ) ;
form = this . scope . form ;
} ) ) ;
it ( 'passes with correct IPv4 format' , function ( ) {
form . address . $setViewValue ( '1.1.1.1' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . address ) . toEqual ( '1.1.1.1' ) ;
expect ( form . address . $valid ) . toBe ( true ) ;
} ) ;
it ( 'fails with incorrect IPv4 format' , function ( ) {
form . address . $setViewValue ( 'bad.ipv4' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . address ) . toBeUndefined ( ) ;
expect ( form . address . $valid ) . toBe ( false ) ;
} ) ;
} ) ;
describe ( 'Directive: IPv6 validation' , function ( ) {
var form ;
beforeEach ( inject ( function ( $compile , $rootScope ) {
this . rootScope = $rootScope ;
this . scope = $rootScope . $new ( ) ;
var element = angular . element (
'<form name="form">' +
'<input ng-model="change.address" name="address" ipv6 />' +
'</form>'
) ;
this . scope . change = { address : null } ;
$compile ( element ) ( this . scope ) ;
form = this . scope . form ;
} ) ) ;
it ( 'passes with correct IPv6 format' , function ( ) {
form . address . $setViewValue ( 'fd69:27cc:fe91::60' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . address ) . toEqual ( 'fd69:27cc:fe91::60' ) ;
expect ( form . address . $valid ) . toBe ( true ) ;
} ) ;
it ( 'fails with incorrect IPv6 format' , function ( ) {
form . address . $setViewValue ( 'bad.ipv6' ) ;
this . scope . $digest ( ) ;
expect ( this . scope . change . address ) . toBeUndefined ( ) ;
expect ( form . address . $valid ) . toBe ( false ) ;
} ) ;
} ) ;
} ) ;