Skip to content

Commit

Permalink
Added detox RN app upload APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
shirish87 committed Jan 31, 2024
1 parent 74aeeb4 commit ffe16e8
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 2 deletions.
117 changes: 117 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,123 @@ paths:
"500":
$ref: '#/components/schemas/5xx.InternalServerError'

/app-automate/detox/v2/android/app:
post:
summary: Upload an app
description: Upload the application under test (AUT) for Detox Android testing.
operationId: uploadAppAutomateDetoxAndroidApp
requestBody:
required: true
content:
multipart/form-data:
schema:
allOf:
- type: object
properties:
custom_id:
type: string
description: >-
Custom ID for the app. Accepted characters are A-Z, a-z, 0-9, ., -, _.
All other characters are ignored. Character limit is 100.
example: "app_1"
- oneOf:
- type: object
required: [file]
properties:
file:
type: string
format: binary
description: >-
Path to the app file on your machine. Supported file formats are .apk and .aab files
for Android and .ipa file for iOS
- type: object
required: [url]
properties:
url:
type: string
description: >-
URL of the app file. Ensure that its a publicly accessible URL as BrowserStack
will attempt to download the app from this location. Supported file formats are
.apk and .aab files for Android and .ipa file for iOS
example: "https://example.com/app.ipa"

responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/AppAutomateApp"

"400":
$ref: '#/components/schemas/400.BadRequest'
"401":
$ref: '#/components/schemas/401.Unauthorized'
"404":
$ref: '#/components/schemas/404.NotFound'
"422":
$ref: '#/components/schemas/422.UnprocessableEntity'
"500":
$ref: '#/components/schemas/5xx.InternalServerError'

/app-automate/detox/v2/android/app-client:
post:
summary: Upload an app client
description: Upload the app client under test for Detox Android testing.
operationId: uploadAppAutomateDetoxAndroidAppClient
requestBody:
required: true
content:
multipart/form-data:
schema:
allOf:
- type: object
properties:
custom_id:
type: string
description: >-
Custom ID for the app. Accepted characters are A-Z, a-z, 0-9, ., -, _.
All other characters are ignored. Character limit is 100.
example: "app_1"
- oneOf:
- type: object
required: [file]
properties:
file:
type: string
format: binary
description: >-
Path to the app file on your machine. Supported file formats are .apk and .aab files
for Android
- type: object
required: [url]
properties:
url:
type: string
description: >-
URL of the app file. Ensure that its a publicly accessible URL as BrowserStack
will attempt to download the app from this location. Supported file formats are
.apk and .aab files for Android
example: "https://example.com/app.apk"

responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/AppAutomateApp"

"400":
$ref: '#/components/schemas/400.BadRequest'
"401":
$ref: '#/components/schemas/401.Unauthorized'
"404":
$ref: '#/components/schemas/404.NotFound'
"422":
$ref: '#/components/schemas/422.UnprocessableEntity'
"500":
$ref: '#/components/schemas/5xx.InternalServerError'

/app-automate/espresso/v2/app:
post:
Expand Down
37 changes: 35 additions & 2 deletions src/__tests__/app-automate.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FlutterPlatform } from "@/app-automate";
import { components } from "@/generated/openapi";
import { zipSync } from "fflate";
import { describe, expect, expectTypeOf, test } from "vitest";
import type { BrowserStackTestContext } from "./setup";
import { FlutterPlatform } from "@/app-automate";
import { zip, zipSync } from "fflate";

describe("AppAutomateClient", () => {

Expand Down Expand Up @@ -607,4 +607,37 @@ describe("AppAutomateClient", () => {
expectTypeOf(data.success.message).toMatchTypeOf<string>();
});
});

describe.skip<BrowserStackTestContext>("Detox Android Apps", (test) => {

test("uploadDetoxApp", async ({
appAutomate: { client },
}) => {
const data = await client.uploadDetoxAndroidApp("app", {
url: "https://github.com/aws-samples/aws-device-farm-sample-app-for-android/raw/master/prebuilt/app-debug-androidTest.apk",
filename: "example.apk",
custom_id: "example-app",
});

expect(data).toBeDefined();
expect(data.app_url).toBeDefined();
expectTypeOf(data.app_url).toMatchTypeOf<string>();
expectTypeOf(data).toMatchTypeOf<components["schemas"]["AppAutomateApp"]>();
});

test("uploadDetoxAppClient", async ({
appAutomate: { client },
}) => {
const data = await client.uploadDetoxAndroidApp("app-client", {
url: "https://github.com/aws-samples/aws-device-farm-sample-app-for-android/raw/master/prebuilt/app-debug-androidTest.apk",
filename: "example.apk",
custom_id: "example-app",
});

expect(data).toBeDefined();
expect(data.app_url).toBeDefined();
expectTypeOf(data.app_url).toMatchTypeOf<string>();
expectTypeOf(data).toMatchTypeOf<components["schemas"]["AppAutomateApp"]>();
});
});
});
38 changes: 38 additions & 0 deletions src/app-automate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,44 @@ export class AppAutomateClient extends APIClient {
},
});
}

uploadDetoxAndroidApp<T extends "app" | "app-client">(
type: T,
body: operations[T extends "app"
? "uploadAppAutomateDetoxAndroidApp"
: "uploadAppAutomateDetoxAndroidAppClient"]["requestBody"]["content"]["multipart/form-data"] & {
filename: string;
},
options?: APIFetchOptions<
operations[T extends "app"
? "uploadAppAutomateDetoxAndroidApp"
: "uploadAppAutomateDetoxAndroidAppClient"]
>
) {
return this.makePostRequest(
type
? "/app-automate/detox/v2/android/app"
: "/app-automate/detox/v2/android/app-client",
{
...options,
body,
bodySerializer: () => {
const formData = new FormData();
if ("file" in body) {
formData.append("file", body.file, body.filename);
} else {
formData.append("url", body.url);
}

if (body.custom_id) {
formData.append("custom_id", body.custom_id);
}

return formData;
},
}
);
}
}

export enum FlutterPlatform {
Expand Down

0 comments on commit ffe16e8

Please sign in to comment.