Added validation for outbox statuses#26545
Conversation
WalkthroughThe pull request updates the 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e71eba1 to
8eaf1c8
Compare
8eaf1c8 to
82fda97
Compare
troyciesco
left a comment
There was a problem hiding this comment.
@cmraible i think an isIn change doesn't require a migration but shout if i'm wrong!
| assert(Array.isArray(err)); | ||
| assert.equal(err.length, 1); | ||
| assert.equal((err[0] instanceof errors.ValidationError), true); | ||
| assert.match(err[0].context, /outbox\.status/); |
There was a problem hiding this comment.
this pattern is how it's done elsewhere, like member-created-event.test.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/unit/server/models/outbox.test.js (1)
47-62: Considerasync/awaitto surface the sentinel message on unexpected success.The
.catch()at line 56 sits in the same chain as the.then()sentinel at line 53-55. IfOutbox.add()unexpectedly resolves,.then()throws the sentinel error and.catch()immediately catches it — the test still fails (becauseArray.isArray(new Error(...))isfalse), but the diagnostic message will be an opaqueAssertionErrorrather than"expected ValidationError".♻️ Cleaner async/await equivalent
- it('rejects invalid status values', function () { - return models.Outbox.add({ - event_type: 'MemberCreatedEvent', - payload: '{}', - status: 'not-a-real-status' - }) - .then(function () { - throw new Error('expected ValidationError'); - }) - .catch(function (err) { - assert(Array.isArray(err)); - assert.equal(err.length, 1); - assert.equal((err[0] instanceof errors.ValidationError), true); - assert.match(err[0].context, /outbox\.status/); - }); + it('rejects invalid status values', async function () { + let caught; + try { + await models.Outbox.add({ + event_type: 'MemberCreatedEvent', + payload: '{}', + status: 'not-a-real-status' + }); + assert.fail('expected ValidationError'); + } catch (err) { + caught = err; + } + assert(Array.isArray(caught)); + assert.equal(caught.length, 1); + assert.ok(caught[0] instanceof errors.ValidationError); + assert.match(caught[0].context, /outbox\.status/); + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/test/unit/server/models/outbox.test.js` around lines 47 - 62, The promise-chain test for models.Outbox.add currently throws a sentinel Error inside .then() which is then caught by the following .catch(), hiding the intended message; rewrite the test to use async/await (make the it callback async), await models.Outbox.add({ ... }), and wrap that await in a try/catch so that on unexpected resolution you throw new Error('expected ValidationError') outside the catch that asserts the ValidationError shape, or alternatively await and assert failure with a direct throw if no error was thrown—update references to models.Outbox.add and the test's .then/.catch flow accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ghost/core/test/unit/server/models/outbox.test.js`:
- Around line 47-62: The promise-chain test for models.Outbox.add currently
throws a sentinel Error inside .then() which is then caught by the following
.catch(), hiding the intended message; rewrite the test to use async/await (make
the it callback async), await models.Outbox.add({ ... }), and wrap that await in
a try/catch so that on unexpected resolution you throw new Error('expected
ValidationError') outside the catch that asserts the ValidationError shape, or
alternatively await and assert failure with a direct throw if no error was
thrown—update references to models.Outbox.add and the test's .then/.catch flow
accordingly.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
ghost/core/core/server/data/schema/schema.jsghost/core/test/unit/server/models/outbox.test.js
closes NY-809
outbox.statusfield