

// describe('ConfirmMailTest', function() {
//     it("Register Form: Email is delievered", function() {
//         const incoming_mailbox = `thomasberrodedeclic42@gmail.com`;
//         cy
//           .task("gmail:check", {
//             from: "noreply@talentstube.com",
//             to: incoming_mailbox,
//             subject: `Bienve nue ${incoming_mailbox} 🔑`
//           })
//           .then(email => {
//             assert.isNotNull(email, `Email was not found`);
//           });
//       });
// })

describe("Email assertion:", () => {
    it("Look for an email with specific subject and link in email body", function() {
      // debugger; //Uncomment for debugger to work...
      cy.wait(5000) 
      cy
        .task("gmail:get-messages", {
          options: {
            include_body: true,
          }
        })
        .then(emails => {
          const found_email = emails.find(email => {
            return (
              email.from.indexOf("noreply@talentstube.com") >= 0 &&
              email.subject.indexOf("Bienvenue thomasberrodedeclic42@gmail.com 🔑") >= 0
            );
          });
          assert.isNotNull(found_email, "Found email👍");
          const body = found_email.body.text;
          assert.isTrue(
            body.indexOf(
              "http://localhost:8000/ConfirmAccount/"
            ) >= 0,
            "Found reset link👍"
          );

           var startUrl = body.indexOf("http://");
            var endUrl = body.indexOf("*");
           var link = body.substring(startUrl, endUrl);

           cy.visit(link);


           cy.get('p').should('contain','e-mail validé')
        });
    });
  });
