From fb2c63c0d506fd01f9121166e3bb63aac9af62ff Mon Sep 17 00:00:00 2001 From: Yuchen Shi Date: Mon, 9 Nov 2020 12:49:15 -0800 Subject: [PATCH] Handle lookup returning empty array of users. (#1082) * Handle lookup returning empty array of users. * Update tests. * Use single quotes. * Update auth-api-request.spec.ts --- src/auth/auth-api-request.ts | 2 +- test/unit/auth/auth-api-request.spec.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/auth/auth-api-request.ts b/src/auth/auth-api-request.ts index f57fdc3fcc..753f06e48f 100644 --- a/src/auth/auth-api-request.ts +++ b/src/auth/auth-api-request.ts @@ -629,7 +629,7 @@ export const FIREBASE_AUTH_GET_ACCOUNT_INFO = new ApiSettings('/accounts:lookup' }) // Set response validator. .setResponseValidator((response: any) => { - if (!response.users) { + if (!response.users || !response.users.length) { throw new FirebaseAuthError(AuthClientErrorCode.USER_NOT_FOUND); } }); diff --git a/test/unit/auth/auth-api-request.spec.ts b/test/unit/auth/auth-api-request.spec.ts index 4c621fe215..0a86231e53 100644 --- a/test/unit/auth/auth-api-request.spec.ts +++ b/test/unit/auth/auth-api-request.spec.ts @@ -369,17 +369,23 @@ describe('FIREBASE_AUTH_GET_ACCOUNT_INFO', () => { describe('responseValidator', () => { const responseValidator = FIREBASE_AUTH_GET_ACCOUNT_INFO.getResponseValidator(); it('should succeed with users returned', () => { - const validResponse: object = { users: [] }; + const validResponse: object = { users: [{ localId: 'foo' }] }; expect(() => { return responseValidator(validResponse); }).not.to.throw(); }); - it('should fail when users is not returned', () => { + it('should fail when the response object is empty', () => { const invalidResponse = {}; expect(() => { responseValidator(invalidResponse); }).to.throw(); }); + it('should fail when the response object has an empty list of users', () => { + const invalidResponse = { users: [] }; + expect(() => { + responseValidator(invalidResponse); + }).to.throw(); + }); }); });