saleor-dashboard/cypress/e2e/customerRegistration.js
poulch d5ed6fb202
Feature flags (#2961)
* [Feature Flags] Abstraction over flags provider (#2928)

* Remove useFlag hook

* [Feature Flags] GraphQL build multiple schemas (#2937)

* Build script

* Refactor build types script

* Remove old codegen.yml

* Clean feature flags in script

* Refactor schema path

* Restore useAuthProvider

* Update configuration file

* encapsulate details for feature flags provider

* Add proper env to flagsmith provider

* Remove flagsmith mocks

* Vite config define global variables

* Render flagmisth provider only when is used

* Keep name service agnostic

* Test with mocked flagsmith

* Use global FLAGS varaible for env flags

* Fix type issue with FLAGS

* Fix build issue

* Remove duplicate translations

* Fix typo

* Prepare for QA tests

* Remove test feature flag
2023-01-16 14:55:38 +01:00

97 lines
3.1 KiB
JavaScript

/// <reference types="cypress"/>
/// <reference types="../support"/>
import faker from "faker";
import { CUSTOMER_DETAILS } from "../elements/customers/customer-details";
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
import { customerDetailsUrl } from "../fixtures/urlList";
import {
confirmAccount,
customerRegistration,
deleteCustomersStartsWith,
} from "../support/api/requests/Customer";
import { getDefaultChannel } from "../support/api/utils/channelsUtils";
import { getMailActivationLinkForUser } from "../support/api/utils/users";
describe("Tests for customer registration", () => {
const startsWith = "Registration";
const email = `${startsWith}${faker.datatype.number()}@example.com`;
let defaultChannel;
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteCustomersStartsWith(startsWith);
getDefaultChannel().then(channel => {
defaultChannel = channel;
cy.checkIfDataAreNotNull({ defaultChannel });
});
});
it("should register customer", { tags: ["@customer", "@stagedOnly"] }, () => {
const email = `${startsWith}${faker.datatype.number()}@example.com`;
customerRegistration({ email, channel: defaultChannel.slug });
const registrationLinkRegex = /\[(\s*http[^\]]*)\]/;
getMailActivationLinkForUser(email, registrationLinkRegex)
.then(urlLink => {
const tokenRegex = /token=(.*)/;
const token = urlLink.match(tokenRegex)[1];
cy.clearSessionData();
confirmAccount(email, token);
})
.then(() => {
cy.loginUserViaRequest("token", {
email,
password: Cypress.env("USER_PASSWORD"),
}).its("body.data.tokenCreate");
})
.then(({ errors, token }) => {
expect(errors.length).to.eq(0);
expect(token).to.be.ok;
});
});
it(
"shouldn't register customer with duplicated email",
{ tags: ["@customer", "@allEnv", "@stable"] },
() => {
const duplicatedEmail = Cypress.env("USER_NAME");
customerRegistration({
duplicatedEmail,
channel: defaultChannel.slug,
}).then(({ user, errors }) => {
expect(errors[0].field).to.eq("email");
expect(user).to.not.be.ok;
});
},
);
it(
"should activate customer from dashboard",
{ tags: ["@customer", "@allEnv", "@stable"] },
() => {
customerRegistration({ email, channel: defaultChannel.slug })
.then(({ user }) => {
cy.clearSessionData()
.loginUserViaRequest()
.visit(customerDetailsUrl(user.id))
.get(CUSTOMER_DETAILS.isActiveCheckbox)
.click()
.get(BUTTON_SELECTORS.confirm)
.click()
.confirmationMessageShouldDisappear()
.clearSessionData()
.loginUserViaRequest("token", {
email,
password: Cypress.env("USER_PASSWORD"),
})
.its("body.data.tokenCreate");
})
.then(({ token, errors }) => {
expect(errors.length).to.eq(0);
expect(token).to.be.ok;
});
},
);
});