Skip to content

Fix assertFails() logic of @firebase/rules-unit-testing #3676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rules-unit-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
}
}
}
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 @@ -328,7 +328,8 @@ export function assertFails(pr: Promise<any>): any {
},
(err: any) => {
const isPermissionDenied =
err && err.message && err.message.indexOf('PERMISSION_DENIED') >= 0;
(err && err.message && err.message.indexOf('PERMISSION_DENIED') >= 0) ||
(err && err.code === 'permission-denied');
if (!isPermissionDenied) {
return Promise.reject(
new Error(
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 @@ -67,6 +67,31 @@ describe('Testing Module Tests', function () {
.catch(() => {});
});

it('assertFails() if code is permission-denied', async function () {
const success = Promise.resolve('success');
const permissionDenied = Promise.reject({
code: '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('initializeTestApp() with auth=null does not set access token', async function () {
const app = firebase.initializeTestApp({
projectId: 'foo',
Expand Down