Guest User

Untitled

a guest
Jun 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. // Dependencies
  2. const assert = require('assert');
  3. const {
  4. Dashboard,
  5. DashboardUser,
  6. User,
  7. Organisation,
  8. OrganisationUser,
  9. ForgotPassword
  10. } = require('api/models');
  11. const { validUsers, validUser } = require('api/test/data/userData.test');
  12. const { interactsWithMail } = require('api/test/helpers/emailStub');
  13. const pages = require('./pages');
  14. const selectors = require('./selectors');
  15. const scope = require('./scope');
  16.  
  17. // Defines whether puppeteer runs Chrome in headless mode.
  18. let headless = true;
  19. let slowMo = 5;
  20. // Chrome is set to run headlessly and with no slowdown in CircleCI
  21. if (process.env.CIRCLECI) headless = true;
  22. if (process.env.CIRCLECI) slowMo = 0;
  23.  
  24. const assertUserHasPassword = async (identifier, password) => {
  25. const authenticated = await User.authenticate({ identifier, password });
  26. assert(authenticated);
  27. };
  28.  
  29. const assertUserHasEmail = async (username, email) => {
  30. const user = await User.findOne({ username });
  31. assert.equal(user.email, email);
  32. };
  33.  
  34. const userExists = async username => {
  35. const userDetails = validUsers.find(v => v.username === username);
  36. await new User(userDetails).save();
  37. };
  38.  
  39. const dashboardForUserExists = async (username, name) => {
  40. const user = await User.findOne({ username });
  41. await new Dashboard({ name, createdBy: user._id }).save();
  42. };
  43.  
  44. const closeAccount = async username => {
  45. const user = await User.findOne({ username });
  46. await user.deactivate(validUser.password);
  47. };
  48.  
  49. const pending = callback => {
  50. callback(null, 'pending');
  51. };
  52.  
  53. const visitHomepage = async () => {
  54. if (!scope.browser)
  55. scope.browser = await scope.driver.launch({ headless, slowMo });
  56. scope.context.currentPage = await scope.browser.newPage();
  57. scope.context.currentPage.setViewport({ width: 1280, height: 1024 });
  58. const url = scope.host + pages.home;
  59. const visit = await scope.context.currentPage.goto(url, {
  60. waitUntil: 'networkidle2'
  61. });
  62. return visit;
  63. };
Add Comment
Please, Sign In to add comment