0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/test/unit/server/models/newsletter.test.js
Rishabh Garg b0df387deb
Cleaned up newsletter schema migrations (#14441)
refs https://github.com/TryGhost/Team/issues/1500

The newsletter table schema has bunch of changes to go through for new and existing columns, this consolidates the schema changes into a single re-create table migration that drops and adds the newsletter table with correct schema. The table re-create migration needs to run before any of the tables using newsletter as foreign key. The changes include -

- new columns for design related fields
- new slug column for filtering
- unique constraint to `name` column
- remove `default` column (noops the existing default column migration)
- `sender_reply_to` has a default of newsletter and a validation of ['newsletter', 'support']
- updated default values for `subscribe_on_signup` and  `recipient_filter`
2022-04-08 19:06:30 +05:30

54 lines
1.9 KiB
JavaScript

/* eslint no-invalid-this:0 */
const errors = require('@tryghost/errors');
const sinon = require('sinon');
const should = require('should');
const models = require('../../../../core/server/models');
describe('Unit: models/newsletter', function () {
const mockDb = require('mock-knex');
before(function () {
models.init();
});
after(function () {
sinon.restore();
});
describe('validation', function () {
describe('blank', function () {
it('name cannot be blank', function () {
return models.Newsletter.add({
sender_name: 'Jamie',
sender_email: 'jamie@example.com',
sender_reply_to: 'newsletter',
visibility: 'members',
sort_order: 0
})
.then(function () {
throw new Error('expected ValidationError');
})
.catch(function (err) {
should(err[0] instanceof errors.ValidationError).eql(true);
err[0].message.should.match(/newsletters\.name/);
});
});
it('sender name cannot be blank', function () {
return models.Newsletter.add({
name: 'Daily report 2',
sender_email: 'jamie@example.com',
sender_reply_to: 'newsletter',
sort_order: 0
})
.then(function () {
throw new Error('expected ValidationError');
})
.catch(function (err) {
(err[0] instanceof errors.ValidationError).should.eql(true);
err[0].message.should.match(/newsletters\.sender_name/);
});
});
});
});
});