Adding mock functions to tests.

This commit is contained in:
David Jay
2016-11-30 16:18:54 -05:00
parent fb977da01d
commit 2b0a503c6a
2 changed files with 56 additions and 41 deletions
+18 -17
View File
@@ -1,20 +1,21 @@
const Comments = require('../../models/comment')
const Users = require('../../models/user')
const Actions = require('../../models/action')
const Comments = require('../../models/comment');
const Users = require('../../models/user');
const Actions = require('../../models/action');
const Assets = require('../../models/asset');
const globals = require('./globals');
const mockComments = [
{
body: 'Pangolin pups are called pangopups.',
author_id: '123',
id: 'abc'
},
{
body: 'Baby whales grow at up to 8lbs an hour.',
author_id: '456',
id: 'def'
}
];
/* Create an array of comments */
module.exports.comments = (comments) => Assets.findOrCreateByUrl(globals.baseUrl)
.then((asset) => {
comments = comments.map((comment) => {
comment.asset_id = asset.id;
return comment;
});
return Comments.create(comments);
});
console.log('Loading mocks.');
/* Create an array of users */
module.exports.users = (users) => Users.createLocalUsers(users);
Comments.create(mockComments);
/* Create an array of actions */
module.exports.actions = (actions) => Actions.create(actions);
+38 -24
View File
@@ -1,4 +1,5 @@
const utils = require('../../utils/e2e-mongoose');
const mocks = require('../mocks');
const mockComment = 'This is a test comment.';
const mockReply = 'This is a test reply';
@@ -93,30 +94,43 @@ module.exports = {
});
});
},
// 'User replies to a comment with premod on': client => {
// client.perform((client, done) => {
// client.page.embedStream().setConfig({moderation: 'pre'}, client.globals.baseUrl)
// .then(() => {
// //Load Page
// client.resizeWindow(1200, 800)
// .url(client.globals.baseUrl)
// .frame('coralStreamIframe')
// .pause(60000);
//
// // Post a reply
// client.waitForElementVisible('.coral-plugin-replies-reply-button', 5000)
// .click('.coral-plugin-replies-reply-button')
// .waitForElementVisible('#replyText')
// .setValue('#replyText', mockReply)
// .click('.coral-plugin-replies-textarea button')
// .waitForElementVisible('.reply', 1000)
//
// //Verify that it appears
// .assert.containsText('.reply', mockReply);
// done();
// });
// });
// },
'User replies to a comment with premod on': client => {
client.perform((client, done) => {
client.page.embedStream().setConfig({moderation: 'pre'}, client.globals.baseUrl)
// Add a mock user
.then(() => mocks.users([{
displayName: 'Baby Blue',
email: 'whale@tale.sea',
password: 'krill'
}]))
// Add a mock preapproved comment by that user
.then((user) => mocks.comments([{
body: 'Whales are not fish.',
status: 'approved',
author_id: user.id
}]))
.then(() => {
//Load Page
client.resizeWindow(1200, 800)
.url(client.globals.baseUrl)
.frame('coralStreamIframe')
.pause(60000);
// Post a reply
client.waitForElementVisible('.coral-plugin-replies-reply-button', 5000)
.click('.coral-plugin-replies-reply-button')
.waitForElementVisible('#replyText')
.setValue('#replyText', mockReply)
.click('.coral-plugin-replies-textarea button')
.waitForElementVisible('#coral-notif', 1000)
//Verify that it appears
.assert.containsText('#coral-notif', 'moderation team');
done();
});
});
},
after: client => {
utils.after();
client.end();