---
policy: /ce/unit-test/is-empty/date-time
logic: /ce/unit-test/is-empty/date-time/unit-test.logic.yaml
executionTime: 2025-04-24T23:47:55.388269373Z
rows:
  - id: Test-1
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: "unitTest(Test-1): '2000-01-01T00:00:00Z'.isNotEmpty()"
      actual: "unitTest(Test-1): '2000-01-01T00:00:00Z'.isNotEmpty()"
    runtimeError: {}
  - id: Test-2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: "unitTest(Test-2): '1970-01-01T00:00:00Z'.isNotEmpty()"
      actual: "unitTest(Test-2): '1970-01-01T00:00:00Z'.isNotEmpty()"
    runtimeError: {}
  - id: Test-3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: "unitTest(Test-3): null.isEmpty()"
      actual: "unitTest(Test-3): null.isEmpty()"
    runtimeError: {}
usedFiles:
  - path: /ce/unit-test/is-empty/date-time/policy.yaml
    md5Hash: EA71B704EE1D775FC4B7DB8902FF05C5
    content: |-
      ---
      names:
        full: "IS_EMPTY / NOT_EMPTY Unit Tests: DateTimeType"
        contextual: "DateTimeType"
      description: ""
  - path: /ce/unit-test/is-empty/date-time/unit-test.logic.yaml
    md5Hash: 2F05A42D29EABC9EE2143045A3B266C0
    content: |-
      ---
      inputType: CA10__CaAwsInstance__c
      testData:
        - file: test-data.json
      conditions:
        - status: COMPLIANT
          currentStateMessage: Test-1
          check:
            UNIT_TEST:
              id: Test-1
              arg:
                NOT_EMPTY:
                  arg:
                    DATE_TIME: "2000-01-01T00:00:00Z"
        - status: COMPLIANT
          currentStateMessage: Test-2
          check:
            UNIT_TEST:
              id: Test-2
              arg:
                NOT_EMPTY:
                  arg:
                    DATE_TIME: "1970-01-01T00:00:00Z"
        - status: COMPLIANT
          currentStateMessage: Test-3
          check:
            UNIT_TEST:
              id: Test-3
              arg:
                IS_EMPTY:
                  arg:
                    UNIT_TEST_NULL:
                      returnType: DATE_TIME
      otherwise:
        status: INCOMPLIANT
        currentStateMessage: Test Failed
        remediationMessage: Developer Fix Required
  - path: /ce/unit-test/is-empty/date-time/test-data.json
    md5Hash: C18BA085B0E0009818D51F6A53397E88
    content: |-
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "unitTest(Test-1): '2000-01-01T00:00:00Z'.isNotEmpty()",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2024-01-01T00:00:00Z"
          },
          "Id": "Test-1",
          "Name": "Test-1",
          "CA10__disappearanceTime__c": null
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "unitTest(Test-2): '1970-01-01T00:00:00Z'.isNotEmpty()",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2024-01-01T00:00:00Z"
          },
          "Id": "Test-2",
          "Name": "Test-2",
          "CA10__disappearanceTime__c": null
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "399",
            "conditionText": "unitTest(Test-3): null.isEmpty()",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2024-01-01T00:00:00Z"
          },
          "Id": "Test-3",
          "Name": "Test-3",
          "CA10__disappearanceTime__c": null
        }
      ]
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "Test-1",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "unitTest(Test-1): '2000-01-01T00:00:00Z'.isNotEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "Test-2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "unitTest(Test-2): '1970-01-01T00:00:00Z'.isNotEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "Test-3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "unitTest(Test-3): null.isEmpty()",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00Z")
    },
    "Id" : "Test-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00Z")
    },
    "Id" : "Test-2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00Z")
    },
    "Id" : "Test-3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var TemporalLib = new function () {
          var iso8601regex = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/
          this.checkIso8601 = function(arg) {
              return arg == null || iso8601regex.test(arg);
          };
          this.parseIso8601 = function(arg) {
              return new Date(arg);
          };
          this.replaceNullValues = function(arg, nullValues) {
              for (var i = 0; i < nullValues.length; i++) {
                  if (TextLib.equal(arg, nullValues[i])) {
                      return null;
                  }
              }
              return arg;
          };
      }();
      var IsEmptyLib = new function () {
          this.simpleIsEmpty = function(arg) {
              return arg == null;
          };
          this.simpleIsNotEmpty = function(arg) {
              return arg != null;
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      if (obj.Id == 'Test-1' && IsEmptyLib.simpleIsNotEmpty(TemporalLib.parseIso8601('2000-01-01T00:00:00Z'))) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "unitTest(Test-1): '2000-01-01T00:00:00Z'.isNotEmpty()", currentStateMessage: "Test-1", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      if (obj.Id == 'Test-2' && IsEmptyLib.simpleIsNotEmpty(TemporalLib.parseIso8601('1970-01-01T00:00:00Z'))) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "unitTest(Test-2): '1970-01-01T00:00:00Z'.isNotEmpty()", currentStateMessage: "Test-2", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      if (obj.Id == 'Test-3' && IsEmptyLib.simpleIsEmpty(null)) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "unitTest(Test-3): null.isEmpty()", currentStateMessage: "Test-3", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Test Failed", currentStateReferences: references1.join('\n'), remediation: "Developer Fix Required", runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          process_CA10__CaAwsInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
