Skip to content

Commit

Permalink
Handle lookup returning empty array of users. (#1082)
Browse files Browse the repository at this point in the history
* Handle lookup returning empty array of users.

* Update tests.

* Use single quotes.

* Update auth-api-request.spec.ts
  • Loading branch information
yuchenshi committed Nov 9, 2020
1 parent 12b02d6 commit fb2c63c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
10 changes: 8 additions & 2 deletions test/unit/auth/auth-api-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

Expand Down

0 comments on commit fb2c63c

Please sign in to comment.