Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 28 additions & 36 deletions src/appdistribution/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("distribution", () => {
expect(nock.isDone()).to.be.true;
});

it("should resolve with ListTestersResponse when request succeeds - no filter", async () => {
it("should resolve with array of testers when request succeeds - no filter", async () => {
const testerListing = [
{
name: "tester_1",
Expand All @@ -119,22 +119,20 @@ describe("distribution", () => {
nock(appDistributionOrigin()).get(`/v1/${projectName}/testers`).reply(200, {
testers: testerListing,
});
await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq({
testers: [
{
name: "tester_1",
displayName: "Tester 1",
groups: [],
lastActivityTime: new Date("2024-08-27T02:37:19.539865Z"),
},
{
name: "tester_2",
displayName: "Tester 2",
groups: [`${projectName}/groups/beta-team`, `${projectName}/groups/alpha-team`],
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
},
],
});
await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq([
{
name: "tester_1",
displayName: "Tester 1",
groups: [],
lastActivityTime: new Date("2024-08-27T02:37:19.539865Z"),
},
{
name: "tester_2",
displayName: "Tester 2",
groups: [`${projectName}/groups/beta-team`, `${projectName}/groups/alpha-team`],
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
},
]);
expect(nock.isDone()).to.be.true;
});

Expand All @@ -157,25 +155,21 @@ describe("distribution", () => {
});
await expect(
appDistributionClient.listTesters(projectName, "beta-team"),
).to.eventually.deep.eq({
testers: [
{
name: "tester_2",
displayName: "Tester 2",
groups: [`${projectName}/groups/beta-team`],
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
},
],
});
).to.eventually.deep.eq([
{
name: "tester_2",
displayName: "Tester 2",
groups: [`${projectName}/groups/beta-team`],
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
},
]);
expect(nock.isDone()).to.be.true;
});

it("should gracefully handle no testers", async () => {
nock(appDistributionOrigin()).get(`/v1/${projectName}/testers`).reply(200, {});

await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq({
testers: [],
});
await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq([]);
expect(nock.isDone()).to.be.true;
});
});
Expand Down Expand Up @@ -403,8 +397,8 @@ describe("distribution", () => {
expect(nock.isDone()).to.be.true;
});

it("should resolve with ListGroupsResponse when request succeeds", async () => {
const groupListing: Group[] = [
it("should resolve with array of groups when request succeeds", async () => {
const groups: Group[] = [
{
name: "group_1",
displayName: "Group 1",
Expand All @@ -419,11 +413,9 @@ describe("distribution", () => {
];

nock(appDistributionOrigin()).get(`/v1/${projectName}/groups`).reply(200, {
groups: groupListing,
});
await expect(appDistributionClient.listGroups(projectName)).to.eventually.deep.eq({
groups: groupListing,
groups: groups,
});
await expect(appDistributionClient.listGroups(projectName)).to.eventually.deep.eq(groups);
expect(nock.isDone()).to.be.true;
});
});
Expand Down
28 changes: 10 additions & 18 deletions src/appdistribution/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
mapDeviceToExecution,
ReleaseTest,
TestDevice,
Tester,
UploadReleaseResponse,
} from "./types";

Expand Down Expand Up @@ -110,15 +111,15 @@

try {
await this.appDistroV1Client.post(`/${releaseName}:distribute`, data);
} catch (err: any) {

Check warning on line 114 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
let errorMessage = err.message;

Check warning on line 115 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value

Check warning on line 115 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const errorStatus = err?.context?.body?.error?.status;

Check warning on line 116 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .context on an `any` value

Check warning on line 116 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
if (errorStatus === "FAILED_PRECONDITION") {
errorMessage = "invalid testers";
} else if (errorStatus === "INVALID_ARGUMENT") {
errorMessage = "invalid groups";
}
throw new FirebaseError(`failed to distribute to testers/groups: ${errorMessage}`, {

Check warning on line 122 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
exit: 1,
});
}
Expand All @@ -126,17 +127,12 @@
utils.logSuccess("distributed to testers/groups successfully");
}

async listTesters(projectName: string, groupName?: string): Promise<ListTestersResponse> {
const listTestersResponse: ListTestersResponse = {
testers: [],
};

async listTesters(projectName: string, groupName?: string): Promise<Tester[]> {
const testers: Tester[] = [];
const client = this.appDistroV1Client;

let pageToken: string | undefined;

const filter = groupName ? `groups=${projectName}/groups/${groupName}` : null;

let pageToken: string | undefined;
do {
const queryParams: Record<string, string> = pageToken ? { pageToken } : {};
if (filter != null) {
Expand All @@ -149,11 +145,11 @@
queryParams,
});
} catch (err) {
throw new FirebaseError(`Client request failed to list testers ${err}`);

Check warning on line 148 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "unknown" of template literal expression
}

for (const t of apiResponse.body.testers ?? []) {
listTestersResponse.testers.push({
testers.push({
name: t.name,
displayName: t.displayName,
groups: t.groups,
Expand All @@ -163,7 +159,7 @@

pageToken = apiResponse.body.nextPageToken;
} while (pageToken);
return listTestersResponse;
return testers;
}

async addTesters(projectName: string, emails: string[]): Promise<void> {
Expand Down Expand Up @@ -197,28 +193,24 @@
return apiResponse.body;
}

async listGroups(projectName: string): Promise<ListGroupsResponse> {
const listGroupsResponse: ListGroupsResponse = {
groups: [],
};

async listGroups(projectName: string): Promise<Group[]> {
const groups: Group[] = [];
const client = this.appDistroV1Client;

let pageToken: string | undefined;

do {
const queryParams: Record<string, string> = pageToken ? { pageToken } : {};
try {
const apiResponse = await client.get<ListGroupsResponse>(`${projectName}/groups`, {
queryParams,
});
listGroupsResponse.groups.push(...(apiResponse.body.groups ?? []));
groups.push(...(apiResponse.body.groups ?? []));
pageToken = apiResponse.body.nextPageToken;
} catch (err) {
throw new FirebaseError(`Client failed to list groups ${err}`);

Check warning on line 210 in src/appdistribution/client.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "unknown" of template literal expression
}
} while (pageToken);
return listGroupsResponse;
return groups;
}

async createGroup(projectName: string, displayName: string, alias?: string): Promise<Group> {
Expand Down
7 changes: 3 additions & 4 deletions src/commands/appdistribution-groups-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@
.action(async (options?: Options): Promise<ListGroupsResponse> => {
const projectName = await getProjectName(options);
const appDistroClient = new AppDistributionClient();
let groupsResponse: ListGroupsResponse;
let groups: Group[];
const spinner = ora("Preparing the list of your App Distribution Groups").start();
try {
groupsResponse = await appDistroClient.listGroups(projectName);
groups = await appDistroClient.listGroups(projectName);
} catch (err: any) {

Check warning on line 24 in src/commands/appdistribution-groups-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
spinner.fail();
throw new FirebaseError("Failed to list groups.", {
exit: 1,
original: err,

Check warning on line 28 in src/commands/appdistribution-groups-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
});
}
spinner.succeed();
const groups = groupsResponse.groups ?? [];
printGroupsTable(groups);
utils.logSuccess(`Groups listed successfully`);
return groupsResponse;
return { groups };
});

/**
Expand Down
7 changes: 3 additions & 4 deletions src/commands/appdistribution-testers-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const command = new Command("appdistribution:testers:list [group]")
.action(async (group: string | undefined, options: Options): Promise<ListTestersResponse> => {
const projectName = await getProjectName(options);
const appDistroClient = new AppDistributionClient();
let testersResponse: ListTestersResponse;
let testers: Tester[];
const spinner = ora("Preparing the list of your App Distribution testers").start();
try {
testersResponse = await appDistroClient.listTesters(projectName, group);
testers = await appDistroClient.listTesters(projectName, group);
} catch (err: any) {
spinner.fail();
throw new FirebaseError("Failed to list testers.", {
Expand All @@ -28,10 +28,9 @@ export const command = new Command("appdistribution:testers:list [group]")
});
}
spinner.succeed();
const testers = testersResponse.testers ?? [];
printTestersTable(testers);
utils.logSuccess(`Testers listed successfully`);
return testersResponse;
return { testers };
});

/**
Expand Down
Loading