Skip to content

Commit 1655c19

Browse files
authored
Fix: non ios/android apps should be listed as PLATFORM_UNKNOWN (#18)
1 parent fcc14dc commit 1655c19

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/project-management/project-management.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,14 @@ export class ProjectManagement implements FirebaseServiceInterface {
177177
responseData,
178178
`"apps[].appId" field must be present in the listAppMetadata() response data.`);
179179
assertServerResponse(
180-
this.validateAppPlatform(appJson.platform),
180+
validator.isNonEmptyString(appJson.platform),
181181
responseData,
182-
`"apps[].platform" field must be one of [${Object.keys(AppPlatform).join(', ')}].`);
182+
`"apps[].platform" field must be present in the listAppMetadata() response data.`);
183+
appJson.platform = AppPlatform[appJson.platform] || AppPlatform.PLATFORM_UNKNOWN;
183184
return appJson as AppMetadata;
184185
});
185186
}
186187

187-
private validateAppPlatform(platform: any): boolean {
188-
return platform && (AppPlatform[platform] !== undefined);
189-
}
190-
191188
/**
192189
* Lists up to 100 Firebase apps for a specified platform, associated with this Firebase project.
193190
*/

test/unit/project-management/project-management.spec.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,24 +459,23 @@ describe('ProjectManagement', () => {
459459
+ `Response data: ${JSON.stringify(partialApiResponse, null, 2)}`);
460460
});
461461

462-
it('should throw with API response with invalid "apps[].platform" field', () => {
463-
const invalidPlatformApiResponse = {
462+
it('should throw with API response missing "apps[].platform" field', () => {
463+
const missingPlatformApiResponse = {
464464
apps: [{
465465
appId: APP_ID,
466-
platform: 'INVALID',
467466
}],
468467
};
469468

470469
const stub = sinon
471470
.stub(ProjectManagementRequestHandler.prototype, 'listAppMetadata')
472-
.returns(Promise.resolve(invalidPlatformApiResponse));
471+
.returns(Promise.resolve(missingPlatformApiResponse));
473472
stubs.push(stub);
474473
return projectManagement.listAppMetadata()
475474
.should.eventually.be.rejected
476475
.and.have.property(
477476
'message',
478-
'"apps[].platform" field must be one of [PLATFORM_UNKNOWN, IOS, ANDROID]. '
479-
+ `Response data: ${JSON.stringify(invalidPlatformApiResponse, null, 2)}`);
477+
'"apps[].platform" field must be present in the listAppMetadata() response data. '
478+
+ `Response data: ${JSON.stringify(missingPlatformApiResponse, null, 2)}`);
480479
});
481480

482481
it('should resolve with list of apps metadata on success', () => {
@@ -489,6 +488,26 @@ describe('ProjectManagement', () => {
489488
return projectManagement.listAppMetadata()
490489
.should.eventually.deep.equal(validAppMetadata);
491490
});
491+
492+
it('should resolve with "apps[].platform" to be "PLATFORM_UNKNOWN" for web app', () => {
493+
const webPlatformApiResponse = {
494+
apps: [{
495+
appId: APP_ID,
496+
platform: 'WEB',
497+
}],
498+
};
499+
const expectedAppMetadata: AppMetadata[] = [{
500+
appId: APP_ID,
501+
platform: AppPlatform.PLATFORM_UNKNOWN,
502+
}];
503+
504+
const stub = sinon
505+
.stub(ProjectManagementRequestHandler.prototype, 'listAppMetadata')
506+
.returns(Promise.resolve(webPlatformApiResponse));
507+
stubs.push(stub);
508+
return projectManagement.listAppMetadata()
509+
.should.eventually.deep.equal(expectedAppMetadata);
510+
});
492511
});
493512

494513
describe('setDisplayName', () => {

0 commit comments

Comments
 (0)