SalesforceCommerceCloud / b2c-crm-sync

... a contemporary perspective on how to integrate B2C Commerce and the Salesforce Customer 360 Platform to power frictionless customer experiences in the B2C domain.
https://salesforcecommercecloud.github.io/b2c-crm-sync/
BSD 3-Clause "New" or "Revised" License
65 stars 45 forks source link

[BUG] ... #171

Open United22 opened 2 years ago

United22 commented 2 years ago

Describe the bug Step 2 "Exercise the B2C Commerce Unit Tests Execute the B2C Commerce unit-tests to verify that the B2C Commerce cartridge and OCAPI Hook code is trustworthy." fails with below error

To Reproduce Execute npm run crm-sync:test:b2c

Screenshots image

Your local environment details:

Your remote environment details:

Additional context After step 1 executes, step 2 gives some test class failures, and step 3 gives below error. image

gintoMathew commented 2 years ago

we are facing this exact same issue, although we are on the following versions -

Node version (node -v): v15.2.1 NPM version (npm -v): 7.0.8 SFDX version (sfdx -v): sfdx-cli/7.150.0 darwin-x64 node-v16.13.1

jbachelet commented 1 year ago

Hello,

(Please NEVER post credentials, either in text or screenshots)

Just tested on the latest version of the framework: v3.0.2. All working fine as you can see:

jbachelet@jbachel-ltmkcll ~/D/G/S/b2c-crm-sync (develop)> npm -v
8.1.2
jbachelet@jbachel-ltmkcll ~/D/G/S/b2c-crm-sync (develop)> node -v
v16.13.1
jbachelet@jbachel-ltmkcll ~/D/G/S/b2c-crm-sync (develop)> sfdx -v
 ›   Warning: sfdx-cli update available from 7.162.0 to 7.194.1.
sfdx-cli/7.162.0 darwin-x64 node-v16.16.0
jbachelet@jbachel-ltmkcll ~/D/G/S/b2c-crm-sync (develop)> npm run crm-sync:test:b2c

> b2c-crm-sync@3.0.2 crm-sync:test:b2c
> mocha "test/b2c/**/*.test.js"

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/customer.process
    loggedIn
      ✓ should not do anything in case no profile is sent as parameter
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the loggedIn-specific site preference is disabled
      ✓ should not do anything in case the profile has already been synched
      ✓ should fail to update the profile if no auth token is found, or an error occur, even if sync is enabled when the profile has already been synched
      ✓ should fail to update the profile if no auth token is found, or an error occur
      ✓ should call the rest service to process the profile and fail silently if the service replies an error
      ✓ should call the rest service to process the profile and fail silently if the service OK but contains errors
      ✓ should call the rest service to process the profile and update the profile custom attributes accordingly
    created
      ✓ should not do anything in case no profile is sent as parameter
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should fail to update the profile if no auth token is found, or an error occur
      ✓ should call the rest service to process the profile and fail silently if the service replies an error
      ✓ should call the rest service to process the profile and fail silently if the service OK but contains errors
      ✓ should call the rest service to process the profile and update the profile custom attributes accordingly
    updated
      ✓ should not do anything in case no profile is sent as parameter
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should fail to update the profile if no auth token is found, or an error occur
      ✓ should call the rest service to process the profile and fail silently if the service replies an error
      ✓ should call the rest service to process the profile and fail silently if the service OK but contains errors
      ✓ should call the rest service to process the profile and update the profile custom attributes accordingly
    synchronized
      ✓ should not do anything in case no profile is sent as parameter
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should fail to update the profile if no auth token is found, or an error occur
      ✓ should call the rest service to process the profile and fail silently if the service replies an error
      ✓ should call the rest service to process the profile and fail silently if the service OK but contains errors
      ✓ should call the rest service to process the profile and update the profile custom attributes accordingly

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/customer.retrieve
    retrieve
      ✓ should not do anything in case no profile is sent as parameter
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should fail to retrieve the profile if no auth token is found, or an error occur
      ✓ should fail to retrieve the profile if the object given in paremeters does not contain at least one required parameter
      ✓ should call the rest service to retrieve the profile and fail silently if the service replies an error
      ✓ should call the rest service to retrieve the profile and fail silently if the service OK but contains errors
      ✓ should call the rest service to retrieve the profile and abort because no profile have been found
      ✓ should call the rest service to retrieve the profile and update the profile custom attributes accordingly
      ✓ should call the rest service to retrieve the profile and update the profile custom attributes accordingly when sending an object as parameter

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/ocapi/shop.auth
    afterPOST
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the B2C CRM Sync site hook is not present in the codebase
      ✓ should not do anything in case the customer is not authenticated
      ✓ should call the HookMgr if the preference is enabled and the customer is authenticated

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/ocapi/shop.customer
    afterPOST
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the B2C CRM Sync site hook is not present in the codebase
      ✓ should not do anything in case the customer is not authenticated
      ✓ should call the HookMgr if the preference is enabled and the customer is authenticated
    afterPATCH
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the B2C CRM Sync site hook is not present in the codebase
      ✓ should not do anything in case the customer is not authenticated
      ✓ should call the HookMgr if the preference is enabled and the customer is authenticated
    modifyGETResponse
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the B2C CRM Sync site preference is enabled but the custom expand GET parameter is missing
      ✓ should call the PromotionMgr if the preference is enabled and the GET param is passed, but return no promotions
      ✓ should provide promotions if the customer is eligible to promotions

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/ocapi/shop.order
    afterPOST
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the B2C CRM Sync site hook is not present in the codebase
      ✓ should call the HookMgr if the preference is enabled

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/ocapi/shop.promotion
    modifyGETResponse
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the B2C CRM Sync site preference is enabled but the custom expand GET parameter is missing
      ✓ should try to add coupons if the preference is enabled and the GET param is passed, but return no coupons as the promotion is not based on coupons
      ✓ should provide coupon IDs if the customer is eligible to promotions based on coupons

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/order.process
    created
      ✓ should not do anything in case no order is sent as parameter
      ✓ should not do anything in case the b2c-crm-sync site preference is disabled
      ✓ should not do anything in case the b2c-crm-sync guest-orders site preference is disabled and the order is a guest-order
      ✓ should not do anything in case the b2c-crm-sync PlatformID site preference is disabled and the order is a registered-order
      ✓ should fail to update the order if no auth token is found, or an error occur
      ✓ should call the rest service to process the guest-order and fail silently if the service replies an error
      ✓ should call the rest service to process the guest-order and fail silently if the service OK but contains errors
      ✓ should call the rest service to process the guest-order and update the order's custom attributes accordingly
      ✓ should call the rest service to process the registered-order and update the order's custom attributes accordingly

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/models/authToken
    getValidToken
      ✓ should return a token object if found in the cache and the token is still valid
      ✓ should throw an error saying no valid token exist when nothing is found in the cache and the service fails
      ✓ should throw an error saying no valid token exist when the token from the cache is expired
      ✓ should call the service if the cached value is undefined

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/models/customer
    getRequestBody
      ✓ should return a stringified body of the given profil details passed in parameters, when the model does no hold a profile
      ✓ should return a stringified body of the given profil details passed in parameters, even if the model holds a profile
      ✓ should return a stringified body of the profile data sent within the model
      ✓ should return a stringified body of the profile data sent within the model, but without accountId nor contactId in case of first attempt
      ✓ should return an empty input body when no profile is given to the model
    updateStatus
      ✓ should save the given data into the profile custom attribute
      ✓ should not do anything in case no profile is sent within the model
    updateExternalId
      ✓ should save the given data into the profile custom attributes
      ✓ should only save the account ID into the profile custom attribute
      ✓ should only save the contact ID into the profile custom attribute
      ✓ should not do anything in case no profile is sent within the model
    updateSyncResponseText
      ✓ should save response text in the profile custom attribute if this is the first time the response text is saved and so the custom attribute is undefined
      ✓ should save response text in the profile custom attribute if this is the first time the response text is saved
      ✓ should save response text in the profile custom attribute, even if we already saved response texts previously
      ✓ should save response text in the profile custom attribute, and remove the first element of the array as the limit is reached
      ✓ should not do anything in case no profile is sent within the model

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/models/order
    getRequestBody
      ✓ should return a stringified body of the order data sent within the model
      ✓ should return a stringified body of the order data sent within the model, but without accountId nor contactId in case of first attempt
      ✓ should return undefined when no order is given to the model
    updateStatus
      ✓ should save the given data into the order custom attribute
      ✓ should not do anything in case no order is sent within the model
    updateExternalId
      ✓ should save the given data into the order custom attributes
      ✓ should only save the account ID into the order custom attribute
      ✓ should only save the contact ID into the order custom attribute
      ✓ should not do anything in case no order is sent within the model
    updateSyncResponseText
      ✓ should save response text in the order custom attribute if this is the first time the response text is saved and so the custom attribute is undefined
      ✓ should save response text in the order custom attribute if this is the first time the response text is saved
      ✓ should save response text in the order custom attribute, even if we already saved response texts previously
      ✓ should save response text in the order custom attribute, and remove the first element of the array as the limit is reached
      ✓ should not do anything in case no order is sent within the model

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/services/rest
    getServiceCallback
      ✓ should throw an error if no model is sent within the method
      ✓ should throw an error if no operation is sent within the method
      ✓ should throw an error if the given model and operation sent within the method are not valid (not present within the configuration)
      ✓ should return a service callback object when trying to get the customer retrieve service callback
      ✓ should return a service callback object when trying to get the customer process service callback

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/services/ServiceMgr
    getAuthService
      ✓ should return an instance of the LocaleServiceRegistry for the auth service
      ✓ should execute the service call
      ✓ should execute the mockFull method of the service, and so return the mock as result
    callRestService
      ✓ should throw an error if no model is sent within the method
      ✓ should throw an error if no state is sent within the method
      ✓ should throw an error if the given model and state sent within the method are not valid (not present within the configuration)
      ✓ should throw an error as their is no auth token retrieved for the retrieve customer call
      ✓ should throw an error as their is no auth token retrieved for the process customer call
      ✓ should execute the service call to retrieve the customer by using a valid Auth token
      ✓ should execute the service call to process the customer by using a valid Auth token
      ✓ should execute the mockFull method of the retrieve service, and so return the mock as result
      ✓ should execute the mockFull method of the process service, and so return the mock as result

  int_b2ccrmsync/cartridge/scripts/b2ccrmsync/util/helpers
    expandJSON
      ✓ should parse the given string into a valid object
      ✓ should parse the given string into a valid object and return it even if we provide a default value
      ✓ should fail in case we don't provide a string as first parameter, and so return an undefined object
      ✓ should fail in case we don't provide a string as first parameter, and so return the default object
      ✓ should fail to parse the object, and so return undefined as no default value is provided
      ✓ should fail to parse the object, and so return the provided default value
    isIntegrationEnabled
      ✓ should be enabled if both preferences are enabled
      ✓ should be disabled if the b2ccrm_syncIsEnabled preference is disabled
      ✓ should be disabled if the b2ccrm_syncCustomersEnabled preference is disabled
      ✓ should be disabled if both preferences are disabled
    sfdcContactIDIdentifierPresent
      ✓ should return false if the profile is undefined
      ✓ should return false if the profile is null
      ✓ should return false if the profile has no b2ccrm_contactId custom property
      ✓ should return false if the profile's b2ccrm_contactId custom property is undefined
      ✓ should return false if the profile's b2ccrm_contactId custom property is null
      ✓ should return false if the profile's b2ccrm_contactId custom property is an empty string
      ✓ should return true if the profile's b2ccrm_contactId custom property exists

  plugin_b2ccrmsync/cartridge/scripts/b2ccrmsync/hooks/ocapi/shop.customer.passwordReset
    afterPOST
      ✓ should not do anything in case the B2C CRM Sync site preference is disabled
      ✓ should not do anything in case the customer has no profile
      ✓ should call the agent helper and send the email to the customer if the preference is enabled and the customer has a profile

  139 passing (988ms)

jbachelet@jbachel-ltmkcll ~/D/G/S/b2c-crm-sync (develop)> npm run crm-sync:b2c:verify

> b2c-crm-sync@3.0.2 crm-sync:b2c:verify
> node cli.js crm-sync:b2c:verify

----------------------------------------------------------------------------
 CRM-SYNC | v3.0.2 | crm-sync:b2c:verify: START
----------------------------------------------------------------------------
 -- Attempting to verify the B2C environment using the following environment details
┌──────────────────────────────┬──────────┬─────────────────────────────────────────────────────────────────────────────┐
│           Env. Property Name │ Is Valid │ Configured Property Value                                                   │
├──────────────────────────────┼──────────┼─────────────────────────────────────────────────────────────────────────────┤
│                  b2cHostName │   true   │ XXXX.dx.commercecloud.salesforce.com                                    │
├──────────────────────────────┼──────────┼─────────────────────────────────────────────────────────────────────────────┤
│                  b2cClientId │   true   │ 25c65b97-XXXX-XXXX-XXXX-XXXX                                        │
├──────────────────────────────┼──────────┼─────────────────────────────────────────────────────────────────────────────┤
│              b2cClientSecret │   true   │ XXXXXXXXXXXX                                                       │
├──────────────────────────────┼──────────┼─────────────────────────────────────────────────────────────────────────────┤
│               b2cCodeVersion │   true   │ SFRA_AP_05_04_2021                                                          │
├──────────────────────────────┼──────────┼─────────────────────────────────────────────────────────────────────────────┤
│                   b2cSiteIds │   true   │ RefArch                                                                     │
├──────────────────────────────┼──────────┼─────────────────────────────────────────────────────────────────────────────┤
│              b2cInstanceName │   true   │ XXXX                                                                     │
└──────────────────────────────┴──────────┴─────────────────────────────────────────────────────────────────────────────┘
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ B2C Commerce Authentication Token                                                                                     │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ eyJ0eXAiOiJKV1QiLCJraWQiOiJEMWhPUDdEODN4TjBqZWlqaTI3WWFvZFRjL0E9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyNWM2NWI5Ny1lZTcxL… │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
 -- Sites verification details - successfully verified these sites
┌─────────────────────────┬──────────┬────────────────────┬─────────────────────────────────────────────────────────────┐
│         Site Identifier │  Status  │     Storefront     │ Site URL                                                    │
├─────────────────────────┼──────────┼────────────────────┼─────────────────────────────────────────────────────────────┤
│                 RefArch │   200    │       online       │ /s/-/dw/data/v21_3/sites/RefArch                            │
└─────────────────────────┴──────────┴────────────────────┴─────────────────────────────────────────────────────────────┘
 -- Code version verification details
┌─────────────────────────┬──────────┬────────────────────┬──────────┬──────────────────────────────────────────────────┐
│                      Id │  Active  │   Last Modified    │  CMode   │ WebDAV Url                                       │
├─────────────────────────┼──────────┼────────────────────┼──────────┼──────────────────────────────────────────────────┤
│      SFRA_AP_05_04_2021 │   true   │ 05/02/23 12:05:00  │   21.7   │ /webdav/Sites/Cartridges/SFRA_AP_05_04_2021      │
└─────────────────────────┴──────────┴────────────────────┴──────────┴──────────────────────────────────────────────────┘

  ,--------------------------------------------------------------------------------------------------.
  |                                                                                                  |
  |   ▄▄▄▄▄▄▄▄▄▄▄  ▄         ▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄   |
  |  ▐░░░░░░░░░░░▌▐░▌       ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌  |
  |  ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌       ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌  |
  |  ▐░▌          ▐░▌       ▐░▌▐░▌          ▐░▌          ▐░▌          ▐░▌          ▐░▌          ▐░▌  |
  |  ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌       ▐░▌▐░▌          ▐░▌          ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌  |
  |  ▐░░░░░░░░░░░▌▐░▌       ▐░▌▐░▌          ▐░▌          ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌  |
  |   ▀▀▀▀▀▀▀▀▀█░▌▐░▌       ▐░▌▐░▌          ▐░▌          ▐░█▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀█░▌ ▀▀▀▀▀▀▀▀▀█░▌▐░▌  |
  |            ▐░▌▐░▌       ▐░▌▐░▌          ▐░▌          ▐░▌                    ▐░▌          ▐░▌ ▀   |
  |   ▄▄▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄█░▌ ▄▄▄▄▄▄▄▄▄█░▌ ▄   |
  |  ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌  |
  |   ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀   |
  |                                                                                                  |
  |                                                                                                  |
  |                                     - Brought to You by the Full Power of Salesforce Architects  |
  |                                                 Architect Success, SCPPE, Services, & Alliances  |
  |                                                                                                  |
  |                                                                                                  |
  `--------------------------------------------------------------------------------------------------'

----------------------------------------------------------------------------
 CRM-SYNC | v3.0.2 | crm-sync:b2c:verify: END
----------------------------------------------------------------------------