@spscommerce/e2e-core 1.1.1 → 1.1.2

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.
@@ -1,5 +1,10 @@
1
1
  import fetch from 'node-fetch';
2
- import { authEndpoint } from './envSetup';
2
+
3
+ let authEndpoint = 'https://test.id.spsc.io/';
4
+
5
+ if (process.env.URL && process.env.URL.toLowerCase().includes('prod')) {
6
+ authEndpoint = 'https://id.spsc.io/';
7
+ }
3
8
 
4
9
  export async function getAuthToken(): Promise<string> {
5
10
  if (process.env.USER_EMAIL && process.env.USER_PASSWORD) {
@@ -56,7 +61,10 @@ export async function changePreferredOrg(orgID: string): Promise<void> {
56
61
  email: userData.email,
57
62
  first_name: userData.first_name,
58
63
  last_name: userData.last_name,
59
- preferred_org_id: orgID
64
+ preferred_org_id: orgID,
65
+ organization: {
66
+ id: orgID
67
+ }
60
68
  }),
61
69
  headers: {
62
70
  'Authorization': `Bearer ${process.env.TOKEN}`,
@@ -1,14 +1,21 @@
1
- import { getAuthToken, changePreferredOrg } from './apiCalls';
2
- import { primaryOrgID } from './envSetup';
1
+ import { changePreferredOrg, getAuthToken, getUserInfo } from '../helpers/apiCalls';
3
2
 
4
- export async function authenticate(orgID?: string): Promise<void> {
5
- if (orgID) {
3
+ export async function authenticate(orgID: string): Promise<void> {
4
+ const testSuiteName = expect.getState().testPath.split('/').pop().split('.').reverse()[2];
5
+ process.env.TOKEN = await getAuthToken();
6
+ let userData = await getUserInfo();
7
+ console.log(`${testSuiteName} suite authentication flow:
8
+ Current preferred org: ${userData.preferred_org_id}.
9
+ Current org: ${userData.organization.organization_name}.`);
10
+ while (userData.preferred_org_id !== orgID || userData.organization.id !== orgID) {
6
11
  await changePreferredOrg(orgID);
7
12
  process.env.TOKEN = await getAuthToken();
8
- } else {
9
- await changePreferredOrg(primaryOrgID);
10
- process.env.TOKEN = await getAuthToken();
13
+ userData = await getUserInfo();
14
+ console.log(`${testSuiteName} suite authentication flow:
15
+ Preferred org was changed to: ${userData.preferred_org_id}.
16
+ Current org was changed to: ${userData.organization.organization_name}.`);
11
17
  }
18
+ console.log(process.env.TOKEN);
12
19
  await page.addInitScript(params => {
13
20
  window.localStorage.setItem(params.name, params.value);
14
21
  }, { name: "access_token", value: process.env.TOKEN });
@@ -19,5 +26,7 @@ export async function unauthenticate(): Promise<void> {
19
26
  await context.clearCookies();
20
27
  await context.addInitScript(() => window.localStorage.clear());
21
28
  await context.addInitScript(() => window.sessionStorage.clear());
29
+ await page.goto(process.env.BASEURL);
30
+ await page.waitForURL(/https:\/\/auth.*/);
22
31
  return;
23
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spscommerce/e2e-core",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "An automation test framework which is based on playwright, jest and ts",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -1,9 +0,0 @@
1
- let authEndpoint = 'https://test.id.spsc.io/';
2
- let primaryOrgID = '209098808305562446811265341033453015703'; // SPS Commerce org id on test env
3
-
4
- if (process.env.URL && process.env.URL.toLowerCase().includes('prod')) {
5
- authEndpoint = 'https://id.spsc.io/';
6
- primaryOrgID = '157627141979612915626333577105111854232'; // SPS Commerce org id on prod env
7
- }
8
-
9
- export { authEndpoint, primaryOrgID };