mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
d53ef125e0
no issue - updates `package.json` details to better reflect the separation from the `Ghost` package - update ember config and all import statements to reflect the new `ghost-admin` module name in `package.json`
67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
/* jshint expr:true */
|
|
import { expect } from 'chai';
|
|
import {
|
|
describe,
|
|
it
|
|
} from 'mocha';
|
|
import validator from 'ghost-admin/validators/slack-integration';
|
|
import SlackObject from 'ghost-admin/models/slack-integration';
|
|
|
|
const testInvalidUrl = function (url) {
|
|
let slackObject = SlackObject.create({url});
|
|
|
|
validator.check(slackObject, 'url');
|
|
|
|
expect(validator.get('passed'), `"${url}" passed`).to.be.false;
|
|
expect(slackObject.get('errors').errorsFor('url')).to.deep.equal([{
|
|
attribute: 'url',
|
|
message: 'The URL must be in a format like https://hooks.slack.com/services/<your personal key>'
|
|
}]);
|
|
expect(slackObject.get('hasValidated')).to.include('url');
|
|
};
|
|
|
|
const testValidUrl = function (url) {
|
|
let slackObject = SlackObject.create({url});
|
|
|
|
validator.check(slackObject, 'url');
|
|
|
|
expect(validator.get('passed'), `"${url}" failed`).to.be.true;
|
|
expect(slackObject.get('hasValidated')).to.include('url');
|
|
};
|
|
|
|
describe('Unit: Validator: slack-integration', function () {
|
|
it('fails on invalid url values', function () {
|
|
let invalidUrls = [
|
|
'test@example.com',
|
|
'/has spaces',
|
|
'no-leading-slash',
|
|
'http://example.com/with spaces'
|
|
];
|
|
|
|
invalidUrls.forEach(function (url) {
|
|
testInvalidUrl(url);
|
|
});
|
|
});
|
|
|
|
it('passes on valid url values', function () {
|
|
let validUrls = [
|
|
'https://hooks.slack.com/services/;alskdjf',
|
|
'https://hooks.slack.com/services/123445678',
|
|
'https://hooks.slack.com/services/some_webhook'
|
|
];
|
|
|
|
validUrls.forEach(function (url) {
|
|
testValidUrl(url);
|
|
});
|
|
});
|
|
|
|
it('validates url by default', function () {
|
|
let slackObject = SlackObject.create();
|
|
|
|
validator.check(slackObject);
|
|
|
|
expect(slackObject.get('errors').errorsFor('url')).to.be.empty;
|
|
expect(validator.get('passed')).to.be.true;
|
|
});
|
|
});
|