Skip to content

Commit

Permalink
fix: assertFails for storage read/write requests (#5086) (#5209)
Browse files Browse the repository at this point in the history
Fixes Issue 4 of #5086
  • Loading branch information
lovelle-cardoso committed Aug 3, 2021
1 parent c493d92 commit c52eb48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/rules-unit-testing/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ export function assertFails(pr: Promise<any>): any {
errCode === 'permission-denied' ||
errCode === 'permission_denied' ||
errMessage.indexOf('permission_denied') >= 0 ||
errMessage.indexOf('permission denied') >= 0;
errMessage.indexOf('permission denied') >= 0 ||
// Storage permission errors contain message: (storage/unauthorized)
errMessage.indexOf('unauthorized') >= 0;

if (!isPermissionDenied) {
return Promise.reject(
Expand Down
25 changes: 25 additions & 0 deletions packages/rules-unit-testing/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,31 @@ describe('Testing Module Tests', function () {
.catch(() => {});
});

it('assertFails() if message contains unauthorized', async function () {
const success = Promise.resolve('success');
const permissionDenied = Promise.reject({
message: 'User does not have permission to access \'file\'. (storage/unauthorized)'
});
const otherFailure = Promise.reject('failure');
await firebase
.assertFails(success)
.then(() => {
throw new Error('Expected success to fail.');
})
.catch(() => {});

await firebase.assertFails(permissionDenied).catch(() => {
throw new Error('Expected permissionDenied to succeed.');
});

await firebase
.assertFails(otherFailure)
.then(() => {
throw new Error('Expected otherFailure to fail.');
})
.catch(() => {});
});

it('discoverEmulators() finds all running emulators', async () => {
const options = await firebase.discoverEmulators();

Expand Down

0 comments on commit c52eb48

Please sign in to comment.