Skip to content

Commit 3b9f99d

Browse files
authored
Return arrays from listTesters() and listGroups(). (#9395)
1 parent dd7c567 commit 3b9f99d

File tree

4 files changed

+44
-62
lines changed

4 files changed

+44
-62
lines changed

src/appdistribution/client.spec.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe("distribution", () => {
100100
expect(nock.isDone()).to.be.true;
101101
});
102102

103-
it("should resolve with ListTestersResponse when request succeeds - no filter", async () => {
103+
it("should resolve with array of testers when request succeeds - no filter", async () => {
104104
const testerListing = [
105105
{
106106
name: "tester_1",
@@ -119,22 +119,20 @@ describe("distribution", () => {
119119
nock(appDistributionOrigin()).get(`/v1/${projectName}/testers`).reply(200, {
120120
testers: testerListing,
121121
});
122-
await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq({
123-
testers: [
124-
{
125-
name: "tester_1",
126-
displayName: "Tester 1",
127-
groups: [],
128-
lastActivityTime: new Date("2024-08-27T02:37:19.539865Z"),
129-
},
130-
{
131-
name: "tester_2",
132-
displayName: "Tester 2",
133-
groups: [`${projectName}/groups/beta-team`, `${projectName}/groups/alpha-team`],
134-
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
135-
},
136-
],
137-
});
122+
await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq([
123+
{
124+
name: "tester_1",
125+
displayName: "Tester 1",
126+
groups: [],
127+
lastActivityTime: new Date("2024-08-27T02:37:19.539865Z"),
128+
},
129+
{
130+
name: "tester_2",
131+
displayName: "Tester 2",
132+
groups: [`${projectName}/groups/beta-team`, `${projectName}/groups/alpha-team`],
133+
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
134+
},
135+
]);
138136
expect(nock.isDone()).to.be.true;
139137
});
140138

@@ -157,25 +155,21 @@ describe("distribution", () => {
157155
});
158156
await expect(
159157
appDistributionClient.listTesters(projectName, "beta-team"),
160-
).to.eventually.deep.eq({
161-
testers: [
162-
{
163-
name: "tester_2",
164-
displayName: "Tester 2",
165-
groups: [`${projectName}/groups/beta-team`],
166-
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
167-
},
168-
],
169-
});
158+
).to.eventually.deep.eq([
159+
{
160+
name: "tester_2",
161+
displayName: "Tester 2",
162+
groups: [`${projectName}/groups/beta-team`],
163+
lastActivityTime: new Date("2024-08-26T02:37:19Z"),
164+
},
165+
]);
170166
expect(nock.isDone()).to.be.true;
171167
});
172168

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

176-
await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq({
177-
testers: [],
178-
});
172+
await expect(appDistributionClient.listTesters(projectName)).to.eventually.deep.eq([]);
179173
expect(nock.isDone()).to.be.true;
180174
});
181175
});
@@ -403,8 +397,8 @@ describe("distribution", () => {
403397
expect(nock.isDone()).to.be.true;
404398
});
405399

406-
it("should resolve with ListGroupsResponse when request succeeds", async () => {
407-
const groupListing: Group[] = [
400+
it("should resolve with array of groups when request succeeds", async () => {
401+
const groups: Group[] = [
408402
{
409403
name: "group_1",
410404
displayName: "Group 1",
@@ -419,11 +413,9 @@ describe("distribution", () => {
419413
];
420414

421415
nock(appDistributionOrigin()).get(`/v1/${projectName}/groups`).reply(200, {
422-
groups: groupListing,
423-
});
424-
await expect(appDistributionClient.listGroups(projectName)).to.eventually.deep.eq({
425-
groups: groupListing,
416+
groups: groups,
426417
});
418+
await expect(appDistributionClient.listGroups(projectName)).to.eventually.deep.eq(groups);
427419
expect(nock.isDone()).to.be.true;
428420
});
429421
});

src/appdistribution/client.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
mapDeviceToExecution,
1818
ReleaseTest,
1919
TestDevice,
20+
Tester,
2021
UploadReleaseResponse,
2122
} from "./types";
2223

@@ -126,17 +127,12 @@ export class AppDistributionClient {
126127
utils.logSuccess("distributed to testers/groups successfully");
127128
}
128129

129-
async listTesters(projectName: string, groupName?: string): Promise<ListTestersResponse> {
130-
const listTestersResponse: ListTestersResponse = {
131-
testers: [],
132-
};
133-
130+
async listTesters(projectName: string, groupName?: string): Promise<Tester[]> {
131+
const testers: Tester[] = [];
134132
const client = this.appDistroV1Client;
135-
136-
let pageToken: string | undefined;
137-
138133
const filter = groupName ? `groups=${projectName}/groups/${groupName}` : null;
139134

135+
let pageToken: string | undefined;
140136
do {
141137
const queryParams: Record<string, string> = pageToken ? { pageToken } : {};
142138
if (filter != null) {
@@ -153,7 +149,7 @@ export class AppDistributionClient {
153149
}
154150

155151
for (const t of apiResponse.body.testers ?? []) {
156-
listTestersResponse.testers.push({
152+
testers.push({
157153
name: t.name,
158154
displayName: t.displayName,
159155
groups: t.groups,
@@ -163,7 +159,7 @@ export class AppDistributionClient {
163159

164160
pageToken = apiResponse.body.nextPageToken;
165161
} while (pageToken);
166-
return listTestersResponse;
162+
return testers;
167163
}
168164

169165
async addTesters(projectName: string, emails: string[]): Promise<void> {
@@ -197,28 +193,24 @@ export class AppDistributionClient {
197193
return apiResponse.body;
198194
}
199195

200-
async listGroups(projectName: string): Promise<ListGroupsResponse> {
201-
const listGroupsResponse: ListGroupsResponse = {
202-
groups: [],
203-
};
204-
196+
async listGroups(projectName: string): Promise<Group[]> {
197+
const groups: Group[] = [];
205198
const client = this.appDistroV1Client;
206199

207200
let pageToken: string | undefined;
208-
209201
do {
210202
const queryParams: Record<string, string> = pageToken ? { pageToken } : {};
211203
try {
212204
const apiResponse = await client.get<ListGroupsResponse>(`${projectName}/groups`, {
213205
queryParams,
214206
});
215-
listGroupsResponse.groups.push(...(apiResponse.body.groups ?? []));
207+
groups.push(...(apiResponse.body.groups ?? []));
216208
pageToken = apiResponse.body.nextPageToken;
217209
} catch (err) {
218210
throw new FirebaseError(`Client failed to list groups ${err}`);
219211
}
220212
} while (pageToken);
221-
return listGroupsResponse;
213+
return groups;
222214
}
223215

224216
async createGroup(projectName: string, displayName: string, alias?: string): Promise<Group> {

src/commands/appdistribution-groups-list.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export const command = new Command("appdistribution:groups:list")
1717
.action(async (options?: Options): Promise<ListGroupsResponse> => {
1818
const projectName = await getProjectName(options);
1919
const appDistroClient = new AppDistributionClient();
20-
let groupsResponse: ListGroupsResponse;
20+
let groups: Group[];
2121
const spinner = ora("Preparing the list of your App Distribution Groups").start();
2222
try {
23-
groupsResponse = await appDistroClient.listGroups(projectName);
23+
groups = await appDistroClient.listGroups(projectName);
2424
} catch (err: any) {
2525
spinner.fail();
2626
throw new FirebaseError("Failed to list groups.", {
@@ -29,10 +29,9 @@ export const command = new Command("appdistribution:groups:list")
2929
});
3030
}
3131
spinner.succeed();
32-
const groups = groupsResponse.groups ?? [];
3332
printGroupsTable(groups);
3433
utils.logSuccess(`Groups listed successfully`);
35-
return groupsResponse;
34+
return { groups };
3635
});
3736

3837
/**

src/commands/appdistribution-testers-list.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export const command = new Command("appdistribution:testers:list [group]")
1616
.action(async (group: string | undefined, options: Options): Promise<ListTestersResponse> => {
1717
const projectName = await getProjectName(options);
1818
const appDistroClient = new AppDistributionClient();
19-
let testersResponse: ListTestersResponse;
19+
let testers: Tester[];
2020
const spinner = ora("Preparing the list of your App Distribution testers").start();
2121
try {
22-
testersResponse = await appDistroClient.listTesters(projectName, group);
22+
testers = await appDistroClient.listTesters(projectName, group);
2323
} catch (err: any) {
2424
spinner.fail();
2525
throw new FirebaseError("Failed to list testers.", {
@@ -28,10 +28,9 @@ export const command = new Command("appdistribution:testers:list [group]")
2828
});
2929
}
3030
spinner.succeed();
31-
const testers = testersResponse.testers ?? [];
3231
printTestersTable(testers);
3332
utils.logSuccess(`Testers listed successfully`);
34-
return testersResponse;
33+
return { testers };
3534
});
3635

3736
/**

0 commit comments

Comments
 (0)