@@ -61,6 +61,158 @@ describe('OrgPreferences', () => {
6161 } ) ;
6262 } ) ;
6363
64+ describe ( 'readDrVersion' , ( ) => {
65+ it ( 'should return true when DR versioning is enabled' , async ( ) => {
66+ // Arrange
67+ const metadataReadResult = {
68+ enableOmniStudioDrVersion : 'true' ,
69+ } ;
70+ const metadataReadStub = sandbox . stub ( ) . resolves ( metadataReadResult ) ;
71+ connection . metadata . read = metadataReadStub ;
72+
73+ // Act
74+ const result = await OrgPreferences . readDrVersion ( connection ) ;
75+
76+ // Assert
77+ expect ( result ) . to . be . true ;
78+ expect ( metadataReadStub . calledOnce ) . to . be . true ;
79+ expect ( metadataReadStub . firstCall . args [ 0 ] ) . to . equal ( 'OmniStudioSettings' ) ;
80+ expect ( metadataReadStub . firstCall . args [ 1 ] ) . to . deep . equal ( [ 'OmniStudioDrVersionOrgPreference' ] ) ;
81+ } ) ;
82+
83+ it ( 'should return false when DR versioning is disabled' , async ( ) => {
84+ // Arrange
85+ const metadataReadResult = {
86+ enableOmniStudioDrVersion : 'false' ,
87+ } ;
88+ const metadataReadStub = sandbox . stub ( ) . resolves ( metadataReadResult ) ;
89+ connection . metadata . read = metadataReadStub ;
90+
91+ // Act
92+ const result = await OrgPreferences . readDrVersion ( connection ) ;
93+
94+ // Assert
95+ expect ( result ) . to . be . false ;
96+ expect ( metadataReadStub . calledOnce ) . to . be . true ;
97+ } ) ;
98+
99+ it ( 'should return false when enableOmniStudioDrVersion is not "true"' , async ( ) => {
100+ // Arrange
101+ const metadataReadResult = {
102+ enableOmniStudioDrVersion : 'maybe' ,
103+ } ;
104+ const metadataReadStub = sandbox . stub ( ) . resolves ( metadataReadResult ) ;
105+ connection . metadata . read = metadataReadStub ;
106+
107+ // Act
108+ const result = await OrgPreferences . readDrVersion ( connection ) ;
109+
110+ // Assert
111+ expect ( result ) . to . be . false ;
112+ expect ( metadataReadStub . calledOnce ) . to . be . true ;
113+ } ) ;
114+
115+ it ( 'should return false when enableOmniStudioDrVersion is undefined' , async ( ) => {
116+ // Arrange
117+ const metadataReadResult = { } ;
118+ const metadataReadStub = sandbox . stub ( ) . resolves ( metadataReadResult ) ;
119+ connection . metadata . read = metadataReadStub ;
120+
121+ // Act
122+ const result = await OrgPreferences . readDrVersion ( connection ) ;
123+
124+ // Assert
125+ expect ( result ) . to . be . false ;
126+ expect ( metadataReadStub . calledOnce ) . to . be . true ;
127+ } ) ;
128+
129+ it ( 'should return false when enableOmniStudioDrVersion is null' , async ( ) => {
130+ // Arrange
131+ const metadataReadResult = {
132+ enableOmniStudioDrVersion : null ,
133+ } ;
134+ const metadataReadStub = sandbox . stub ( ) . resolves ( metadataReadResult ) ;
135+ connection . metadata . read = metadataReadStub ;
136+
137+ // Act
138+ const result = await OrgPreferences . readDrVersion ( connection ) ;
139+
140+ // Assert
141+ expect ( result ) . to . be . false ;
142+ expect ( metadataReadStub . calledOnce ) . to . be . true ;
143+ } ) ;
144+
145+ it ( 'should throw error when metadata read fails' , async ( ) => {
146+ // Arrange
147+ const error = new Error ( 'Metadata read failed' ) ;
148+ const metadataReadStub = sandbox . stub ( ) . rejects ( error ) ;
149+ connection . metadata . read = metadataReadStub ;
150+
151+ // Act & Assert
152+ try {
153+ await OrgPreferences . readDrVersion ( connection ) ;
154+ expect . fail ( 'Expected an error to be thrown' ) ;
155+ } catch ( err : unknown ) {
156+ if ( err instanceof Error ) {
157+ expect ( err . message ) . to . equal ( 'Failed to read DR version: Metadata read failed' ) ;
158+ } else {
159+ expect . fail ( 'Expected an Error object' ) ;
160+ }
161+ }
162+ } ) ;
163+
164+ it ( 'should throw error when metadata read fails with non-Error object' , async ( ) => {
165+ // Arrange
166+ const error = 'String error message' ;
167+ const metadataReadStub = sandbox . stub ( ) . rejects ( error ) ;
168+ connection . metadata . read = metadataReadStub ;
169+
170+ // Act & Assert
171+ try {
172+ await OrgPreferences . readDrVersion ( connection ) ;
173+ expect . fail ( 'Expected an error to be thrown' ) ;
174+ } catch ( err : unknown ) {
175+ if ( err instanceof Error ) {
176+ expect ( err . message ) . to . equal ( 'Failed to read DR version: ' ) ;
177+ } else {
178+ expect . fail ( 'Expected an Error object' ) ;
179+ }
180+ }
181+ } ) ;
182+
183+ it ( 'should handle boolean true value correctly' , async ( ) => {
184+ // Arrange
185+ const metadataReadResult = {
186+ enableOmniStudioDrVersion : true ,
187+ } ;
188+ const metadataReadStub = sandbox . stub ( ) . resolves ( metadataReadResult ) ;
189+ connection . metadata . read = metadataReadStub ;
190+
191+ // Act
192+ const result = await OrgPreferences . readDrVersion ( connection ) ;
193+
194+ // Assert
195+ expect ( result ) . to . be . false ; // Should be false because it's not the string 'true'
196+ expect ( metadataReadStub . calledOnce ) . to . be . true ;
197+ } ) ;
198+
199+ it ( 'should handle boolean false value correctly' , async ( ) => {
200+ // Arrange
201+ const metadataReadResult = {
202+ enableOmniStudioDrVersion : false ,
203+ } ;
204+ const metadataReadStub = sandbox . stub ( ) . resolves ( metadataReadResult ) ;
205+ connection . metadata . read = metadataReadStub ;
206+
207+ // Act
208+ const result = await OrgPreferences . readDrVersion ( connection ) ;
209+
210+ // Assert
211+ expect ( result ) . to . be . false ;
212+ expect ( metadataReadStub . calledOnce ) . to . be . true ;
213+ } ) ;
214+ } ) ;
215+
64216 describe ( 'checkRollbackFlags' , ( ) => {
65217 it ( 'should return empty array when no flags are enabled' , async ( ) => {
66218 // Arrange
0 commit comments