@bigbinary/neeto-playwright-commons 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Page, APIRequestContext, Response, APIResponse, Fixtures, PlaywrightWor
3
3
  import MailosaurClient from 'mailosaur';
4
4
  import { I18nPlaywrightFixture } from 'playwright-i18next-fixture';
5
5
  import { TFunction } from 'i18next';
6
+ import * as playwright_core from 'playwright-core';
6
7
 
7
8
  interface InterceptMultipleResponsesParams {
8
9
  responseUrl: string;
@@ -139,6 +140,7 @@ declare class OrganizationPage {
139
140
  page: Page;
140
141
  neetoPlaywrightUtilities: CustomCommands;
141
142
  constructor(page: Page, neetoPlaywrightUtilities: CustomCommands);
143
+ baseUrlGenerator: (appName: string) => string;
142
144
  createOrganization: ({ email, businessName, subdomainName, firstName, lastName, appName, }: CreateOrganizationProps) => Promise<void>;
143
145
  setupOrganization: (product: string) => Promise<void>;
144
146
  updateSubdomainIfExists: (appName: string) => Promise<void>;
@@ -186,6 +188,14 @@ declare const ROUTES: {
186
188
  show: (id: string) => string;
187
189
  };
188
190
  };
191
+ declare const API_ROUTES: {
192
+ teamMembers: {
193
+ all: string;
194
+ bulkUpdate: string;
195
+ index: string;
196
+ show: (id: string) => string;
197
+ };
198
+ };
189
199
 
190
200
  declare const COMMON_SELECTORS: {
191
201
  spinner: string;
@@ -441,8 +451,10 @@ type Hyphenize = (input: number | string) => string;
441
451
  type JoinHyphenCase = (args: string) => string;
442
452
  declare const joinString: JoinString;
443
453
  declare const readFileSyncIfExists: ReadFileSyncIfExists;
454
+ declare const getGlobalUserState: () => Record<string, string>;
444
455
  declare const writeDataToFile: WriteDataToFile;
445
456
  declare const updateCredentials: UpdateCredentials;
457
+ declare const removeCredentialFile: ClearCredentials;
446
458
  declare const clearCredentials: ClearCredentials;
447
459
  declare const hyphenize: Hyphenize;
448
460
  declare const joinHyphenCase: JoinHyphenCase;
@@ -451,6 +463,7 @@ declare const skipTest: {
451
463
  forReviewEnv: () => void;
452
464
  forAllExceptStagingEnv: () => void;
453
465
  };
466
+ declare const shouldSkipSetupAndTeardown: () => boolean | "";
454
467
 
455
468
  interface LoginProps {
456
469
  page: Page;
@@ -462,6 +475,32 @@ declare const login: ({ page, neetoPlaywrightUtilities, loginPath, }: LoginProps
462
475
 
463
476
  declare const extractSubdomainFromError: (errorString: string) => string;
464
477
 
478
+ interface AddMemberProps {
479
+ email: string;
480
+ role?: string;
481
+ appName: string;
482
+ requestCount?: number;
483
+ neetoPlaywrightUtilities: CustomCommands;
484
+ }
485
+ interface EditMemberProps {
486
+ email: string;
487
+ firstName?: string;
488
+ lastName?: string;
489
+ newRole?: string;
490
+ requestCount?: number;
491
+ neetoPlaywrightUtilities: CustomCommands;
492
+ }
493
+ interface DeactiveMemberProps {
494
+ email: string;
495
+ neetoPlaywrightUtilities: CustomCommands;
496
+ requestCount?: number;
497
+ }
498
+ declare const memberUtils: {
499
+ addMemberViaRequest: ({ email, role, appName, neetoPlaywrightUtilities, }: AddMemberProps) => Promise<playwright_core.APIResponse | undefined>;
500
+ editMemberViaRequest: ({ email, firstName, lastName, newRole, neetoPlaywrightUtilities, }: EditMemberProps) => Promise<void>;
501
+ deactivateMemberViaRequest: ({ email, neetoPlaywrightUtilities, }: DeactiveMemberProps) => Promise<playwright_core.APIResponse | undefined>;
502
+ };
503
+
465
504
  interface CurrentsOverrides {
466
505
  projectId: string;
467
506
  }
@@ -474,4 +513,4 @@ interface Overrides {
474
513
  }
475
514
  declare const definePlaywrightConfig: (overrides: Overrides) => _playwright_test.PlaywrightTestConfig<{}, {}>;
476
515
 
477
- export { BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, type CustomFixture, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, readFileSyncIfExists, skipTest, updateCredentials, writeDataToFile };
516
+ export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, type CustomFixture, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, updateCredentials, writeDataToFile };
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import test, { expect, test as test$1, defineConfig, devices } from '@playwright/test';
2
2
  import * as require$$0 from 'fs';
3
3
  import require$$0__default from 'fs';
4
- import { isEmpty as isEmpty$1, isNil, isNotNil, mergeDeepLeft, mergeAll, mergeLeft } from 'ramda';
4
+ import { isEmpty as isEmpty$1, isNil, isNotNil, mergeDeepLeft, mergeAll } from 'ramda';
5
5
  import { faker } from '@faker-js/faker';
6
6
  import MailosaurClient from 'mailosaur';
7
7
  import dayjs from 'dayjs';
@@ -44,6 +44,7 @@ const readFileSyncIfExists = (path = STORAGE_STATE) => {
44
44
  return {};
45
45
  }
46
46
  };
47
+ const getGlobalUserState = () => { var _a; return (_a = readFileSyncIfExists()) === null || _a === void 0 ? void 0 : _a.user; };
47
48
  const writeDataToFile = data => {
48
49
  try {
49
50
  require$$0.writeFileSync(STORAGE_STATE, data, "utf8");
@@ -58,13 +59,18 @@ const updateCredentials = ({ key, value }) => {
58
59
  data["user"][key] = value;
59
60
  return writeDataToFile(JSON.stringify(data));
60
61
  };
61
- const clearCredentials = () => {
62
+ const removeCredentialFile = () => {
62
63
  require$$0.unlink(STORAGE_STATE, error => {
63
64
  if (!error)
64
65
  return;
65
66
  console.log(error); // eslint-disable-line
66
67
  });
67
68
  };
69
+ const clearCredentials = () => {
70
+ if (shouldSkipSetupAndTeardown())
71
+ return;
72
+ removeCredentialFile();
73
+ };
68
74
  const hyphenize = input => {
69
75
  const fallbackString = "";
70
76
  if (typeof input === "number")
@@ -84,6 +90,7 @@ const skipTest = {
84
90
  forReviewEnv: () => test.skip(process.env.TEST_ENV === ENVIRONMENT.review),
85
91
  forAllExceptStagingEnv: () => test.skip(process.env.TEST_ENV !== ENVIRONMENT.staging),
86
92
  };
93
+ const shouldSkipSetupAndTeardown = () => { var _a; return ((_a = getGlobalUserState()) === null || _a === void 0 ? void 0 : _a.isLoggedIn) && process.env.SKIP_SETUP === "true"; };
87
94
 
88
95
  const COMMON_SELECTORS = {
89
96
  spinner: ".neeto-ui-spinner",
@@ -7157,11 +7164,22 @@ const ROUTES = {
7157
7164
  show: (id) => `/team_members/teams/${id}`,
7158
7165
  },
7159
7166
  };
7167
+ const API_ROUTES = {
7168
+ teamMembers: {
7169
+ all: "/team_members*/**",
7170
+ bulkUpdate: "/team_members/teams/bulk_update",
7171
+ index: "/team_members/teams",
7172
+ show: (id) => `/team_members/teams/${id}`,
7173
+ },
7174
+ };
7160
7175
 
7161
7176
  const CHAT_WIDGET_TEXTS = {
7162
7177
  newConversation: "New Conversation",
7163
7178
  welcomeChatBubble: "Hi! I'm here to assist you with any questions you may have. What can I do for you?",
7164
7179
  };
7180
+ const MEMBER_TEXTS = {
7181
+ agent: "Agent",
7182
+ };
7165
7183
 
7166
7184
  const HELP_CENTER_SELECTORS = {
7167
7185
  helpButton: "help-button",
@@ -7396,6 +7414,8 @@ class HelpAndProfilePage {
7396
7414
  }));
7397
7415
  };
7398
7416
  this.verifyLogout = async () => {
7417
+ if (shouldSkipSetupAndTeardown())
7418
+ return;
7399
7419
  await test$1.step("Step 1: Open Profile popup and verify", this.openProfilePopup);
7400
7420
  await test$1.step("Step 2: Click logout and verify", async () => {
7401
7421
  await this.page
@@ -7441,9 +7461,15 @@ const extractSubdomainFromError = (errorString) => {
7441
7461
 
7442
7462
  class OrganizationPage {
7443
7463
  constructor(page, neetoPlaywrightUtilities) {
7464
+ this.baseUrlGenerator = (appName) => {
7465
+ const { subdomainName } = getGlobalUserState();
7466
+ return `https://${subdomainName}.${appName}.net`;
7467
+ };
7444
7468
  this.createOrganization = async ({ email, businessName, subdomainName, firstName, lastName, appName, }) => {
7445
7469
  if (!IS_STAGING_ENV)
7446
7470
  return;
7471
+ if (shouldSkipSetupAndTeardown())
7472
+ return;
7447
7473
  const defaultOtp = "123456";
7448
7474
  const appNameInLowerCase = appName.toLowerCase();
7449
7475
  const isNeetoAuth = appNameInLowerCase === "neetoauth";
@@ -7496,6 +7522,8 @@ class OrganizationPage {
7496
7522
  this.setupOrganization = async (product) => {
7497
7523
  if (!IS_STAGING_ENV)
7498
7524
  return;
7525
+ if (shouldSkipSetupAndTeardown())
7526
+ return;
7499
7527
  const { user } = readFileSyncIfExists();
7500
7528
  await this.createOrganization({
7501
7529
  businessName: user.businessName,
@@ -7513,6 +7541,11 @@ class OrganizationPage {
7513
7541
  userCredentials,
7514
7542
  ]);
7515
7543
  writeDataToFile(JSON.stringify(mergedCredentials, null, 2));
7544
+ updateCredentials({ key: "isLoggedIn", value: "true" });
7545
+ updateCredentials({
7546
+ key: "baseUrl",
7547
+ value: this.baseUrlGenerator(`neeto${product}`),
7548
+ });
7516
7549
  };
7517
7550
  this.updateSubdomainIfExists = async (appName) => {
7518
7551
  const subdomainError = this.page.getByTestId(SIGNUP_SELECTORS.subdomainError);
@@ -7534,8 +7567,7 @@ class OrganizationPage {
7534
7567
  key: "businessName",
7535
7568
  value: newOrganizationName,
7536
7569
  });
7537
- const newBaseUrl = `https://${newOrganizationName}.${appName}.net`;
7538
- process.env.BASE_URL = newBaseUrl;
7570
+ process.env.BASE_URL = this.baseUrlGenerator(appName);
7539
7571
  await this.page
7540
7572
  .getByTestId(SIGNUP_SELECTORS.organizationNameTextField)
7541
7573
  .fill(newOrganizationName);
@@ -7679,17 +7711,35 @@ const MERGE_TAGS_SELECTORS = {
7679
7711
  };
7680
7712
 
7681
7713
  const initializeCredentials = (product) => {
7682
- const { user } = readFileSyncIfExists();
7714
+ var _a;
7715
+ if (process.env.SKIP_SETUP === "true" && getGlobalUserState()) {
7716
+ const { email } = getGlobalUserState();
7717
+ if (IS_STAGING_ENV) {
7718
+ email.endsWith("example.com") && removeCredentialFile();
7719
+ }
7720
+ else {
7721
+ email.endsWith("bigbinary.com") && removeCredentialFile();
7722
+ }
7723
+ readFileSyncIfExists();
7724
+ }
7725
+ const skipSetup = shouldSkipSetupAndTeardown();
7726
+ if (skipSetup) {
7727
+ if (IS_STAGING_ENV) {
7728
+ process.env.BASE_URL = (_a = getGlobalUserState()) === null || _a === void 0 ? void 0 : _a.baseUrl;
7729
+ }
7730
+ return;
7731
+ }
7683
7732
  const stagingData = generateStagingData(product);
7684
- const newUserState = mergeLeft(user, stagingData);
7685
- writeDataToFile(JSON.stringify({ user: newUserState }, null, 2));
7733
+ writeDataToFile(JSON.stringify({ user: stagingData }, null, 2));
7686
7734
  if (IS_STAGING_ENV) {
7687
- const baseUrl = `https://${newUserState.subdomainName}.${stagingData.domain}`;
7735
+ const baseUrl = `https://${stagingData.subdomainName}.${stagingData.domain}`;
7688
7736
  process.env.BASE_URL = baseUrl;
7689
7737
  }
7690
7738
  };
7691
7739
 
7692
7740
  const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, loginPath = "/", }) => {
7741
+ if (shouldSkipSetupAndTeardown())
7742
+ return;
7693
7743
  await page.goto(loginPath);
7694
7744
  await page.getByTestId("login-email-text-field").fill(CREDENTIALS.email);
7695
7745
  await page
@@ -7704,10 +7754,57 @@ const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, loginPath = "/"
7704
7754
  await page.context().storageState({ path: STORAGE_STATE });
7705
7755
  const mergedCredentials = mergeAll([readFileSyncIfExists(), userCredentials]);
7706
7756
  writeDataToFile(JSON.stringify(mergedCredentials, null, 2));
7757
+ updateCredentials({ key: "isLoggedIn", value: "true" });
7707
7758
  };
7708
7759
  const login = async ({ page, neetoPlaywrightUtilities, loginPath, }) => !IS_STAGING_ENV &&
7709
7760
  (await loginWithoutSSO({ page, neetoPlaywrightUtilities, loginPath }));
7710
7761
 
7762
+ const addMemberViaRequest = ({ email, role = MEMBER_TEXTS.agent, appName, neetoPlaywrightUtilities, }) => neetoPlaywrightUtilities.apiRequest({
7763
+ method: "post",
7764
+ url: API_ROUTES.teamMembers.index,
7765
+ body: {
7766
+ user: {
7767
+ emails: [email],
7768
+ organization_role: role,
7769
+ app_roles: [{ app_name: appName, active_role: role, is_enabled: true }],
7770
+ },
7771
+ },
7772
+ });
7773
+ const editMemberViaRequest = async ({ email, firstName, lastName, newRole, neetoPlaywrightUtilities, }) => {
7774
+ const response = await neetoPlaywrightUtilities.apiRequest({
7775
+ method: "get",
7776
+ url: API_ROUTES.teamMembers.index,
7777
+ params: { search: email },
7778
+ });
7779
+ if (response) {
7780
+ const responseBodyBuffer = await response.body();
7781
+ const responseBody = JSON.parse(responseBodyBuffer.toString());
7782
+ const memberDetails = responseBody === null || responseBody === void 0 ? void 0 : responseBody.members[0];
7783
+ await neetoPlaywrightUtilities.apiRequest({
7784
+ method: "put",
7785
+ url: API_ROUTES.teamMembers.show(memberDetails.id),
7786
+ body: {
7787
+ team: {
7788
+ active: true,
7789
+ first_name: firstName,
7790
+ last_name: lastName,
7791
+ organization_role: newRole,
7792
+ },
7793
+ },
7794
+ });
7795
+ }
7796
+ };
7797
+ const deactivateMemberViaRequest = ({ email, neetoPlaywrightUtilities, }) => neetoPlaywrightUtilities.apiRequest({
7798
+ method: "patch",
7799
+ url: API_ROUTES.teamMembers.bulkUpdate,
7800
+ body: { users: { active: false, emails: [email] } },
7801
+ });
7802
+ const memberUtils = {
7803
+ addMemberViaRequest,
7804
+ editMemberViaRequest,
7805
+ deactivateMemberViaRequest,
7806
+ };
7807
+
7711
7808
  var main$2 = {exports: {}};
7712
7809
 
7713
7810
  var name = "dotenv";
@@ -8244,5 +8341,5 @@ const definePlaywrightConfig = (overrides) => {
8244
8341
  });
8245
8342
  };
8246
8343
 
8247
- export { BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, readFileSyncIfExists, skipTest, updateCredentials, writeDataToFile };
8344
+ export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, updateCredentials, writeDataToFile };
8248
8345
  //# sourceMappingURL=index.js.map