unit-testingpalantir-foundrypalantir-foundry-api

Handling decimal-fields of mocked ontology-objects in unit-tests


I am trying to write unit tests for a typescript function repo in foundry. According to the palantir-foundry documentation, I'd like to use Objects.create() to mock objects for my tests and whenObjectSet(objectSetOperation).thenReturn(objects) for injection.

However, setting decimal fields of mocked objects in my tests results in the exception:

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^
[...]
SafeError: Setting property type is not supported.
args: [
    {
      type: 'UNSAFE',
      name: 'type',
      value: '{"version":2,"propertyTypeId":"confirmed_quantity_menge","type":{"type":"decimal"}}'
    }
  ],
  type: 'UserCausedError',
  errorInstanceId: 'd4e336a8-791b-48e3-8ea8-feb5405ace53',
  result: {
    runtimeError: {
      message: 'Setting property type is not supported.',
      stacktrace: 'SafeError: Setting property type is not supported.\n' +
        '    at UserCausedError.SafeError [as constructor] (/scratch/standalone/53c47a40-195f-4d78-9e75-53ee67c1e813/code-assist/contents/functions-typescript/node_modules/@foundry/witchcraft-logging-api/src/args/safeError.ts:26:9)\n' +
        '    at new UserCausedError (/scratch/standalone/53c47a40-195f-4d78-9e75-53ee67c1e813/code-assist/contents/functions-typescript/node_modules/@foundry/functions-typescript-runtime-isolate-api/src/UserCausedError.ts:19:5)\n' +
        '    at Object.settingPropertyTypeNotSupported (/scratch/standalone/53c47a40-195f-4d78-9e75-53ee67c1e813/code-assist/contents/functions-typescript/node_modules/@foundry/functions-typescript-runtime-storage/src/Errors.ts:81:12)\n' +
        '    at ObjectPropertyStore.throwIfSettingPropertyTypeUnsupported (/scratch/standalone/53c47a40-195f-4d78-9e75-53ee67c1e813/code-assist/contents/functions-typescript/node_modules/@foundry/functions-typescript-runtime-storage/src/properties/ObjectPropertyStore.ts:63:22)\n' +
        '    at ObjectPropertyStore.set (/scratch/standalone/53c47a40-195f-4d78-9e75-53ee67c1e813/code-assist/contents/functions-typescript/node_modules/@foundry/functions-typescript-runtime-storage/src/properties/ObjectPropertyStore.ts:26:14)\n' +
        '    at AnnotatingObjectStorageProvider.setPropertyValue (/scratch/standalone/53c47a40-195f-4d78-9e75-53ee67c1e813/code-assist/contents/functions-typescript/node_modules/@foundry/functions-typescript-runtime-storage/src/DefaultObjectStorageProvider.ts:39:28)\n
[...]
      parameters: {
        type: '{"version":2,"propertyTypeId":"confirmed_quantity_menge","type":{"type":"decimal"}}'
      }
    },
    type: 'runtimeError'
  }
}

In the foundry documentation I found the following information regarding the decimal type:

decimal: Properties of this type cannot be used within action types as the precision cannot be guaranteed when updating this data type due to the conversion between JSON and Java. This type is also not supported in Object Storage V2.

However, I feel like this restriction really should not apply when it comes unit-testing (after all we are only talking about mocked data in this context). Does someone know a workaround for that problem without having to change the property type (and thus the ontology)?


Solution

  • The unit testing for functions and actions on objects runs within the same runtime framework in which a published function would run in production. At the moment, there aren't any alternative runtimes available for unit tests that would have an alternative set of checks to allow you to bypass this.