@@ -21,76 +21,6 @@ const crypto = require('crypto');
2121// eslint-disable-next-line node/no-unpublished-require
2222const nock = require ( 'nock' ) ;
2323
24- describe ( 'getAdobeCommerceClient' , ( ) => {
25- beforeEach ( ( ) => {
26- jest . clearAllMocks ( ) ;
27- } ) ;
28-
29- describe ( 'getAdobeCommerceClient' , ( ) => {
30- const sharedParams = {
31- COMMERCE_BASE_URL : 'http://mycommerce.com' ,
32- LOG_LEVEL : 'debug' ,
33- } ;
34- test ( 'with IMS auth' , async ( ) => {
35- const params = {
36- ...sharedParams ,
37- OAUTH_CLIENT_ID : 'test-client-id' ,
38- OAUTH_CLIENT_SECRETS : JSON . stringify ( [ 'supersecret' ] ) ,
39- OAUTH_TECHNICAL_ACCOUNT_ID : 'test-technical-account-id' ,
40- OAUTH_TECHNICAL_ACCOUNT_EMAIL :
'[email protected] ' , 41- OAUTH_IMS_ORG_ID : 'test-org-id' ,
42- OAUTH_SCOPES : JSON . stringify ( [ 'scope1' , 'scope2' ] ) ,
43- } ;
44- getToken . mockResolvedValue ( 'supersecrettoken' ) ;
45- const scope = nock ( params . COMMERCE_BASE_URL )
46- . get ( '/V1/testauth' )
47- . matchHeader ( 'Content-Type' , 'application/json' )
48- . matchHeader ( 'x-ims-org-id' , params . OAUTH_IMS_ORG_ID )
49- . matchHeader ( 'x-api-key' , params . OAUTH_CLIENT_ID )
50- . matchHeader ( 'Authorization' , 'Bearer supersecrettoken' )
51- . reply ( 200 ) ;
52-
53- const client = await getAdobeCommerceClient ( params ) ;
54- expect ( getToken ) . toHaveBeenCalled ( ) ;
55-
56- const { success } = await client . get ( 'testauth' ) ;
57- expect ( success ) . toBeTruthy ( ) ;
58- scope . done ( ) ;
59- } ) ;
60-
61- test ( 'with Commerce integration auth' , async ( ) => {
62- const params = {
63- ...sharedParams ,
64- COMMERCE_CONSUMER_KEY : 'test-consumer-key' ,
65- COMMERCE_CONSUMER_SECRET : 'test-consumer-secret' ,
66- COMMERCE_ACCESS_TOKEN : 'test-access-token' ,
67- COMMERCE_ACCESS_TOKEN_SECRET : 'test-access-token-secret' ,
68- } ;
69-
70- const scope = nock ( params . COMMERCE_BASE_URL )
71- . get ( '/V1/testauth' )
72- . matchHeader ( 'Content-Type' , 'application/json' )
73- . matchHeader (
74- 'Authorization' ,
75- / ^ O A u t h o a u t h _ c o n s u m e r _ k e y = " t e s t - c o n s u m e r - k e y " , o a u t h _ n o n c e = " [ ^ " ] + " , o a u t h _ s i g n a t u r e = " [ ^ " ] + " , o a u t h _ s i g n a t u r e _ m e t h o d = " H M A C - S H A 2 5 6 " , o a u t h _ t i m e s t a m p = " [ ^ " ] + " , o a u t h _ t o k e n = " t e s t - a c c e s s - t o k e n " , o a u t h _ v e r s i o n = " 1 \. 0 " $ /
76- )
77- . reply ( 200 ) ;
78-
79- const client = await getAdobeCommerceClient ( params ) ;
80-
81- const { success } = await client . get ( 'testauth' ) ;
82- expect ( success ) . toBeTruthy ( ) ;
83- scope . done ( ) ;
84- } ) ;
85-
86- test ( 'throws when missing auth method' , async ( ) => {
87- await expect ( getAdobeCommerceClient ( sharedParams ) ) . rejects . toThrow (
88- "Can't resolve authentication options for the given params."
89- ) ;
90- } ) ;
91- } ) ;
92- } ) ;
93-
9424describe ( 'webhookVerify' , ( ) => {
9525 const { publicKey, privateKey } = crypto . generateKeyPairSync ( 'rsa' , { modulusLength : 512 } ) ;
9626 const body = JSON . stringify ( { test : 'data' } ) ;
0 commit comments