Skip to content

Commit

Permalink
Playwright members tests (#4453)
Browse files Browse the repository at this point in the history
* attributes critical test migrated to playwright

* changeset added

* TC: SALEOR_35 User should be able to invite staff member with full access permissions

* deactivate staff member test

* Admin User should be able to activate other user

* reset password test

* user should be able to change password test

* Trigger Build

* Trigger Build

* removed reset password and change password tests

* fix dashboard path

* removed should be able to invite staff user

* removed duplacated e2-poll.yaml
  • Loading branch information
wojteknowacki committed Nov 21, 2023
1 parent b5d5740 commit 698e2cd
Show file tree
Hide file tree
Showing 26 changed files with 488 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-points-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Attributes critical test migrated to playwright
6 changes: 3 additions & 3 deletions cypress/e2e/staffMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("Staff members", () => {
);

it(
"should deactivate user. TC: SALEOR_3502",
"should deactivate user. TC: SALEOR_3502 - migration in progress - to delete when done",
{ tags: ["@staffMembers", "@allEnv"] },
() => {
updateStaffMember({ userId: user.id, isActive: true });
Expand All @@ -103,7 +103,7 @@ describe("Staff members", () => {
);

it(
"should activate user. TC: SALEOR_3503",
"should activate user. TC: SALEOR_3503 - migration in progress - to delete when done",
{ tags: ["@staffMembers", "@allEnv", "@critical"] },
() => {
const serverStoredEmail = email.toLowerCase();
Expand Down Expand Up @@ -178,7 +178,7 @@ describe("Staff members", () => {
);

it(
"should not be able to create staff member with not unique email. TC: SALEOR_3508",
"should not be able to create staff member with not unique email. TC: SALEOR_3508 - should not be migrated to playwright as critical",
{ tags: ["@staffMembers", "@allEnv", "@critical"] },
() => {
const firstName = faker.name.firstName();
Expand Down
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"@graphql-codegen/typescript-apollo-client-helpers": "^2.1.10",
"@graphql-codegen/typescript-operations": "^2.2.4",
"@graphql-codegen/typescript-react-apollo": "^3.2.5",
"@playwright/test": "^1.38.1",
"@playwright/test": "^1.40.0",
"@saleor/app-sdk": "0.43.0",
"@sentry/cli": "^2.20.6",
"@swc/jest": "^0.2.26",
Expand Down
43 changes: 32 additions & 11 deletions playwright/api/basics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIResponse, request } from "@playwright/test";
import { APIRequestContext } from "@playwright/test";

const URL = process.env.API_URI || "";
interface Data {
Expand All @@ -9,21 +9,41 @@ interface User {
email: string;
password: string;
}
export class GraphQLService {
async example(
user: User,
authorization: string = "auth",
): Promise<APIResponse> {
interface TokenCreateResponse {
tokenCreate: {
token: string;
refreshToken: string;
errors: [
{
message: string;
code: string;
},
];
user: {
id: string;
};
};
}

interface ApiResponse<T> {
data: T;
}

export class BasicApiService {
readonly request: APIRequestContext;

constructor(request: APIRequestContext) {
this.request = request;
}
async logInUserViaApi(user: User, authorization: string = "auth") {
const headers = { Authorization: `Bearer ${authorization}` };

const api = await request.newContext();
const query = `mutation TokenAuth{
tokenCreate(email: "${user.email}", password: "${user.password}") {
token
refreshToken
refreshToken
errors: errors {
code
field
message
}
user {
Expand All @@ -34,7 +54,8 @@ export class GraphQLService {
const data: Data = {
query: query,
};
const loginResponse = await api.post(URL, { data, headers });
return loginResponse;
const loginResponse = await this.request.post(URL, { data, headers });
const loginResponseJson = await loginResponse.json();
return loginResponseJson as ApiResponse<TokenCreateResponse>;
}
}
66 changes: 66 additions & 0 deletions playwright/api/mailpit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { URL_LIST } from "@data/url";
import { APIRequestContext, expect } from "@playwright/test";

const MAILPIT_URI = process.env.CYPRESS_MAILPITURL || "no mailpit url provided";
const mailpitUrl = "https://" + MAILPIT_URI;
export class MailpitService {
readonly request: APIRequestContext;

constructor(request: APIRequestContext) {
this.request = request;
}

async getLastEmails(getEmailsLimit = 100) {
let latestEmails: any;
await expect(async () => {
latestEmails = await this.request.get(
`${mailpitUrl}/api/v1/messages?limit=${getEmailsLimit}`,
);
expect(latestEmails.body()).not.toBeUndefined();
}).toPass({
intervals: [3_000, 3_000, 3_000],
timeout: 10_000,
});
const latestEmailsJson = await latestEmails!.json();
return latestEmailsJson;
}

async getEmailDetails(mailId: string) {
const emailDetails = await this.request.get(
`${mailpitUrl}/api/v1/message/${mailId}`,
);
const emailDetailsJson = await emailDetails.json();

return emailDetailsJson;
}

async getEmailsForUser(userEmail: string) {
let userEmails: any[] = [];
await expect(async () => {
const emails = await this.getLastEmails();
userEmails = emails.messages.filter((mails: { To: any[] }) =>
mails.To.map(
(recipientObj: { Address: any }) => `${recipientObj.Address}`,
).includes(userEmail),
);
expect(userEmails.length).toBeGreaterThanOrEqual(1);
}).toPass({
intervals: [3_000, 3_000, 3_000],
timeout: 10_000,
});
await expect(userEmails).not.toEqual([]);

return userEmails;
}

async generateResetPasswordUrl(userEmail: string) {
const tokenRegex = /token=([A-Za-z0-9]+(-[A-Za-z0-9]+)+)/;

const userEmails = await this.getEmailsForUser(userEmail);
const emailDetails = await this.getEmailDetails(userEmails[0].ID);
const emailHtmlFormat = tokenRegex.exec(emailDetails.HTML.toString());
const token = "&" + emailHtmlFormat![0];
const resetPasswordUrl = URL_LIST.resetPassword + userEmail + token;
return resetPasswordUrl;
}
}
47 changes: 47 additions & 0 deletions playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const PRODUCTS = {
singleProductType: {
id: "UHJvZHVjdFR5cGU6Njcy",
info: "Single product type",
},
productToAddVariants: {
id: "UHJvZHVjdDo3Mjk%3D",
info: "Product that does not contain any variant yet",
},
productWithOneVariant: {
id: "UHJvZHVjdDo3MzM%3D",
info: "Product that contains single variant",
},
};

export const SHIPPING_METHODS = {
shippingMethodWithoutRates: {
id: "U2hpcHBpbmdab25lOjIzNzg%3D",
info: "Shipping method that is used to add rates",
},
};
export const USERS = {
userToBeDeactivated: {
id: "VXNlcjoxMzQ3",
email: "user-to-be-deactivated@gmai.com",
info: "Active user used in deactivation user test",
},
userToBeActivated: {
id: "VXNlcjoxMzQ5",
email: "user-to-be-activated@gmai.com",
info: "Inactive user used in activation user test",
},
userForPasswordReset: {
email: "user-for-password-reset@gmail.com",
newPassword: "4321test",
info: "User used in reset password test",
name: "e2e",
lastName: "user",
},
userForPasswordChange: {
email: "change-password-user@gmail.com",
newPassword: "4321test",
info: "User used in change password test",
name: "change password",
lastName: "user",
},
};
21 changes: 0 additions & 21 deletions playwright/data/testData.ts

This file was deleted.

37 changes: 19 additions & 18 deletions playwright/data/url.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export const URL_LIST = {
addProduct: "/products/add",
addPageType: "/pages/add?page-type-id=",
apps: "/custom-apps/",
attributes: "/attributes/",
categories: "/categories/",
channels: "/channels/",
collections: "/collections/",
configuration: "/configuration/",
customers: "/customers/",
dashboard: "/dashboard/",
draftOrders: "/orders/drafts/",
giftCards: "/gift-cards/",
addProduct: "products/add",
addPageType: "pages/add?page-type-id=",
apps: "custom-apps/",
attributes: "attributes/",
addAttributes: "attributes/add",
categories: "categories/",
channels: "channels/",
collections: "collections/",
configuration: "configuration/",
customers: "customers/",
dashboard: "dashboard/",
draftOrders: "orders/drafts/",
giftCards: "gift-cards/",
homePage: "/",
newPassword: "/new-password/",
navigation: "/navigation/",
Expand All @@ -29,10 +29,11 @@ export const URL_LIST = {
siteSettings: "/site-settings/",
staffMembers: "/staff/",
stripeApiPaymentMethods: "https://api.stripe.com/v1/payment_methods",
translations: "/translations/",
variants: "/variant/",
vouchers: "/discounts/vouchers/",
variant: "/variant/",
warehouses: "/warehouses/",
webhooksAndEvents: "/custom-apps/",
translations: "translations/",
variants: "variant/",
vouchers: "discounts/vouchers/",
variant: "variant/",
warehouses: "warehouses/",
webhooksAndEvents: "custom-apps/",
resetPassword: "/new-password/?email=",
};

0 comments on commit 698e2cd

Please sign in to comment.