Skip to content

Commit 4b8c97f

Browse files
authored
Implement setDisplayName() for ProjectManagement class (#19)
* Implement setDisplayName() for ProjectManagement class * fix integration test to address comment * Enable promise support for integration test
1 parent 9815634 commit 4b8c97f

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ declare namespace admin.projectManagement {
813813
listIosApps(): Promise<admin.projectManagement.IosApp[]>;
814814
listAppMetadata(): Promise<admin.projectManagement.AppMetadata[]>;
815815
androidApp(appId: string): admin.projectManagement.AndroidApp;
816+
setDisplayName(newDisplayName: string): Promise<void>;
816817
iosApp(appId: string): admin.projectManagement.IosApp;
817818
shaCertificate(shaHash: string): admin.projectManagement.ShaCertificate;
818819
createAndroidApp(

src/project-management/project-management.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ export class ProjectManagement implements FirebaseServiceInterface {
159159
/**
160160
* Update display name of the project
161161
*/
162-
public setDisplayName(displayName: string): Promise<void> {
163-
throw new FirebaseProjectManagementError(
164-
'service-unavailable', 'This service is not available');
162+
public setDisplayName(newDisplayName: string): Promise<void> {
163+
return this.requestHandler.setDisplayName(this.resourceName, newDisplayName);
165164
}
166165

167166
private transformResponseToAppMetadata(responseData: any): AppMetadata[] {

test/integration/project-management.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,25 @@
1616

1717
import * as _ from 'lodash';
1818
import * as chai from 'chai';
19+
import * as chaiAsPromised from 'chai-as-promised';
1920
import * as admin from '../../lib/index';
2021
import { projectId } from './setup';
2122

2223
const APP_NAMESPACE_PREFIX = 'com.adminsdkintegrationtest.a';
2324
const APP_NAMESPACE_SUFFIX_LENGTH = 15;
2425

2526
const APP_DISPLAY_NAME_PREFIX = 'Created By Firebase AdminSDK Nodejs Integration Testing ';
27+
const PROJECT_DISPLAY_NAME_PREFIX = 'Nodejs AdminSDK Testing ';
2628
const APP_DISPLAY_NAME_SUFFIX_LENGTH = 15;
29+
const PROJECT_DISPLAY_NAME_SUFFIX_LENGTH = 6;
2730

2831
const SHA_256_HASH = 'aaaaccccaaaaccccaaaaccccaaaaccccaaaaccccaaaaccccaaaaccccaaaacccc';
2932

3033
const expect = chai.expect;
3134

35+
chai.should();
36+
chai.use(chaiAsPromised);
37+
3238
describe('admin.projectManagement', () => {
3339

3440
let androidApp: admin.projectManagement.AndroidApp;
@@ -75,6 +81,15 @@ describe('admin.projectManagement', () => {
7581
});
7682
});
7783

84+
describe('setDisplayName()', () => {
85+
it('successfully set project\'s display name', () => {
86+
const newDisplayName = generateUniqueProjectDisplayName();
87+
// TODO(caot): verify that project name has been renamed successfully
88+
return admin.projectManagement().setDisplayName(newDisplayName)
89+
.should.eventually.be.fulfilled;
90+
});
91+
});
92+
7893
describe('listAppMetadata()', () => {
7994
it('successfully lists metadata of all apps', () => {
8095
return admin.projectManagement().listAppMetadata()
@@ -247,6 +262,13 @@ function generateUniqueAppDisplayName() {
247262
return APP_DISPLAY_NAME_PREFIX + generateRandomString(APP_DISPLAY_NAME_SUFFIX_LENGTH);
248263
}
249264

265+
/**
266+
* @return {string} string that can be used as a unique project display name.
267+
*/
268+
function generateUniqueProjectDisplayName() {
269+
return PROJECT_DISPLAY_NAME_PREFIX + generateRandomString(PROJECT_DISPLAY_NAME_SUFFIX_LENGTH);
270+
}
271+
250272
/**
251273
* @return {boolean} True if the specified appNamespace belongs to these integration tests.
252274
*/

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,21 @@ describe('ProjectManagement', () => {
511511
});
512512

513513
describe('setDisplayName', () => {
514-
it('should throw service-unavailable error', () => {
515-
expect(() => projectManagement.setDisplayName('new project name'))
516-
.to.throw('This service is not available');
514+
it('should propagate API errors', () => {
515+
const stub = sinon
516+
.stub(ProjectManagementRequestHandler.prototype, 'setDisplayName')
517+
.returns(Promise.reject(EXPECTED_ERROR));
518+
stubs.push(stub);
519+
return projectManagement.setDisplayName(DISPLAY_NAME_ANDROID)
520+
.should.eventually.be.rejected.and.equal(EXPECTED_ERROR);
521+
});
522+
523+
it('should resolve on success', () => {
524+
const stub = sinon
525+
.stub(ProjectManagementRequestHandler.prototype, 'setDisplayName')
526+
.returns(Promise.resolve());
527+
stubs.push(stub);
528+
return projectManagement.setDisplayName(DISPLAY_NAME_ANDROID).should.eventually.be.fulfilled;
517529
});
518530
});
519531
});

0 commit comments

Comments
 (0)