SAP / open-ux-odata

Enable community collaboration to jointly promote and facilitate best in class framework and tooling capabilities when working with OData services.
Apache License 2.0
51 stars 10 forks source link

BUG - @sap-ux/ui5-middleware-fe-mockserver - executeAction gets called for navigation Properties #633

Closed pwasem closed 1 year ago

pwasem commented 1 year ago

with latest version 2.1.102 (or at least >= 2.1.89) the executeAction hook gets called not only for actions but also for navigationProperties.

E.g. consider the following webapp/localService/mockdata/ServiceRequests.js:

const { getLogger } = require('@ui5/logger');

const logger = getLogger('localService:mockdata:ServiceRequests');

const unsubscribe = async (base, { ID }) => {
  const serviceRequestsInterface = await base.getEntityInterface('ServiceRequests');

  const [serviceRequest] = await serviceRequestsInterface.fetchEntries({ ID });
  serviceRequest.status_code = 'Unsubscribed';

  await serviceRequestsInterface.updateEntry({ ID }, serviceRequest);
};

module.exports = {
  // https://github.com/SAP/open-ux-odata/blob/main/docs/EntityContainerAPI.md#executeaction
  async executeAction({ name }, actionData, { ID }) {
    try {
      logger.info('Executing action: %s with action data: %j', name, actionData, { ID });

      let response = null;

      switch (name) {
        case 'unsubscribe':
          response = await unsubscribe(this.base, { ID });
          break;
        default:
          logger.warn(`Unhandled action: ${name}`);
      }

      return response;
    } catch (error) {
      const { message } = error;
      logger.error('Error executing action: %s with action data: %j - %s', name, actionData, message);
      throw error;
    }
  },
};

Will lead to the following logs:

info localService:mockdata:ServiceRequests Executing action: serviceResults with action data: {"":"00000011-0000-0000-0000-000000000001"} { ID: '00000010-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceRequests Unhandled action: serviceResults
info localService:mockdata:ServiceResults Executing action: processingLogs with action data: {} { ID: '00000011-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceResults Unhandled action: processingLogs
info localService:mockdata:ServiceResults Executing action: errors with action data: {} { ID: '00000011-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceResults Unhandled action: errors
info localService:mockdata:ServiceRequests Executing action: serviceResults with action data: {"":"00000011-0000-0000-0000-000000000001"} { ID: '00000010-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceRequests Unhandled action: serviceResults
info localService:mockdata:ServiceRequests Executing action: serviceResults with action data: {} { ID: '00000010-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceRequests Unhandled action: serviceResults
info localService:mockdata:ServiceResults Executing action: processResult with action data: {"overwrite":true} { ID: '00000011-0000-0000-0000-000000000001' }
info localService:mockdata:ServiceRequests Executing action: serviceResults with action data: {} { ID: '00000010-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceRequests Unhandled action: serviceResults
info localService:mockdata:ServiceResults Executing action: processingLogs with action data: {} { ID: '00000011-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceResults Unhandled action: processingLogs
info localService:mockdata:ServiceRequests Executing action: serviceResults with action data: {"":"00000011-0000-0000-0000-000000000001"} { ID: '00000010-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceRequests Unhandled action: serviceResults
info localService:mockdata:ServiceResults Executing action: errors with action data: {} { ID: '00000011-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceResults Unhandled action: errors
info localService:mockdata:ServiceResults Executing action: processingLogs with action data: {} { ID: '00000011-0000-0000-0000-000000000001' }
WARN localService:mockdata:ServiceResults Unhandled action: processingLogs
nlunets commented 1 year ago

I see, that is unfortunate, at least it doesn't break anything except for the too lenient call usage. Will prepare a fix

nlunets commented 1 year ago

Fixed in version 2.1.104