Repository: wix/Detox
Pull request #2577 (2021-01-07 10:59:25)

Further improve genycloud logging, by a little
Description
(Yet another) Genymotion-cloud work tech debt (#2429): Improve logging + code-notes just a tad further , following #2575.



Patch:
diff --git a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js
index 5beff6764..553d95ab6 100644
--- a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js
+++ b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.js
@@ -23,10 +23,7 @@ class GenyRecipesService {
   }
 
   async getRecipeByUUID(uuid) {
-    return new Recipe({
-      uuid,
-      name: `Recipe of ${uuid}`,
-    });
+    return new Recipe({ uuid });
   }
 }
 
diff --git a/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js b/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js
index 406870fff..44435a47e 100644
--- a/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js
+++ b/detox/src/devices/drivers/android/genycloud/services/dto/GenyInstance.js
@@ -14,6 +14,18 @@ class GenyInstance {
   constructor(rawInstance) {
     this.uuid = rawInstance.uuid;
     this.name = rawInstance.name;
+
+    /**
+     * According to Genymotion's API docs, state is an enum with these possible values (description is not official):
+     * - "CREATING": Handling instance creation request
+     * - "STARTING": Instance created but not yet available for usage
+     * - "BOOTING": Instance created & started; Android OS is not booting
+     * - "ONLINE": Instance is ready for action
+     * - "RECYCLED": Instance has been automatically shut down due an idle timeout
+     * - "STOPPING": Instance is being shut-down
+     *
+     * Additional states: "OFFLINE", "SAVING", "SAVED", "DELETING", "ERROR", "REVOKED", "EXPIRED".
+     */
     this.state = rawInstance.state;
     this.adb = {
       name: rawInstance.adb_serial,
diff --git a/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.js b/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.js
index 792d692e2..833b551a7 100644
--- a/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.js
+++ b/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.js
@@ -1,11 +1,12 @@
 class GenyRecipe {
   constructor(rawRecipe) {
     this.uuid = rawRecipe.uuid;
-    this.name = rawRecipe.name;
+    this.name = rawRecipe.name || 'Anonymous GMSaaS Recipe';
+    this._description = (rawRecipe.name ? `${this.name} (${this.uuid})` : `Recipe of ${this.uuid}`);
   }
 
   toString() {
-    return this.name;
+    return this._description;
   }
 }
 


Test patch:
diff --git a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js
index 0d5da2a10..c4c90f114 100644
--- a/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js
+++ b/detox/src/devices/drivers/android/genycloud/services/GenyRecipesService.test.js
@@ -18,7 +18,7 @@ describe('Genymotion-Cloud recipes service', () => {
 
   const anotherRecipe = () => ({
     uuid: 'another-mock-recipe-uuid',
-    name: 'mock-recipe-name',
+    name: 'another-mock-recipe-name',
   });
 
   let logger;
@@ -46,7 +46,9 @@ describe('Genymotion-Cloud recipes service', () => {
       const recipe2 = anotherRecipe();
       givenRecipes(recipe, recipe2);
 
-      expect(await uut.getRecipeByName(recipe.name)).toEqual(recipe);
+      const result = await uut.getRecipeByName(recipe.name);
+
+      expect(result.uuid).toEqual(recipe.uuid);
     });
 
     it('should return a recipe DTO', async () => {
@@ -92,7 +94,6 @@ describe('Genymotion-Cloud recipes service', () => {
       const result = await uut.getRecipeByUUID(recipe.uuid);
 
       expect(result.uuid).toEqual(recipe.uuid);
-      expect(result.name).toEqual(`Recipe of ${recipe.uuid}`);
       expect(result.constructor.name).toContain('Recipe');
     });
   });
diff --git a/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.test.js b/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.test.js
index b2279f0f8..34ba8ba8c 100644
--- a/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.test.js
+++ b/detox/src/devices/drivers/android/genycloud/services/dto/GenyRecipe.test.js
@@ -1,26 +1,37 @@
 describe('Genymotion-Cloud Recipe DTO', () => {
-  it('should have a uuid', () => {
-    const rawRecipe = {
-      uuid: 'mock-uuid',
-      name: 'mock-name',
-    };
+  const rawRecipe = {
+    uuid: 'mock-uuid',
+    name: 'mock-name',
+  };
+
+  let Recipe;
+  beforeEach(() => {
+    Recipe = require('./GenyRecipe');
+  });
 
-    const Recipe = require('./GenyRecipe');
+  it('should have a uuid', () => {
     const recipe = new Recipe(rawRecipe);
 
     expect(recipe.uuid).toEqual('mock-uuid');
     expect(recipe.name).toEqual('mock-name');
   });
 
-  it('should override toString()', () => {
-    const rawRecipe = {
-      uuid: 'mock-uuid',
-      name: 'mock-name',
-    };
+  it('should allow for anonymous (name-less) recipes', () => {
+    const recipe = new Recipe({
+      uuid: rawRecipe.uuid,
+    });
+    expect(recipe.name).toEqual('Anonymous GMSaaS Recipe');
+  });
 
-    const Recipe = require('./GenyRecipe');
+  it('should override toString()', () => {
     const recipe = new Recipe(rawRecipe);
+    expect(recipe.toString()).toEqual('mock-name (mock-uuid)');
+  });
 
-    expect(recipe.toString()).toEqual('mock-name');
+  it('should implement toString() for anonymous recipes', () => {
+    const recipe = new Recipe({
+      uuid: rawRecipe.uuid,
+    });
+    expect(recipe.toString()).toEqual('Recipe of mock-uuid');
   });
 });