@@ -416,19 +416,14 @@ describe('Guest user flow', () => {
416416 expect . stringContaining ( 'Invalid Parameter for authorizeCustomer: hello' )
417417 ) ;
418418
419- expect ( getAccessTokenMock ) . toBeCalledWith ( {
420- ...expectedTokenBody ,
421- parameters : {
422- hello : 'world' ,
423- } ,
424- } ) ;
419+ expect ( getAccessTokenMock ) . toBeCalledWith ( expectedTokenBody ) ;
425420 expect ( accessToken ) . toBe ( expectedTokenResponse ) ;
426421
427422 // Restore the original console.warn
428423 consoleWarnSpy . mockRestore ( ) ;
429424 } ) ;
430425
431- test ( 'can pass custom params, headers on public guest' , async ( ) => {
426+ test ( 'can pass custom params on public guest' , async ( ) => {
432427 const expectedTokenBody = {
433428 body : {
434429 client_id : 'client_id' ,
@@ -440,12 +435,6 @@ describe('Guest user flow', () => {
440435 usid : '048adcfb-aa93-4978-be9e-09cb569fdcb9' ,
441436 dnt : 'false' ,
442437 } ,
443- headers : {
444- c_headers : 'custom header' ,
445- } ,
446- parameters : {
447- c_color : 'red' ,
448- } ,
449438 } ;
450439 const mockSlasClient = createMockSlasClient ( ) ;
451440 const { shortCode, organizationId} = mockSlasClient . clientConfig . parameters ;
@@ -454,39 +443,26 @@ describe('Guest user flow', () => {
454443 nock ( `https://${ shortCode } .api.commercecloud.salesforce.com` )
455444 . get ( `/shopper/auth/v1/organizations/${ organizationId } /oauth2/authorize` )
456445 . query ( query => query . c_color === 'red' )
457- . matchHeader ( 'c_headers' , 'custom header' ) // Verify the custom header is included
458446 . reply ( 303 , { response_body : 'response_body' } , { location : url } ) ;
459447
460- const accessToken = await slasHelper . loginGuestUser (
461- mockSlasClient ,
462- {
463- redirectURI : parameters . redirectURI ,
464- dnt : false ,
465- c_color : 'red' ,
466- } ,
467- {
468- headers : {
469- c_headers : 'custom header' ,
470- } ,
471- }
472- ) ;
448+ const accessToken = await slasHelper . loginGuestUser ( mockSlasClient , {
449+ redirectURI : parameters . redirectURI ,
450+ dnt : false ,
451+ c_color : 'red' ,
452+ } ) ;
473453
474454 // Verify getAccessToken was called with the right parameters,
475455 // including custom headers and parameters
476456 expect ( getAccessTokenMock ) . toBeCalledWith ( expectedTokenBody ) ;
477457 expect ( accessToken ) . toBe ( expectedTokenResponse ) ;
478458 } ) ;
479459
480- test ( 'generates an access token using slas private client (with a custom params) ' , async ( ) => {
460+ test ( 'generates an access token using slas private client' , async ( ) => {
481461 const mockSlasClient = createMockSlasClient ( ) ;
482462
483463 const accessToken = await slasHelper . loginGuestUserPrivate (
484464 mockSlasClient ,
485- {
486- usid : parameters . usid ,
487- dnt : false ,
488- c_color : 'red' ,
489- } ,
465+ parameters ,
490466 credentialsPrivate
491467 ) ;
492468
@@ -502,9 +478,6 @@ describe('Guest user flow', () => {
502478 usid : 'usid' ,
503479 dnt : 'false' ,
504480 } ,
505- parameters : {
506- c_color : 'red' ,
507- } ,
508481 } ;
509482 expect ( getAccessTokenMock ) . toBeCalledWith ( expectedReqOptions ) ;
510483 expect ( accessToken ) . toBe ( expectedTokenResponse ) ;
@@ -576,7 +549,7 @@ describe('Registered B2C user flow', () => {
576549 expect ( getAccessTokenMock ) . toBeCalledWith ( expectedTokenBody ) ;
577550 } ) ;
578551
579- test ( 'can pass custom parameters, headers and body field, and throw warning for invalid params' , async ( ) => {
552+ test ( 'can pass custom body field, and throw warning for invalid params' , async ( ) => {
580553 const consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
581554
582555 // slasClient is copied and tries to make an actual API call
@@ -585,9 +558,7 @@ describe('Registered B2C user flow', () => {
585558
586559 // // Mocking slasCopy.authenticateCustomer
587560 nock ( `https://${ shortCode } .api.commercecloud.salesforce.com` )
588- . post (
589- `/shopper/auth/v1/organizations/${ organizationId } /oauth2/login?c_color=red`
590- )
561+ . post ( `/shopper/auth/v1/organizations/${ organizationId } /oauth2/login` )
591562 . reply ( ( uri , requestBody ) => {
592563 expect ( requestBody ) . toMatch ( / c _ b o d y = t e s t / i) ;
593564 return [ 303 , { response_body : 'response_body' } , { location : url } ] ;
@@ -599,13 +570,11 @@ describe('Registered B2C user flow', () => {
599570 {
600571 redirectURI : 'redirect_uri' ,
601572 dnt : false ,
602- c_color : 'red' ,
603573 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
604574 // @ts -ignore intentionally passing invalid param
605575 invalid_param : 'invalid param' ,
606576 } ,
607577 {
608- headers : { c_header : 'test' } ,
609578 body : {
610579 redirect_uri : 'redirect_uri' ,
611580 c_body : 'test' ,
@@ -618,11 +587,7 @@ describe('Registered B2C user flow', () => {
618587 'Invalid Parameter for authenticateCustomer: invalid_param'
619588 )
620589 ) ;
621- expect ( getAccessTokenMock ) . toBeCalledWith ( {
622- ...expectedTokenBody ,
623- headers : { c_header : 'test' } ,
624- parameters : { c_color : 'red' , invalid_param : 'invalid param' } ,
625- } ) ;
590+ expect ( getAccessTokenMock ) . toBeCalledWith ( expectedTokenBody ) ;
626591 // Restore the original console.warn
627592 consoleWarnSpy . mockRestore ( ) ;
628593 } ) ;
@@ -944,23 +909,20 @@ describe('getPasswordLessAccessToken is working', () => {
944909
945910describe ( 'Refresh Token' , ( ) => {
946911 test ( 'refreshes the token with slas public client' , ( ) => {
947- const expectedOptions = {
912+ const expectedBody = {
948913 body : {
949914 client_id : 'client_id' ,
950915 channel_id : 'site_id' ,
951916 grant_type : 'refresh_token' ,
952917 refresh_token : 'refresh_token' ,
953918 dnt : 'false' ,
954919 } ,
955- parameters : {
956- refreshToken : parameters . refreshToken ,
957- } ,
958920 } ;
959- const token = slasHelper . refreshAccessToken ( createMockSlasClient ( ) , {
960- refreshToken : parameters . refreshToken ,
961- dnt : parameters . dnt ,
962- } ) ;
963- expect ( getAccessTokenMock ) . toBeCalledWith ( expectedOptions ) ;
921+ const token = slasHelper . refreshAccessToken (
922+ createMockSlasClient ( ) ,
923+ parameters
924+ ) ;
925+ expect ( getAccessTokenMock ) . toBeCalledWith ( expectedBody ) ;
964926 expect ( token ) . toStrictEqual ( expectedTokenResponse ) ;
965927 } ) ;
966928
@@ -978,13 +940,6 @@ describe('Refresh Token', () => {
978940 refresh_token : parameters . refreshToken ,
979941 dnt : 'false' ,
980942 } ,
981- parameters : {
982- accessToken : 'access_token' ,
983- hint : 'hint' ,
984- redirectURI : 'redirect_uri' ,
985- refreshToken : 'refresh_token' ,
986- usid : 'usid' ,
987- } ,
988943 } ;
989944 const token = slasHelper . refreshAccessToken (
990945 createMockSlasClient ( ) ,
@@ -1011,10 +966,7 @@ describe('Logout', () => {
1011966 } ;
1012967
1013968 test ( 'logs out the customer' , ( ) => {
1014- const token = slasHelper . logout ( createMockSlasClient ( ) , {
1015- accessToken : 'access_token' ,
1016- refreshToken : 'refresh_token' ,
1017- } ) ;
969+ const token = slasHelper . logout ( createMockSlasClient ( ) , parameters ) ;
1018970 expect ( logoutCustomerMock ) . toBeCalledWith ( expectedOptions ) ;
1019971 expect ( token ) . toStrictEqual ( expectedTokenResponse ) ;
1020972 } ) ;
0 commit comments