Repository: saucelabs/node-saucelabs
Pull request #58 (2019-04-23 14:50:31)

Add create sub account endpoint
Seems this endpoint is missing. Tested it with:

```js
const SauceLabs = require('./build').default

const api = new SauceLabs()
api.getSubaccounts('cb-onboarding').then(
    (subaccounts) => console.log(subaccounts),
    (err) => console.error(err))
```



Patch:
diff --git a/README.md b/README.md
index 334957f..9bb961c 100644
--- a/README.md
+++ b/README.md
@@ -132,7 +132,7 @@ import SauceLabs from 'saucelabs';
             breakpointed: null,
             browser: 'googlechrome' } ] }
      */
-})
+})()
 ```
 
 ## Test
diff --git a/apis/sauce.json b/apis/sauce.json
index f973547..129b357 100644
--- a/apis/sauce.json
+++ b/apis/sauce.json
@@ -1757,6 +1757,40 @@
         ]
       }
     },
+    "/v1/users/{username}/subaccounts": {
+      "get": {
+        "operationId": "get_subaccounts",
+        "parameters": [
+          {
+            "$ref": "#/parameters/username"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "User",
+            "schema": {
+              "$ref": "#/definitions/User"
+            }
+          },
+          "404": {
+            "description": "User is not found",
+            "schema": {
+              "$ref": "#/definitions/Error"
+            }
+          },
+          "default": {
+            "description": "Unexpected error",
+            "schema": {
+              "$ref": "#/definitions/Error"
+            }
+          }
+        },
+        "summary": "User information",
+        "tags": [
+          "User"
+        ]
+      }
+    },
     "/v1/users/{username}/activity": {
       "get": {
         "operationId": "get_user_activity",
diff --git a/src/constants.js b/src/constants.js
index 8ddc078..7e8ad3b 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -60,7 +60,9 @@ export const DEFAULT_OPTIONS = {
 
 export const REGION_MAPPING = {
     'us': 'us-west-1.', // default endpoint
-    'eu': 'eu-central-1.'
+    'eu': 'eu-central-1.',
+    'us-west-1': 'us-west-1.',
+    'eu-central-1': 'eu-central-1.'
 }
 
 export const SYMBOL_INSPECT = Symbol.for('nodejs.util.inspect.custom')
diff --git a/src/utils.js b/src/utils.js
index bb832e3..acd659a 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -47,6 +47,8 @@ export function getSauceEndpoint (hostname, region, headless, protocol = 'https:
         locale = hostname.includes('testobject') ? '' : locale
     } else if (!headless && region === 'us') {
         locale = ''
+    } else if (locale === 'us-west-1.') { // us-west-1 is currently not a valid endpoint for Sauce
+        locale = ''
     }
 
     return protocol + subdomain + locale + hostname


Test patch:
diff --git a/tests/utils.test.js b/tests/utils.test.js
index 8958a7f..a67f201 100644
--- a/tests/utils.test.js
+++ b/tests/utils.test.js
@@ -8,12 +8,16 @@ test('createHMAC', async () => {
 test('getSauceEndpoint', () => {
     expect(getSauceEndpoint('saucelabs.com', 'us', false))
         .toBe('https://saucelabs.com')
+    expect(getSauceEndpoint('saucelabs.com', 'us-west-1', false))
+        .toBe('https://saucelabs.com')
     expect(getSauceEndpoint('saucelabs.com', 'I_DONT_EXIST', false))
-        .toBe('https://us-west-1.saucelabs.com')
+        .toBe('https://saucelabs.com')
     expect(getSauceEndpoint('saucelabs.com', 'us', false, 'http://'))
         .toBe('http://saucelabs.com')
     expect(getSauceEndpoint('saucelabs.com', 'eu', false))
         .toBe('https://eu-central-1.saucelabs.com')
+    expect(getSauceEndpoint('saucelabs.com', 'eu-central-1', false))
+        .toBe('https://eu-central-1.saucelabs.com')
     expect(getSauceEndpoint('saucelabs.com', 'us', true))
         .toBe('https://us-east-1.saucelabs.com')
     expect(getSauceEndpoint('api.saucelabs.com', 'us', false))