Skip to content

Commit

Permalink
Fix assert fails (#4667) (#4713)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattGoldwater authored Apr 2, 2021
1 parent 5ef7031 commit 5ad7ff2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/happy-planets-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/rules-unit-testing": patch
---

Fix assertFails not correctly catching RTDB permission denied errors (#4667).
3 changes: 2 additions & 1 deletion packages/rules-unit-testing/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ export function assertFails(pr: Promise<any>): any {
const isPermissionDenied =
errCode === 'permission-denied' ||
errCode === 'permission_denied' ||
errMessage.indexOf('permission_denied') >= 0;
errMessage.indexOf('permission_denied') >= 0 ||
errMessage.indexOf('permission denied') >= 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 @@ -128,6 +128,31 @@ describe('Testing Module Tests', function () {
.catch(() => {});
});

it('assertFails() if message is Permission denied', async function () {
const success = Promise.resolve('success');
const permissionDenied = Promise.reject({
message: 'Permission denied'
});
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 5ad7ff2

Please sign in to comment.