Skip to content

Commit fb2c63c

Browse files
authored
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
1 parent 12b02d6 commit fb2c63c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/auth/auth-api-request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ export const FIREBASE_AUTH_GET_ACCOUNT_INFO = new ApiSettings('/accounts:lookup'
629629
})
630630
// Set response validator.
631631
.setResponseValidator((response: any) => {
632-
if (!response.users) {
632+
if (!response.users || !response.users.length) {
633633
throw new FirebaseAuthError(AuthClientErrorCode.USER_NOT_FOUND);
634634
}
635635
});

test/unit/auth/auth-api-request.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,23 @@ describe('FIREBASE_AUTH_GET_ACCOUNT_INFO', () => {
369369
describe('responseValidator', () => {
370370
const responseValidator = FIREBASE_AUTH_GET_ACCOUNT_INFO.getResponseValidator();
371371
it('should succeed with users returned', () => {
372-
const validResponse: object = { users: [] };
372+
const validResponse: object = { users: [{ localId: 'foo' }] };
373373
expect(() => {
374374
return responseValidator(validResponse);
375375
}).not.to.throw();
376376
});
377-
it('should fail when users is not returned', () => {
377+
it('should fail when the response object is empty', () => {
378378
const invalidResponse = {};
379379
expect(() => {
380380
responseValidator(invalidResponse);
381381
}).to.throw();
382382
});
383+
it('should fail when the response object has an empty list of users', () => {
384+
const invalidResponse = { users: [] };
385+
expect(() => {
386+
responseValidator(invalidResponse);
387+
}).to.throw();
388+
});
383389
});
384390
});
385391

0 commit comments

Comments
 (0)