@@ -153,6 +153,33 @@ describe("Module `web-tool-processor`: ", () => {
153153 expect ( blobToJsonSpy . calls . count ( ) ) . toBe ( 1 ) ;
154154 } ) ;
155155
156+ it ( "can handle error on getEnterpriseServers" , async ( ) => {
157+ const getEnterpriseServersSpy = spyOn ( common , "getEnterpriseServers" ) . and . throwError ( "error" )
158+
159+ await WebToolProcessor . createItemFromTemplate (
160+ {
161+ id : "bc3" ,
162+ type : "Geoprocessing Service" ,
163+ item : {
164+ typeKeywords : [ "Web Tool" ] ,
165+ thumbnail : "thumb" ,
166+ } ,
167+ data : {
168+ notebookId : "123" ,
169+ name : "NotebookName" ,
170+ } ,
171+ } as any ,
172+ {
173+ isPortal : true
174+ } ,
175+ MOCK_USER_SESSION ,
176+ cb ,
177+ ) ;
178+
179+ expect ( getEnterpriseServersSpy . calls . count ( ) ) . toBe ( 1 ) ;
180+ expect ( getEnterpriseServersSpy ) . toThrowError ( ) ;
181+ } ) ;
182+
156183 it ( "Web Tool Geoprocessing Service handles cancel with item removal" , async ( ) => {
157184 const createCb2 = ( ) => {
158185 let calls = 0 ;
@@ -638,12 +665,100 @@ describe("Module `web-tool-processor`: ", () => {
638665 type : "Geoprocessing Service" ,
639666 item : { typeKeywords : [ "Web Tool" ] } ,
640667 } as any ,
641- undefined ,
668+ { } ,
642669 MOCK_USER_SESSION ,
643670 ) . then (
644671 ( ) => fail ( ) ,
645672 ( e ) => expect ( e ) . toBeUndefined ( ) ,
646673 ) ;
647674 } ) ;
648675 } ) ;
676+
677+ describe ( "getNotebookServerCreateServiceURL" , ( ) => {
678+ it ( "should fetch servers for Enterprise" , async ( ) => {
679+ const notebookBaseUrl = "https://RQALnxBI01NB.esri.com/gis" ;
680+ const getEnterpriseServersSpy = spyOn ( common , "getEnterpriseServers" ) . and . resolveTo ( [
681+ {
682+ "id" : "e0d0rP32Fai4ToC3" ,
683+ "name" : "RQALnxBI01Sv.esri.com:6443" ,
684+ "adminUrl" : "https://RQALnxBI01Sv.esri.com:6443/arcgis" ,
685+ "url" : "https://RQALnxBI01Sv.esri.com/gis" ,
686+ "isHosted" : true ,
687+ "serverType" : "ArcGIS" ,
688+ "serverRole" : "HOSTING_SERVER" ,
689+ "serverFunction" : "KnowledgeServer,WorkflowManager"
690+ } ,
691+ {
692+ "id" : "U5yshUHhJkWINozX" ,
693+ "name" : "RQALnxBI01NB.esri.com:11443" ,
694+ "adminUrl" : "https://RQALnxBI01NB.esri.com:11443/arcgis" ,
695+ "url" : notebookBaseUrl ,
696+ "isHosted" : false ,
697+ "serverType" : "ARCGIS_NOTEBOOK_SERVER" ,
698+ "serverRole" : "FEDERATED_SERVER" ,
699+ "serverFunction" : "NotebookServer"
700+ }
701+ ] ) ;
702+
703+ return WebToolProcessor . getNotebookServerCreateServiceURL (
704+ "https://gisserver.domain.com/server" ,
705+ MOCK_USER_SESSION ,
706+ {
707+ isPortal : true
708+ }
709+ ) . then (
710+ ( url ) => {
711+ expect ( getEnterpriseServersSpy . calls . count ( ) ) . toBe ( 1 ) ;
712+ expect ( url . startsWith (
713+ `${ notebookBaseUrl } /admin/services/createService?f=json&request.preventCache=`
714+ ) ) . toBe ( true ) ;
715+ } ,
716+ ( ) => fail ( ) ,
717+ ) ;
718+ } ) ;
719+
720+
721+ it ( "should handle missing Enterprise server" , async ( ) => {
722+ const getEnterpriseServersSpy = spyOn ( common , "getEnterpriseServers" ) . and . resolveTo ( [
723+ {
724+ "id" : "e0d0rP32Fai4ToC3" ,
725+ "name" : "RQALnxBI01Sv.esri.com:6443" ,
726+ "adminUrl" : "https://RQALnxBI01Sv.esri.com:6443/arcgis" ,
727+ "url" : "https://RQALnxBI01Sv.esri.com/gis" ,
728+ "isHosted" : true ,
729+ "serverType" : "ArcGIS" ,
730+ "serverRole" : "HOSTING_SERVER" ,
731+ "serverFunction" : "KnowledgeServer,WorkflowManager"
732+ }
733+ ] ) ;
734+
735+ return WebToolProcessor . getNotebookServerCreateServiceURL (
736+ "https://gisserver.domain.com/server" ,
737+ MOCK_USER_SESSION ,
738+ {
739+ isPortal : true
740+ }
741+ ) . then (
742+ ( url ) => {
743+ expect ( getEnterpriseServersSpy . calls . count ( ) ) . toBe ( 1 ) ;
744+ expect ( url ) . toBe ( "" ) ;
745+ } ,
746+ ( ) => fail ( ) ,
747+ ) ;
748+ } ) ;
749+
750+ it ( "should handle missing portalUrls" , async ( ) => {
751+ return WebToolProcessor . getNotebookServerCreateServiceURL (
752+ "https://gisserver.domain.com/server" ,
753+ MOCK_USER_SESSION ,
754+ { }
755+ ) . then (
756+ ( url ) => {
757+ expect ( url ) . toBe ( "" ) ;
758+ } ,
759+ ( ) => fail ( ) ,
760+ ) ;
761+ } ) ;
762+
763+ } ) ;
649764} ) ;
0 commit comments