Ghost/ghost/admin/tests/unit/validators/subscriber-test.js
Kevin Ansfield e74e2e039e Update code to match eslint rules
no issue
- switch `jscs` and `jshint` inline config to `eslint` config
- fix eslint errors, predominantly in tests where the config now the main app config more closely
2016-11-14 13:26:00 +00:00

79 lines
2.4 KiB
JavaScript

/* jshint expr:true */
import {expect} from 'chai';
import {
describe,
it
} from 'mocha';
import Ember from 'ember';
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
const {
run,
Object: EmberObject
} = Ember;
const Subscriber = EmberObject.extend(ValidationEngine, {
validationType: 'subscriber',
email: null
});
describe('Unit: Validator: subscriber', function () {
it('validates email by default', function () {
let subscriber = Subscriber.create({});
let properties = subscriber.get('validators.subscriber.properties');
expect(properties, 'properties').to.include('email');
});
it('passes with a valid email', function () {
let subscriber = Subscriber.create({email: 'test@example.com'});
let passed = false;
run(() => {
subscriber.validate({property: 'email'}).then(() => {
passed = true;
});
});
expect(passed, 'passed').to.be.true;
expect(subscriber.get('hasValidated'), 'hasValidated').to.include('email');
});
it('validates email presence', function () {
let subscriber = Subscriber.create({});
let passed = false;
run(() => {
subscriber.validate({property: 'email'}).then(() => {
passed = true;
});
});
let emailErrors = subscriber.get('errors').errorsFor('email').get(0);
expect(emailErrors.attribute, 'errors.email.attribute').to.equal('email');
expect(emailErrors.message, 'errors.email.message').to.equal('Please enter an email.');
expect(passed, 'passed').to.be.false;
expect(subscriber.get('hasValidated'), 'hasValidated').to.include('email');
});
it('validates email', function () {
let subscriber = Subscriber.create({email: 'foo'});
let passed = false;
run(() => {
subscriber.validate({property: 'email'}).then(() => {
passed = true;
});
});
let emailErrors = subscriber.get('errors').errorsFor('email').get(0);
expect(emailErrors.attribute, 'errors.email.attribute').to.equal('email');
expect(emailErrors.message, 'errors.email.message').to.equal('Invalid email.');
expect(passed, 'passed').to.be.false;
expect(subscriber.get('hasValidated'), 'hasValidated').to.include('email');
});
});