PC06-L02 · independent challenge

Content ready to publish

Check status, validations, final approval, and an optional publication time.

Practical CEL4 test casesDocumented
What will I practise?

You can combine collection and time rules with a safe optional member.

How is it checked?

Your one expression must produce the expected result for all four JSON inputs.

When am I done?

When all tests pass and you can explain every condition in your expression.

Word problem

Content is ready only in review status, with at least one successful check, exactly one approved final approval, and no publication time in the past.

Exact requirements

  1. Status must equal review.
  2. The check list is non-empty and every check passed.
  3. Exactly one approval is both final and approved.
  4. A missing publication time is allowed; a present time is now or later.

Required result

Write one CEL expression. It must return the expected value and type for all four prepared JSON inputs. Do not change the inputs to make an incomplete expression pass.

Recommended procedure

  1. Translate each numbered requirement into one small boolean condition.
  2. Run the starter expression and inspect which cases fail.
  3. Add one condition at a time and run the complete suite again.
  4. Mark the challenge complete only when you can explain every operator and every boundary.

Solve the challenge · browser test suite

Write one expression that passes every case

Edit the CEL expression, then run it against all prepared JSON inputs. A solution is complete only when every case passes.

4 test cases

Hint: Every check must pass, final approval must be unique, and a past publication time is invalid.

Tip: press Ctrl/⌘ + Enter to run all tests.
Ready without scheduleNot run yet
Expected: true · bool
Show JSON input
{
  "now": "2026-07-23T10:00:00Z",
  "content": {
    "status": "review",
    "checks": [
      {
        "passed": true
      },
      {
        "passed": true
      }
    ],
    "approvals": [
      {
        "final": true,
        "approved": true
      }
    ]
  }
}
Future publicationNot run yet
Expected: true · bool
Show JSON input
{
  "now": "2026-07-23T10:00:00Z",
  "content": {
    "status": "review",
    "publishAt": "2026-07-24T10:00:00Z",
    "checks": [
      {
        "passed": true
      }
    ],
    "approvals": [
      {
        "final": true,
        "approved": true
      }
    ]
  }
}
Failed checkNot run yet
Expected: false · bool
Show JSON input
{
  "now": "2026-07-23T10:00:00Z",
  "content": {
    "status": "review",
    "checks": [
      {
        "passed": false
      }
    ],
    "approvals": [
      {
        "final": true,
        "approved": true
      }
    ]
  }
}
Publication time in pastNot run yet
Expected: false · bool
Show JSON input
{
  "now": "2026-07-23T10:00:00Z",
  "content": {
    "status": "review",
    "publishAt": "2026-07-22T10:00:00Z",
    "checks": [
      {
        "passed": true
      }
    ],
    "approvals": [
      {
        "final": true,
        "approved": true
      }
    ]
  }
}
Test result

Not run yet

The same expression runs against every case. Test data is fixed so that boundary and failure scenarios cannot be skipped.

Explained solution

Show the complete expression
content.status == 'review' && content.checks.size() > 0 && content.checks.all(check, check.passed) && content.approvals.exists_one(approval, approval.final && approval.approved) && (!has(content.publishAt) || timestamp(content.publishAt) >= timestamp(now))

Why the solution works

  1. The status and list-size checks establish the basic state.
  2. all() rejects any failed check.
  3. exists_one() counts complete final-and-approved matches.
  4. The last group safely accepts a missing schedule or compares a present timestamp.

What the test cases prove

  • Ready without schedule: expected true (bool).
  • Future publication: expected true (bool).
  • Failed check: expected false (bool).
  • Publication time in past: expected false (bool).

The cases are intentionally different. A solution that passes only the first case has not yet implemented the complete rule.

Common mistake

Do not optimise the expression for the first successful input. A requirement is implemented only when its positive case, negative case, and boundary case all produce the stated result.

Knowledge check

Can you point to the exact part of the solution that makes each false test case fail? If two different failures depend on the same condition, explain why.

Key takeaway

You can combine collection and time rules with a safe optional member.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition for operators, types, macros, presence, strings, and time values used in this challenge.