Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ghost/core/core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,13 @@ module.exports = {
outbox: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
event_type: {type: 'string', maxlength: 50, nullable: false},
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'pending'},
status: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'pending',
validations: {isIn: [['pending', 'processing', 'failed', 'completed']]}
},
payload: {type: 'text', maxlength: 65535, nullable: false},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true},
Expand Down
20 changes: 20 additions & 0 deletions ghost/core/test/unit/server/models/outbox.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = require('node:assert/strict');
const errors = require('@tryghost/errors');
const models = require('../../../../core/server/models');
const {OUTBOX_STATUSES} = require('../../../../core/server/models/outbox');

Expand Down Expand Up @@ -41,4 +42,23 @@ describe('Unit: models/outbox', function () {
assert.equal(defaults.retry_count, 0);
});
});

describe('validation', function () {
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/);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pattern is how it's done elsewhere, like member-created-event.test.js

});
});
});
});