Created
June 18, 2018 10:24
-
-
Save paulbjensen/8f7e56f1ea89b25a85064ed458e2ba99 to your computer and use it in GitHub Desktop.
The actions.js file, part of an article for Medium.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dependencies | |
const assert = require('assert'); | |
const { | |
Dashboard, | |
DashboardUser, | |
User, | |
Organisation, | |
OrganisationUser, | |
ForgotPassword | |
} = require('api/models'); | |
const { validUsers, validUser } = require('api/test/data/userData.test'); | |
const { interactsWithMail } = require('api/test/helpers/emailStub'); | |
const pages = require('./pages'); | |
const selectors = require('./selectors'); | |
const scope = require('./scope'); | |
// Defines whether puppeteer runs Chrome in headless mode. | |
let headless = true; | |
let slowMo = 5; | |
// Chrome is set to run headlessly and with no slowdown in CircleCI | |
if (process.env.CIRCLECI) headless = true; | |
if (process.env.CIRCLECI) slowMo = 0; | |
const assertUserHasPassword = async (identifier, password) => { | |
const authenticated = await User.authenticate({ identifier, password }); | |
assert(authenticated); | |
}; | |
const assertUserHasEmail = async (username, email) => { | |
const user = await User.findOne({ username }); | |
assert.equal(user.email, email); | |
}; | |
const userExists = async username => { | |
const userDetails = validUsers.find(v => v.username === username); | |
await new User(userDetails).save(); | |
}; | |
const dashboardForUserExists = async (username, name) => { | |
const user = await User.findOne({ username }); | |
await new Dashboard({ name, createdBy: user._id }).save(); | |
}; | |
const closeAccount = async username => { | |
const user = await User.findOne({ username }); | |
await user.deactivate(validUser.password); | |
}; | |
const pending = callback => { | |
callback(null, 'pending'); | |
}; | |
const visitHomepage = async () => { | |
if (!scope.browser) | |
scope.browser = await scope.driver.launch({ headless, slowMo }); | |
scope.context.currentPage = await scope.browser.newPage(); | |
scope.context.currentPage.setViewport({ width: 1280, height: 1024 }); | |
const url = scope.host + pages.home; | |
const visit = await scope.context.currentPage.goto(url, { | |
waitUntil: 'networkidle2' | |
}); | |
return visit; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment