run-crank/cog-salesforce

Add operators to all field check steps

Closed this issue · 0 comments

Problem / Motivation

Currently, field check steps on all objects are limited to simply evaluating equality; it's not possible to make any other assertions about the state of records/objects in the system. This is especially problematic on date fields.

In order to support more test cases, we should add an operator field to all field check steps.
In particular, we should support the following operators:be, not be, contain, not contain, be greater than, be less than

Scope / UAT Target

The following should hold true for all currently supported Salesforce Objects:

  • account
  • campaign member
  • contact
  • lead
  • opportunity

  • There should be an operator field (type string) listed between the field and expectedValue fields.
  • The operator field should be marked optional (for backward compatibility)
  • The operator field description should read Check Logic (be, not be, contain, not contain, be greater than, or be less than)
  • The step text should be modified so that should be is replaced with should (?<operator>be less than|be greater than|be|contain|not be|not contain)
  • Field check evaluation logic should follow the following guidelines:
    • be should map to what happens currently (==)
    • not be should map to !=
    • contain should cast both values to string can call .includes()
    • not contain should cast both values to string and call ! .includes()
    • be greater than should map to >
      • For values which conform to a date (e.g. YYYY-MM-DD format), values should be converted to moment.js dates and compared using Moment().isBefore() or .isAfter()
      • For values which conform to a datetime (e.g. YYYY-MM-DDTHH:mm:ss), values should be converted to moment.js dates and compared using .isBefore() or isAfter()
      • For numeric values, if necessary, both values should be cast to numbers (could be int or float) before comparison
      • If either value is non-numeric or does not map to a date or datetime format, an error should be thrown.
  • If a step is executed with no operator value, it should assume the logic for be (==)

Proposed Resolution

We may want to centralize field comparison logic in a method on the BaseStep so that any step could just call this.compare(operator, field, value)


Sample UAT scenarios:

scenario: Backwards Compatibility Test
description: Proves that field check steps can still be run without an operator provided.

tokens:
  test.email: lead-operator-bc@automatoninc.com
  test.name: Atoma

steps:
- step: create a salesforce lead
  data:
    lead:
      Email: '{{test.email}}'
      FirstName: '{{test.name}}'
- cog: automatoninc/salesforce
  stepId: LeadFieldEquals
  data:
    email: '{{test.email}}'
    field: FirstName
    expectedValue: '{{test.name}}'
    # Note: operator is ommitted.
- step: delete the {{test.email}} salesforce lead