Repository: wix/Detox
Pull request #4379 (2024-02-22 13:41:51)

Genycloud: Omit preliminary login check
## Description

<!--
Thank you for contributing!

Step 1: Before submitting a pull request that introduces a new functionality or fixes a bug,
please open an issue where we could discuss the suggestion, problem - and potential ways to fix.
-->

- This pull request addresses the issue described here: #4361

<!--
Step 2: Provide an overview of how your fix / enhancement works.
If possible, provide screenshots of the before and after states (even for simple command line options - show the terminal).
-->

In this pull request, I have removed Detox's preliminary check for proper Genymotion-login.

This stems from Genymotion's deprecation of this command in gmsaas `v1.10.0`.
It was a nice-to-have to begin with, so Detox should be fine without it: The error is reported by the `gmsaas` command itself at runtime. It's a subtle degradation of dev-ex, but nothing alarming.

@lilinor @igorgn 

<!--
Step 3: Please review the checklist below.
-->

---


> _For features/enhancements:_
 - [ ] I have added/updated the relevant references in the [documentation](https://github.com/wix/Detox/tree/master/docs) files.

> _For API changes:_
 - [ ] I have made the necessary changes in the [types index](https://github.com/wix/Detox/blob/master/detox/index.d.ts) file.



Patch:
diff --git a/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.js b/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.js
index 3948f7716..fbb775e3f 100644
--- a/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.js
+++ b/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.js
@@ -11,10 +11,6 @@ class GenyCloudExec {
     return this._exec('--version');
   }
 
-  whoAmI() {
-    return this._exec('auth whoami');
-  }
-
   getRecipe(name) {
     return this._exec(`recipes list --name "${name}"`);
   }
diff --git a/detox/src/devices/allocation/drivers/android/genycloud/services/GenyAuthService.js b/detox/src/devices/allocation/drivers/android/genycloud/services/GenyAuthService.js
deleted file mode 100644
index 46aa0fc7f..000000000
--- a/detox/src/devices/allocation/drivers/android/genycloud/services/GenyAuthService.js
+++ /dev/null
@@ -1,12 +0,0 @@
-class GenyAuthService {
-  constructor(genyCloudExec) {
-    this.genyCloudExec = genyCloudExec;
-  }
-
-  async getLoginEmail() {
-    const whoAmI = await this.genyCloudExec.whoAmI();
-    return whoAmI.auth.email;
-  }
-}
-
-module.exports = GenyAuthService;
diff --git a/detox/src/devices/validation/android/GenycloudEnvValidator.js b/detox/src/devices/validation/android/GenycloudEnvValidator.js
index 09f95ae3c..222d9d6f7 100644
--- a/detox/src/devices/validation/android/GenycloudEnvValidator.js
+++ b/detox/src/devices/validation/android/GenycloudEnvValidator.js
@@ -12,15 +12,13 @@ class GenycloudEnvValidator extends EnvironmentValidatorBase {
    * @param authService { GenyAuthService }
    * @param exec { GenyCloudExec }
    */
-  constructor({ authService, exec }) {
+  constructor({ exec }) {
     super();
-    this._authService = authService;
     this._exec = exec;
   }
 
   async validate() {
     await this._validateGmsaasVersion();
-    await this._validateGmsaasAuth();
   }
 
   async _validateGmsaasVersion() {
@@ -32,15 +30,6 @@ class GenycloudEnvValidator extends EnvironmentValidatorBase {
       });
     }
   }
-
-  async _validateGmsaasAuth() {
-    if (!await this._authService.getLoginEmail()) {
-      throw new DetoxRuntimeError({
-        message: `Cannot run tests using 'android.genycloud' type devices, because Genymotion was not logged-in to!`,
-        hint: `Log-in to Genymotion-cloud by running this command (and following instructions):\n${environment.getGmsaasPath()} auth login --help`,
-      });
-    }
-  }
 }
 
 module.exports = GenycloudEnvValidator;
diff --git a/detox/src/devices/validation/factories/index.js b/detox/src/devices/validation/factories/index.js
index 0aa2f7a4f..1b8c970b7 100644
--- a/detox/src/devices/validation/factories/index.js
+++ b/detox/src/devices/validation/factories/index.js
@@ -7,11 +7,8 @@ class Genycloud extends EnvValidatorFactory {
     const serviceLocator = require('../../servicelocator/android');
     const exec = serviceLocator.genycloud.exec;
 
-    const GenyAuthService = require('../../allocation/drivers/android/genycloud/services/GenyAuthService');
-    const authService = new GenyAuthService(exec);
-
     const GenycloudEnvValidator = require('../android/GenycloudEnvValidator');
-    return new GenycloudEnvValidator({ authService, exec });
+    return new GenycloudEnvValidator({ exec });
   }
 }
 


Test patch:
diff --git a/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.test.js b/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.test.js
index de1deb55b..6ec76c111 100644
--- a/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.test.js
+++ b/detox/src/devices/allocation/drivers/android/genycloud/exec/GenyCloudExec.test.js
@@ -42,7 +42,6 @@ describe('Genymotion-cloud executable', () => {
 
   describe.each([
     ['version', () => uut.getVersion(), `"mock/path/to/gmsaas" --format compactjson --version`],
-    ['whoami', () => uut.whoAmI(), `"mock/path/to/gmsaas" --format compactjson auth whoami`],
     ['Get Recipe', () => uut.getRecipe(recipeName), `"mock/path/to/gmsaas" --format compactjson recipes list --name "${recipeName}"`],
     ['Get Instance', () => uut.getInstance(instanceUUID), `"mock/path/to/gmsaas" --format compactjson instances get ${instanceUUID}`],
     ['Get Instances', () => uut.getInstances(), `"mock/path/to/gmsaas" --format compactjson instances list -q`],
diff --git a/detox/src/devices/allocation/drivers/android/genycloud/services/GenyAuthService.test.js b/detox/src/devices/allocation/drivers/android/genycloud/services/GenyAuthService.test.js
deleted file mode 100644
index 2220121f8..000000000
--- a/detox/src/devices/allocation/drivers/android/genycloud/services/GenyAuthService.test.js
+++ /dev/null
@@ -1,32 +0,0 @@
-describe('Genymotion-cloud authentication service', () => {
-  let exec;
-  let uut;
-  beforeEach(() => {
-    const GenyCloudExec = jest.genMockFromModule('../exec/GenyCloudExec');
-    exec = new GenyCloudExec();
-
-    const GenyAuthService = require('./GenyAuthService');
-    uut = new GenyAuthService(exec);
-  });
-
-  const givenLoginEmail = (email) => exec.whoAmI.mockResolvedValue({
-    auth: {
-      email,
-    },
-  });
-  const givenLoggedOut = () => givenLoginEmail(null);
-
-  it('should return logged-in user email', async () => {
-    givenLoginEmail('mock@wix.com');
-
-    const result = await uut.getLoginEmail();
-    expect(result).toEqual('mock@wix.com');
-  });
-
-  it('should return null if logged-out', async () => {
-    givenLoggedOut();
-
-    const result = await uut.getLoginEmail();
-    expect(result).toEqual(null);
-  });
-});
diff --git a/detox/src/devices/validation/android/GenycloudEnvValidator.test.js b/detox/src/devices/validation/android/GenycloudEnvValidator.test.js
index 28d3e0fdf..3bda2d807 100644
--- a/detox/src/devices/validation/android/GenycloudEnvValidator.test.js
+++ b/detox/src/devices/validation/android/GenycloudEnvValidator.test.js
@@ -4,7 +4,6 @@ describe('Genymotion-cloud test environment validator', () => {
   const MOCK_GMSAAS_PATH = '/path/to/gmsaas';
 
   let exec;
-  let authService;
   let uut;
   beforeEach(() => {
     jest.mock('../../../utils/environment');
@@ -15,20 +14,14 @@ describe('Genymotion-cloud test environment validator', () => {
     const GenyExec = jest.genMockFromModule('../../allocation/drivers/android/genycloud/exec/GenyCloudExec');
     exec = new GenyExec();
 
-    const GenyAuthService = jest.genMockFromModule('../../allocation/drivers/android/genycloud/services/GenyAuthService');
-    authService = new GenyAuthService();
-
     const GenycloudEnvValidator = require('./GenycloudEnvValidator');
-    uut = new GenycloudEnvValidator({ authService, exec });
+    uut = new GenycloudEnvValidator({ exec });
   });
 
-  const givenProperGmsaasLogin = () => authService.getLoginEmail.mockResolvedValue('detox@wix.com');
-  const givenGmsaasLoggedOut = () => authService.getLoginEmail.mockResolvedValue(null);
   const givenGmsaasExecVersion = (version) => exec.getVersion.mockResolvedValue({ version });
   const givenProperGmsaasExecVersion = () => givenGmsaasExecVersion('1.6.0');
 
   it('should throw an error if gmsaas exec is too old (minor version < 6)', async () => {
-    givenProperGmsaasLogin();
     givenGmsaasExecVersion('1.5.9');
 
     try {
@@ -43,19 +36,16 @@ describe('Genymotion-cloud test environment validator', () => {
   });
 
   it('should accept the gmsaas exec if version is sufficiently new', async () => {
-    givenProperGmsaasLogin();
     givenGmsaasExecVersion('1.6.0');
     await uut.validate();
   });
 
   it('should accept the gmsaas exec if version is more than sufficiently new', async () => {
-    givenProperGmsaasLogin();
     givenGmsaasExecVersion('1.7.2');
     await uut.validate();
   });
 
   it('should throw an error if gmsaas exec is too old (major version < 1)', async () => {
-    givenProperGmsaasLogin();
     givenGmsaasExecVersion('0.6.0');
 
     await expect(uut.validate())
@@ -63,24 +53,8 @@ describe('Genymotion-cloud test environment validator', () => {
       .toThrowError(`Your Genymotion-Cloud executable (found in ${MOCK_GMSAAS_PATH}) is too old! (version 0.6.0)`);
   });
 
-  it('should throw an error if not logged-in to gmsaas', async () => {
-    givenProperGmsaasExecVersion();
-    givenGmsaasLoggedOut();
-
-    try {
-      await uut.validate();
-    } catch (e) {
-      expect(e.constructor.name).toEqual('DetoxRuntimeError');
-      expect(e.toString()).toContain(`Cannot run tests using 'android.genycloud' type devices, because Genymotion was not logged-in to!`);
-      expect(e.toString()).toContain(`HINT: Log-in to Genymotion-cloud by running this command (and following instructions):\n${MOCK_GMSAAS_PATH} auth login --help`);
-      return;
-    }
-    throw new Error('Expected an error');
-  });
-
   it('should not throw an error if properly logged in to gmsaas', async () => {
     givenProperGmsaasExecVersion();
-    givenProperGmsaasLogin();
     await uut.validate();
   });
 });