/// <reference types="cypress" />

describe('Unsubscribe from email link', () => {
  beforeEach(() =>{
    cy.intercept('POST', /\S+\/unsubscribe_user_match\/\S+/, { statusCode: 200, body: { ok: true } });
  })

  it("redirect to home page if tok is not provided", () => {
    cy.visit('/unsubscribe');
    cy.location('pathname').should('eq', '/');
  });

  it.only("show unsubscribed message", () => {
    cy.visit('/unsubscribe?tok=123');
    cy.location('search')
    .should('equal', '?tok=123')
    .then((s) => new URLSearchParams(s))
    .invoke('get', 'tok')
    .should('equal', '123')
    cy.contains("successfully unsubscribed")
  });

})