Skip to content

Commit

Permalink
馃毃 change logic for test/utils/configUtils
Browse files Browse the repository at this point in the history
refs #6982
- adaption because of using nconf
- change tests which changed config directly

[ci skip]
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 20, 2016
1 parent bdad235 commit b158a3a
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 99 deletions.
11 changes: 8 additions & 3 deletions core/test/integration/api/api_mail_spec.js
@@ -1,6 +1,6 @@
var testUtils = require('../../utils'),
configUtils = require('../../utils/configUtils'),
should = require('should'),
config = require('../../../server/config'),
i18n = require('../../../../core/server/i18n'),

// test data
Expand All @@ -14,15 +14,20 @@ var testUtils = require('../../utils'),
options: {}
}]
};

i18n.init();

describe('Mail API', function () {
before(testUtils.teardown);
afterEach(testUtils.teardown);
beforeEach(testUtils.setup('perms:mail', 'perms:init'));

afterEach(function () {
configUtils.restore();
});

it('returns a success', function (done) {
config.set({mail: {transport: 'stub'}});
configUtils.set({mail: {transport: 'stub'}});

var MailAPI = require('../../../server/api/mail');

Expand All @@ -37,7 +42,7 @@ describe('Mail API', function () {
});

it('returns a boo boo', function (done) {
config.set({mail: {transport: 'stub', options: {error: 'Stub made a boo boo :('}}});
configUtils.set({mail: {transport: 'stub', options: {error: 'Stub made a boo boo :('}}});

var MailAPI = require('../../../server/api/mail');

Expand Down
4 changes: 1 addition & 3 deletions core/test/integration/api/api_posts_spec.js
Expand Up @@ -47,9 +47,7 @@ describe('Post API', function () {

describe('Browse', function () {
beforeEach(function () {
configUtils.set({theme: {
permalinks: '/:slug/'
}});
configUtils.set('theme:permalinks', '/:slug/');
});

afterEach(function () {
Expand Down
14 changes: 3 additions & 11 deletions core/test/integration/model/model_posts_spec.js
Expand Up @@ -14,9 +14,7 @@ var testUtils = require('../../utils'),
errors = require('../../../server/errors'),
DataGenerator = testUtils.DataGenerator,
context = testUtils.context.owner,

configUtils = require('../../utils/configUtils'),

sandbox = sinon.sandbox.create();

describe('Post Model', function () {
Expand Down Expand Up @@ -68,9 +66,7 @@ describe('Post Model', function () {

describe('findAll', function () {
beforeEach(function () {
configUtils.set({theme: {
permalinks: '/:slug/'
}});
configUtils.set('theme:permalinks', '/:slug/');
});

it('can findAll', function (done) {
Expand Down Expand Up @@ -293,9 +289,7 @@ describe('Post Model', function () {

describe('findOne', function () {
beforeEach(function () {
configUtils.set({theme: {
permalinks: '/:slug/'
}});
configUtils.set('theme:permalinks', '/:slug/');
});

it('can findOne', function (done) {
Expand Down Expand Up @@ -346,9 +340,7 @@ describe('Post Model', function () {
it('can findOne, returning a dated permalink', function (done) {
var firstPost = 1;

configUtils.set({theme: {
permalinks: '/:year/:month/:day/:slug/'
}});
configUtils.set('theme:permalinks', '/:year/:month/:day/:slug/');

PostModel.findOne({id: firstPost})
.then(function (result) {
Expand Down
28 changes: 13 additions & 15 deletions core/test/unit/controllers/frontend/channels_spec.js
Expand Up @@ -3,12 +3,10 @@ var should = require('should'),
Promise = require('bluebird'),
_ = require('lodash'),

// Stuff we are testing
// Stuff we are testing
channels = require('../../../../server/controllers/frontend/channels'),
api = require('../../../../server/api'),

configUtils = require('../../../utils/configUtils'),

sandbox = sinon.sandbox.create();

describe('Channels', function () {
Expand Down Expand Up @@ -122,9 +120,9 @@ describe('Channels', function () {

// Return basic paths for the activeTheme
function setupActiveTheme() {
configUtils.set({paths: {availableThemes: {casper: {
configUtils.set('paths', {availableThemes: {casper: {
'index.hbs': '/content/themes/casper/index.hbs'
}}}});
}}});
}

beforeEach(function () {
Expand Down Expand Up @@ -257,9 +255,9 @@ describe('Channels', function () {

// Return basic paths for the activeTheme
function setupActiveTheme() {
configUtils.set({paths: {availableThemes: {casper: {
configUtils.set('paths', {availableThemes: {casper: {
'index.hbs': '/content/themes/casper/index.hbs'
}}}});
}}});
}

beforeEach(function () {
Expand All @@ -279,10 +277,10 @@ describe('Channels', function () {
});

it('should render the first page of the tag channel using tag.hbs by default', function (done) {
configUtils.set({paths: {availableThemes: {casper: {
configUtils.set('paths',{availableThemes: {casper: {
'index.hbs': '/content/themes/casper/index.hbs',
'tag.hbs': '/content/themes/casper/tag.hbs'
}}}});
}}});

testChannelRender({url: '/tag/my-tag/'}, function (view) {
should.exist(view);
Expand All @@ -293,11 +291,11 @@ describe('Channels', function () {
});

it('should render the first page of the tag channel using tag-:slug.hbs if available', function (done) {
configUtils.set({paths: {availableThemes: {casper: {
configUtils.set('paths', {availableThemes: {casper: {
'index.hbs': '/content/themes/casper/index.hbs',
'tag.hbs': '/content/themes/casper/tag.hbs',
'tag-my-tag.hbs': '/content/themes/casper/tag-my-tag.hbs'
}}}});
}}});

testChannelRender({url: '/tag/my-tag/'}, function (view) {
should.exist(view);
Expand All @@ -317,10 +315,10 @@ describe('Channels', function () {
});

it('should use tag.hbs to render the tag channel if available', function (done) {
configUtils.set({paths: {availableThemes: {casper: {
configUtils.set('paths', {availableThemes: {casper: {
'index.hbs': '/content/themes/casper/index.hbs',
'tag.hbs': '/content/themes/casper/tag.hbs'
}}}});
}}});

testChannelRender({url: '/tag/my-tag/page/2/'}, function (view) {
should.exist(view);
Expand All @@ -330,11 +328,11 @@ describe('Channels', function () {
});

it('should use tag-:slug.hbs to render the tag channel if available', function (done) {
configUtils.set({paths: {availableThemes: {casper: {
configUtils.set('paths', {availableThemes: {casper: {
'index.hbs': '/content/themes/casper/index.hbs',
'tag.hbs': '/content/themes/casper/tag.hbs',
'tag-my-tag.hbs': '/content/themes/casper/tag-my-tag.hbs'
}}}});
}}});

testChannelRender({url: '/tag/my-tag/page/2/'}, function (view) {
should.exist(view);
Expand Down
17 changes: 7 additions & 10 deletions core/test/unit/controllers/frontend/fetch-data_spec.js
@@ -1,15 +1,10 @@
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),

// Stuff we are testing
api = require('../../../../server/api'),
fetchData = require('../../../../server/controllers/frontend/fetch-data'),

config = require('../../../../server/config'),
origConfig = _.cloneDeep(config),

configUtils = require('../../../utils/configUtils'),
sandbox = sinon.sandbox.create();

describe('fetchData', function () {
Expand All @@ -25,13 +20,13 @@ describe('fetchData', function () {
});

afterEach(function () {
config.set(origConfig);
configUtils.restore();
sandbox.restore();
});

describe('channel config', function () {
beforeEach(function () {
config.set({theme: {postsPerPage: 10}});
configUtils.set({theme: {postsPerPage: 10}});
});

it('should handle no post options', function (done) {
Expand Down Expand Up @@ -75,6 +70,7 @@ describe('fetchData', function () {
}
}
};

fetchData(channelOpts).then(function (result) {
should.exist(result);
result.should.be.an.Object().with.properties('posts', 'meta', 'data');
Expand Down Expand Up @@ -102,6 +98,7 @@ describe('fetchData', function () {
}
}
};

fetchData(channelOpts).then(function (result) {
should.exist(result);

Expand Down Expand Up @@ -151,7 +148,7 @@ describe('fetchData', function () {

describe('valid postsPerPage', function () {
beforeEach(function () {
config.set({theme: {postsPerPage: 10}});
configUtils.set({theme: {postsPerPage: 10}});
});

it('Adds limit & includes to options by default', function (done) {
Expand All @@ -167,7 +164,7 @@ describe('fetchData', function () {

describe('invalid postsPerPage', function () {
beforeEach(function () {
config.set({theme: {postsPerPage: '-1'}});
configUtils.set({theme: {postsPerPage: '-1'}});
});

it('Will not add limit if postsPerPage is not valid', function (done) {
Expand Down
43 changes: 21 additions & 22 deletions core/test/unit/metadata/author_image_spec.js
@@ -1,10 +1,13 @@
var getAuthorImage = require('../../../server/data/meta/author_image'),
should = require('should'),
config = require('../../../server/config');
configUtils = require('../../utils/configUtils');

describe('getAuthorImage', function () {
it('should return author image url if post and has url',
function () {
afterEach(function () {
configUtils.restore();
});

it('should return author image url if post and has url', function () {
var imageUrl = getAuthorImage({
context: ['post'],
post: {
Expand All @@ -16,8 +19,7 @@ describe('getAuthorImage', function () {
imageUrl.should.equal('/content/images/2016/01/myimage.jpg');
});

it('should return absolute author image url if post and has url',
function () {
it('should return absolute author image url if post and has url', function () {
var imageUrl = getAuthorImage({
context: ['post'],
post: {
Expand All @@ -30,8 +32,7 @@ describe('getAuthorImage', function () {
imageUrl.should.match(/\/content\/images\/2016\/01\/myimage\.jpg$/);
});

it('should return author image url if AMP post and has url',
function () {
it('should return author image url if AMP post and has url', function () {
var imageUrl = getAuthorImage({
context: ['amp', 'post'],
post: {
Expand All @@ -43,8 +44,7 @@ describe('getAuthorImage', function () {
imageUrl.should.equal('/content/images/2016/01/myimage.jpg');
});

it('should return absolute author image url if AMP post and has url',
function () {
it('should return absolute author image url if AMP post and has url', function () {
var imageUrl = getAuthorImage({
context: ['amp', 'post'],
post: {
Expand All @@ -57,8 +57,7 @@ describe('getAuthorImage', function () {
imageUrl.should.match(/\/content\/images\/2016\/01\/myimage\.jpg$/);
});

it('should return null if context does not contain author image url and is a post',
function () {
it('should return null if context does not contain author image url and is a post', function () {
var imageUrl = getAuthorImage({
context: ['post'],
post: {
Expand Down Expand Up @@ -86,17 +85,17 @@ describe('getAuthorImage', function () {
});

it('should return config theme author image if context is a post and no post',
function () {
config.set({
theme: {
author: {
image: '/content/images/2016/01/myimage.jpg'
function () {
configUtils.set({
theme: {
author: {
image: '/content/images/2016/01/myimage.jpg'
}
}
}
});
var imageUrl = getAuthorImage({
context: ['post']
});
imageUrl.should.match(/\/content\/images\/2016\/01\/myimage\.jpg$/);
});
var imageUrl = getAuthorImage({
context: ['post']
});
imageUrl.should.match(/\/content\/images\/2016\/01\/myimage\.jpg$/);
});
});

0 comments on commit b158a3a

Please sign in to comment.