Guest User

Untitled

a guest
Dec 28th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. // import an apiKey and the official js client
  2. const apiKey = require("./config.json").apiKey;
  3. const Emaile2eClient = require("emaile2e-client");
  4.  
  5. // instantiate a client for the inbox endpoints
  6. const api = new Emaile2eClient.InboxcontrollerApi();
  7.  
  8. // test the authentication flow on emaile2e.com
  9. // using Cypress test runenr
  10. describe("Emaile2e.com user signup", () => {
  11. // we will set these with emaile2e
  12. let username;
  13. let emailAddress;
  14.  
  15. const password = "test-password";
  16.  
  17. before("create a random email inbox to sign-up with", done => {
  18. // create a new email inbox that returns an id and an address
  19. api
  20. .createRandomInboxUsingPOST(apiKey)
  21. .then(
  22. data => data.payload,
  23. err => {
  24. // log or inspect an error here if necessary
  25. throw err;
  26. }
  27. )
  28. .then(({ id, address }) => {
  29. username = id;
  30. emailAddress = address;
  31. expect(username).to.eq(id);
  32. done();
  33. });
  34. });
  35.  
  36. it("allows signup with generated inbox and username", () => {
  37. cy.visit("/sign-up");
  38. // use the username and email address we got
  39. // from Emaile2e to sign a user up by filling out
  40. // the sign-up form
  41. cy.get("#username").type(username);
  42. cy.get("#email").type(emailAddress);
  43. cy.get("#password").type(password);
  44. cy.get("#passwordConfirmation").type(password);
  45. cy.get("button[type='submit']").click();
  46. });
  47.  
  48. it(
  49. "sends a verification code which can be " +
  50. "received by user, extracted, and submitted",
  51. () => {
  52. let verificationCode;
  53. cy.location("pathname").should("eq", `/verify/${username}`);
  54. // use cypress's async api
  55. cy.then(() => {
  56. // check the users inbox and hold the
  57. // connection until one email is present
  58. return api
  59. .getEmailsForInboxUsingGET(apiKey, username, {
  60. minCount: 1,
  61. maxWait: 90
  62. })
  63. .then(
  64. data => data.payload,
  65. err => {
  66. throw err;
  67. }
  68. )
  69. .then(([latestEmail]) => {
  70. // regex match for the confirmation code
  71. // within the email body
  72. const r = /\s(\d{6})\./g;
  73. // extract the verication code
  74. verificationCode = r.exec(latestEmail.body)[1];
  75. });
  76. });
  77. // submit the code we extracted from the email
  78. cy.get("#code").then(input => {
  79. cy.wrap(input).type(verificationCode);
  80. });
  81. cy.get("button[type='submit']").click();
  82. }
  83. );
  84.  
  85. it("successfully verifies a user" + "and allows that user to login", () => {
  86. cy.location("pathname").should("eq", "/login");
  87. cy.get("#username").type(username);
  88. cy.get("#password").type(password);
  89. cy.get("button[type='submit']").click();
  90. cy.location("pathname").should("eq", "/dashboard");
  91. });
  92. });
Add Comment
Please, Sign In to add comment