@@ -16,7 +16,7 @@ import { assert, expect, config as chaiConfig } from 'chai';
16
16
import { OAuth2 } from 'jsforce' ;
17
17
import { Transport } from 'jsforce/lib/transport' ;
18
18
import { SinonSpy , SinonStub } from 'sinon' ;
19
- import { Org , SandboxEvents , SandboxProcessObject , SandboxUserAuthResponse } from '../../../src/org/org' ;
19
+ import { Org , SandboxEvents , SandboxInfo , SandboxProcessObject , SandboxUserAuthResponse } from '../../../src/org/org' ;
20
20
import { AuthInfo } from '../../../src/org/authInfo' ;
21
21
import { } from '../../../src/org/connection' ;
22
22
import { Connection , SingleRecordQueryErrors } from '../../../src/org/connection' ;
@@ -894,6 +894,20 @@ describe('Org Tests', () => {
894
894
] ,
895
895
} ;
896
896
897
+ const sandboxProcessFields = [
898
+ 'Id' ,
899
+ 'Status' ,
900
+ 'SandboxName' ,
901
+ 'SandboxInfoId' ,
902
+ 'LicenseType' ,
903
+ 'CreatedDate' ,
904
+ 'CopyProgress' ,
905
+ 'SandboxOrganization' ,
906
+ 'SourceId' ,
907
+ 'Description' ,
908
+ 'EndDate' ,
909
+ ] ;
910
+
897
911
let prodTestData : MockTestOrgData ;
898
912
let prod : Org ;
899
913
@@ -973,16 +987,111 @@ describe('Org Tests', () => {
973
987
SandboxName : 'test' ,
974
988
EndDate : '2021-19-06T20:25:46.000+0000' ,
975
989
} as SandboxProcessObject ;
990
+ const err = new Error ( 'could not auth' ) ;
991
+ err . name = 'INVALID_STATUS' ;
976
992
// @ts -expect-error - type not assignable
977
- stubMethod < SandboxUserAuthResponse > ( $$ . SANDBOX , prod . getConnection ( ) . tooling , 'request' ) . throws ( {
978
- name : 'INVALID_STATUS' ,
979
- } ) ;
993
+ stubMethod < SandboxUserAuthResponse > ( $$ . SANDBOX , prod . getConnection ( ) . tooling , 'request' ) . throws ( err ) ;
980
994
981
995
// @ts -expect-error because private method
982
996
await prod . sandboxSignupComplete ( sandboxResponse ) ;
983
997
expect ( logStub . callCount ) . to . equal ( 3 ) ;
984
998
// error swallowed
985
- expect ( logStub . thirdCall . args [ 0 ] ) . to . equal ( 'Error while authenticating the user' ) ;
999
+ expect ( logStub . thirdCall . args [ 0 ] ) . to . equal ( 'Error while authenticating the user:' ) ;
1000
+ } ) ;
1001
+ } ) ;
1002
+
1003
+ describe ( 'refreshSandbox' , ( ) => {
1004
+ const sbxInfo : SandboxInfo = {
1005
+ Id : '0GQ4p000000U6nFGAS' ,
1006
+ SandboxName : 'testSbx1' ,
1007
+ LicenseType : 'DEVELOPER' ,
1008
+ HistoryDays : 0 ,
1009
+ CopyChatter : false ,
1010
+ AutoActivate : true ,
1011
+ IsDeleted : false ,
1012
+ CreatedDate : '2024-02-16T17:06:47.000+0000' ,
1013
+ CreatedById : '005B0000004TiUpIAK' ,
1014
+ LastModifiedDate : '2024-02-16T17:06:47.000+0000' ,
1015
+ LastModifiedById : '005B0000004TiUpIAK' ,
1016
+ } ;
1017
+ const sbxProcess = {
1018
+ attributes : {
1019
+ type : 'SandboxProcess' ,
1020
+ url : '/services/data/v60.0/tooling/sobjects/SandboxProcess/0GR1Q0000004kmaWAA' ,
1021
+ } ,
1022
+ Id : '0GR1Q0000004kmaWAA' ,
1023
+ Status : 'Activating' ,
1024
+ SandboxName : 'sbxGS02' ,
1025
+ SandboxInfoId : '0GQ1Q0000004iQDWAY' ,
1026
+ LicenseType : 'DEVELOPER' ,
1027
+ CreatedDate : '2024-02-21T23:06:58.000+0000' ,
1028
+ CopyProgress : 95 ,
1029
+ SandboxOrganization : '00DDX000000QT3W' ,
1030
+ SourceId : null ,
1031
+ Description : null ,
1032
+ EndDate : null ,
1033
+ } ;
1034
+ let updateStub : SinonStub ;
1035
+ let querySandboxProcessStub : SinonStub ;
1036
+ let pollStatusAndAuthStub : SinonStub ;
1037
+
1038
+ beforeEach ( async ( ) => {
1039
+ updateStub = stubMethod ( $$ . SANDBOX , prod . getConnection ( ) . tooling , 'update' ) . resolves ( {
1040
+ id : '0GQ4p000000U6nFGAS' ,
1041
+ success : true ,
1042
+ } ) ;
1043
+ querySandboxProcessStub = stubMethod ( $$ . SANDBOX , prod . getConnection ( ) . tooling , 'query' ) ;
1044
+ pollStatusAndAuthStub = stubMethod ( $$ . SANDBOX , prod , 'pollStatusAndAuth' ) . resolves ( sbxProcess ) ;
1045
+ } ) ;
1046
+
1047
+ it ( 'will refresh the SandboxInfo sObject correctly with polling' , async ( ) => {
1048
+ querySandboxProcessStub . resolves ( { records : [ sbxProcess ] } ) ;
1049
+ const expectedQuery = `SELECT ${ sandboxProcessFields . join ( ',' ) } FROM SandboxProcess WHERE SandboxName='${
1050
+ sbxInfo . SandboxName
1051
+ } ' ORDER BY CreatedDate DESC`;
1052
+
1053
+ const result = await prod . refreshSandbox ( sbxInfo , { wait : Duration . seconds ( 30 ) } ) ;
1054
+
1055
+ expect ( updateStub . calledOnce ) . to . be . true ;
1056
+ expect ( updateStub . firstCall . args [ 0 ] ) . to . equal ( 'SandboxInfo' ) ;
1057
+ expect ( updateStub . firstCall . args [ 1 ] ) . to . equal ( sbxInfo ) ;
1058
+ expect ( querySandboxProcessStub . calledOnce ) . to . be . true ;
1059
+ expect ( querySandboxProcessStub . firstCall . args [ 0 ] ) . to . equal ( expectedQuery ) ;
1060
+ expect ( pollStatusAndAuthStub . calledOnce ) . to . be . true ;
1061
+ expect ( result ) . to . equal ( sbxProcess ) ;
1062
+ } ) ;
1063
+
1064
+ it ( 'will refresh the SandboxInfo sObject correctly async' , async ( ) => {
1065
+ querySandboxProcessStub . resolves ( { records : [ sbxProcess ] } ) ;
1066
+ const expectedQuery = `SELECT ${ sandboxProcessFields . join ( ',' ) } FROM SandboxProcess WHERE SandboxName='${
1067
+ sbxInfo . SandboxName
1068
+ } ' ORDER BY CreatedDate DESC`;
1069
+
1070
+ const result = await prod . refreshSandbox ( sbxInfo , { async : true } ) ;
1071
+
1072
+ expect ( updateStub . calledOnce ) . to . be . true ;
1073
+ expect ( updateStub . firstCall . args [ 0 ] ) . to . equal ( 'SandboxInfo' ) ;
1074
+ expect ( updateStub . firstCall . args [ 1 ] ) . to . equal ( sbxInfo ) ;
1075
+ expect ( querySandboxProcessStub . calledOnce ) . to . be . true ;
1076
+ expect ( querySandboxProcessStub . firstCall . args [ 0 ] ) . to . equal ( expectedQuery ) ;
1077
+ expect ( pollStatusAndAuthStub . called ) . to . be . false ;
1078
+ expect ( result ) . to . equal ( sbxProcess ) ;
1079
+ } ) ;
1080
+
1081
+ it ( 'will throw an error if it fails to update the SandboxInfo' , async ( ) => {
1082
+ updateStub . restore ( ) ;
1083
+ updateStub = stubMethod ( $$ . SANDBOX , prod . getConnection ( ) . tooling , 'update' ) . resolves ( {
1084
+ error : 'duplicate value found' ,
1085
+ success : false ,
1086
+ } ) ;
1087
+ try {
1088
+ await shouldThrow ( prod . refreshSandbox ( sbxInfo , { async : true } ) ) ;
1089
+ } catch ( e ) {
1090
+ expect ( updateStub . calledOnce ) . to . be . true ;
1091
+ expect ( ( e as Error ) . message ) . to . include ( 'The sandbox org refresh failed with a result of' ) ;
1092
+ expect ( ( e as Error ) . message ) . to . include ( 'duplicate value found' ) ;
1093
+ expect ( ( e as SfError ) . exitCode ) . to . equal ( 1 ) ;
1094
+ }
986
1095
} ) ;
987
1096
} ) ;
988
1097
@@ -1058,8 +1167,9 @@ describe('Org Tests', () => {
1058
1167
} ) ;
1059
1168
1060
1169
describe ( 'resumeSandbox' , ( ) => {
1061
- const expectedSoql =
1062
- 'SELECT Id,Status,SandboxName,SandboxInfoId,LicenseType,CreatedDate,CopyProgress,SandboxOrganization,SourceId,Description,EndDate FROM SandboxProcess WHERE %s ORDER BY CreatedDate DESC' ;
1170
+ const expectedSoql = `SELECT ${ sandboxProcessFields . join (
1171
+ ','
1172
+ ) } FROM SandboxProcess WHERE %s ORDER BY CreatedDate DESC`;
1063
1173
let lifecycleSpy : SinonSpy ;
1064
1174
let queryStub : SinonStub ;
1065
1175
let pollStatusAndAuthSpy : SinonSpy ;
@@ -1193,7 +1303,9 @@ describe('Org Tests', () => {
1193
1303
let queryStub : SinonStub ;
1194
1304
let pollStatusAndAuthStub : SinonStub ;
1195
1305
const sandboxNameIn = 'test-sandbox' ;
1196
- const queryStr = `SELECT Id, Status, SandboxName, SandboxInfoId, LicenseType, CreatedDate, CopyProgress, SandboxOrganization, SourceId, Description, EndDate FROM SandboxProcess WHERE SandboxName='${ sandboxNameIn } ' AND Status != 'D' ORDER BY CreatedDate DESC LIMIT 1` ;
1306
+ const queryStr = `SELECT ${ sandboxProcessFields . join (
1307
+ ','
1308
+ ) } FROM SandboxProcess WHERE SandboxName='${ sandboxNameIn } ' AND Status != 'D' ORDER BY CreatedDate DESC LIMIT 1`;
1197
1309
1198
1310
beforeEach ( async ( ) => {
1199
1311
queryStub = stubMethod ( $$ . SANDBOX , prod . getConnection ( ) . tooling , 'query' ) ;
@@ -1250,7 +1362,9 @@ describe('Org Tests', () => {
1250
1362
const deletedSbxProcess = Object . assign ( { } , statusResult . records [ 0 ] , { Status : 'Deleted' } ) ;
1251
1363
queryStub . resolves ( { records : [ deletingSbxProcess , statusResult . records [ 0 ] , deletedSbxProcess ] } ) ;
1252
1364
const where = 'name="foo"' ;
1253
- const expectedSoql = `SELECT Id,Status,SandboxName,SandboxInfoId,LicenseType,CreatedDate,CopyProgress,SandboxOrganization,SourceId,Description,EndDate FROM SandboxProcess WHERE ${ where } ORDER BY CreatedDate DESC` ;
1365
+ const expectedSoql = `SELECT ${ sandboxProcessFields . join (
1366
+ ','
1367
+ ) } FROM SandboxProcess WHERE ${ where } ORDER BY CreatedDate DESC`;
1254
1368
1255
1369
// @ts -ignore Testing a private method
1256
1370
const sbxProcess = await prod . querySandboxProcess ( where ) ;
0 commit comments