@@ -31,7 +31,7 @@ import {
3131 SSLCertificateData ,
3232 Version ,
3333} from '@salesforce/lwc-dev-mobile-core' ;
34- import { AuthInfo , Connection , Logger , Messages , Org } from '@salesforce/core' ;
34+ import { AuthInfo , Connection , Logger , Messages } from '@salesforce/core' ;
3535import { PreviewUtils as LwcDevMobileCorePreviewUtils } from '@salesforce/lwc-dev-mobile-core' ;
3636import {
3737 ConfigUtils ,
@@ -331,163 +331,57 @@ describe('previewUtils', () => {
331331 expect ( generateWebSocketUrlStub . calledOnceWith ( platform , ports , { } as Logger ) ) . to . be . true ;
332332 } ) ;
333333
334- it ( 'initializePreviewConnection succeeds with valid org ' , async ( ) => {
334+ it ( 'initializePreviewConnection succeeds with valid connection ' , async ( ) => {
335335 const mockConnection = {
336336 getUsername : ( ) => testUsername ,
337- } ;
338- const getConnectionStub = $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ;
339- const mockOrg = {
340- getConnection : getConnectionStub ,
341- } as unknown as Org ;
342-
343- $$ . SANDBOX . stub ( OrgUtils , 'isLocalDevEnabled' ) . resolves ( true ) ;
344- $$ . SANDBOX . stub ( OrgUtils , 'ensureMatchingAPIVersion' ) . returns ( ) ;
345- $$ . SANDBOX . stub ( PreviewUtils , 'getOrCreateAppServerIdentity' ) . resolves ( testIdentityData ) ;
346-
347- const result = await PreviewUtils . initializePreviewConnection ( mockOrg ) ;
348-
349- expect ( result . ldpServerId ) . to . equal ( testLdpServerId ) ;
350- expect ( result . ldpServerToken ) . to . equal ( testLdpServerToken ) ;
351- expect ( result . connection ) . to . exist ;
352- expect ( getConnectionStub . calledWith ( undefined ) ) . to . be . true ;
353- } ) ;
354-
355- it ( 'initializePreviewConnection succeeds with valid org and apiVersion' , async ( ) => {
356- const testApiVersion = '67.0' ;
357- const mockConnection = {
358- getUsername : ( ) => testUsername ,
359- } ;
360- const getConnectionStub = $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ;
361- const mockOrg = {
362- getConnection : getConnectionStub ,
363- } as unknown as Org ;
337+ } as unknown as Connection ;
364338
365339 $$ . SANDBOX . stub ( OrgUtils , 'isLocalDevEnabled' ) . resolves ( true ) ;
366340 $$ . SANDBOX . stub ( OrgUtils , 'ensureMatchingAPIVersion' ) . returns ( ) ;
367341 $$ . SANDBOX . stub ( PreviewUtils , 'getOrCreateAppServerIdentity' ) . resolves ( testIdentityData ) ;
368342
369- const result = await PreviewUtils . initializePreviewConnection ( mockOrg , testApiVersion ) ;
343+ const result = await PreviewUtils . initializePreviewConnection ( mockConnection ) ;
370344
371345 expect ( result . ldpServerId ) . to . equal ( testLdpServerId ) ;
372346 expect ( result . ldpServerToken ) . to . equal ( testLdpServerToken ) ;
373- expect ( result . connection ) . to . exist ;
374- expect ( getConnectionStub . calledWith ( testApiVersion ) ) . to . be . true ;
347+ expect ( result . connection ) . to . equal ( mockConnection ) ;
375348 } ) ;
376349
377350 it ( 'initializePreviewConnection rejects when username is not found' , async ( ) => {
378351 const mockConnection = {
379352 getUsername : ( ) => undefined ,
380- } ;
381- const mockOrg = {
382- getConnection : $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ,
383- } as unknown as Org ;
384-
385- try {
386- await PreviewUtils . initializePreviewConnection ( mockOrg ) ;
387- expect . fail ( 'Should have thrown an error' ) ;
388- } catch ( error ) {
389- expect ( ( error as Error ) . message ) . to . include ( 'Org must have a valid user' ) ;
390- }
391- } ) ;
392-
393- it ( 'initializePreviewConnection rejects when username is not found with apiVersion' , async ( ) => {
394- const testApiVersion = '67.0' ;
395- const mockConnection = {
396- getUsername : ( ) => undefined ,
397- } ;
398- const getConnectionStub = $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ;
399- const mockOrg = {
400- getConnection : getConnectionStub ,
401- } as unknown as Org ;
353+ } as unknown as Connection ;
402354
403355 try {
404- await PreviewUtils . initializePreviewConnection ( mockOrg , testApiVersion ) ;
356+ await PreviewUtils . initializePreviewConnection ( mockConnection ) ;
405357 expect . fail ( 'Should have thrown an error' ) ;
406358 } catch ( error ) {
407359 expect ( ( error as Error ) . message ) . to . include ( 'Org must have a valid user' ) ;
408- expect ( getConnectionStub . calledWith ( testApiVersion ) ) . to . be . true ;
409360 }
410361 } ) ;
411362
412363 it ( 'initializePreviewConnection rejects when local dev is not enabled' , async ( ) => {
413364 const mockConnection = {
414365 getUsername : ( ) => testUsername ,
415- } ;
416- const mockOrg = {
417- getConnection : $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ,
418- } as unknown as Org ;
419-
420- $$ . SANDBOX . stub ( OrgUtils , 'ensureMatchingAPIVersion' ) . returns ( ) ;
421- $$ . SANDBOX . stub ( PreviewUtils , 'getOrCreateAppServerIdentity' ) . rejects (
422- new Error ( sharedMessages . getMessage ( 'error.localdev.not.enabled' ) )
423- ) ;
424-
425- try {
426- await PreviewUtils . initializePreviewConnection ( mockOrg ) ;
427- expect . fail ( 'Should have thrown an error' ) ;
428- } catch ( error ) {
429- expect ( ( error as Error ) . message ) . to . include ( 'Local Dev is not enabled' ) ;
430- }
431- } ) ;
432-
433- it ( 'initializePreviewConnection rejects when local dev is not enabled with apiVersion' , async ( ) => {
434- const testApiVersion = '67.0' ;
435- const mockConnection = {
436- getUsername : ( ) => testUsername ,
437- } ;
438- const getConnectionStub = $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ;
439- const mockOrg = {
440- getConnection : getConnectionStub ,
441- } as unknown as Org ;
366+ } as unknown as Connection ;
442367
443368 $$ . SANDBOX . stub ( OrgUtils , 'ensureMatchingAPIVersion' ) . returns ( ) ;
444369 $$ . SANDBOX . stub ( PreviewUtils , 'getOrCreateAppServerIdentity' ) . rejects (
445370 new Error ( sharedMessages . getMessage ( 'error.localdev.not.enabled' ) )
446371 ) ;
447372
448373 try {
449- await PreviewUtils . initializePreviewConnection ( mockOrg , testApiVersion ) ;
374+ await PreviewUtils . initializePreviewConnection ( mockConnection ) ;
450375 expect . fail ( 'Should have thrown an error' ) ;
451376 } catch ( error ) {
452377 expect ( ( error as Error ) . message ) . to . include ( 'Local Dev is not enabled' ) ;
453- expect ( getConnectionStub . calledWith ( testApiVersion ) ) . to . be . true ;
454378 }
455379 } ) ;
456380
457381 it ( 'initializePreviewConnection rejects when ldpServerId is not found' , async ( ) => {
458382 const mockConnection = {
459383 getUsername : ( ) => testUsername ,
460- } ;
461- const mockOrg = {
462- getConnection : $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ,
463- } as unknown as Org ;
464-
465- const identityDataWithoutEntityId = {
466- identityToken : testLdpServerToken ,
467- usernameToServerEntityIdMap : { } ,
468- } ;
469-
470- $$ . SANDBOX . stub ( OrgUtils , 'isLocalDevEnabled' ) . resolves ( true ) ;
471- $$ . SANDBOX . stub ( OrgUtils , 'ensureMatchingAPIVersion' ) . returns ( ) ;
472- $$ . SANDBOX . stub ( PreviewUtils , 'getOrCreateAppServerIdentity' ) . resolves ( identityDataWithoutEntityId ) ;
473-
474- try {
475- await PreviewUtils . initializePreviewConnection ( mockOrg ) ;
476- expect . fail ( 'Should have thrown an error' ) ;
477- } catch ( error ) {
478- expect ( ( error as Error ) . message ) . to . include ( 'entity ID' ) ;
479- }
480- } ) ;
481-
482- it ( 'initializePreviewConnection rejects when ldpServerId is not found with apiVersion' , async ( ) => {
483- const testApiVersion = '67.0' ;
484- const mockConnection = {
485- getUsername : ( ) => testUsername ,
486- } ;
487- const getConnectionStub = $$ . SANDBOX . stub ( ) . returns ( mockConnection ) ;
488- const mockOrg = {
489- getConnection : getConnectionStub ,
490- } as unknown as Org ;
384+ } as unknown as Connection ;
491385
492386 const identityDataWithoutEntityId = {
493387 identityToken : testLdpServerToken ,
@@ -499,11 +393,10 @@ describe('previewUtils', () => {
499393 $$ . SANDBOX . stub ( PreviewUtils , 'getOrCreateAppServerIdentity' ) . resolves ( identityDataWithoutEntityId ) ;
500394
501395 try {
502- await PreviewUtils . initializePreviewConnection ( mockOrg , testApiVersion ) ;
396+ await PreviewUtils . initializePreviewConnection ( mockConnection ) ;
503397 expect . fail ( 'Should have thrown an error' ) ;
504398 } catch ( error ) {
505399 expect ( ( error as Error ) . message ) . to . include ( 'entity ID' ) ;
506- expect ( getConnectionStub . calledWith ( testApiVersion ) ) . to . be . true ;
507400 }
508401 } ) ;
509402} ) ;
0 commit comments