Skip to content

Commit

Permalink
test: Test error conditions, edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
anishkny committed Jan 20, 2019
1 parent 4a0c2cf commit 4cee252
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/maintainCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const enum Delta {
function toString(delta: Delta): string {
if (delta === Delta.Increment) {
return 'Increment';
} else if (delta === Delta.Decrement) {
} else {
return 'Decrement';
}
}
23 changes: 22 additions & 1 deletion test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { getFirebaseCredentials, makeid, sleep } = require('./util');
const fft = require('firebase-functions-test')(...getFirebaseCredentials());
const sut = require('./functions');
const test = require('ava');
const { integrify } = require('./functions/lib');

const admin = require('firebase-admin');
admin.initializeApp(...getFirebaseCredentials());
Expand Down Expand Up @@ -54,7 +55,15 @@ test('test REPLICATE_ATTRIBUTES (online mode)', async t => {
1
);

t.pass();
// Assert irrelevant update is safely ignored
const irrelevantAfterSnap = fft.firestore.makeDocumentSnapshot(
{ masterFieldIrrelevant: 'whatever' },
`master/${masterId}`
);
const irreleventChange = fft.makeChange(beforeSnap, irrelevantAfterSnap);
await wrapped(irreleventChange, { params: { masterId: masterId } });

await t.pass();
});

test('test DELETE_REFERENCES (online mode)', async t => {
Expand Down Expand Up @@ -131,6 +140,18 @@ test('test MAINTAIN_COUNT (online mode)', async t => {
t.pass();
});

test('test error conditions', async t => {
t.throws(() => integrify(), TypeError, /Cannot read property.*of undefined/i);
t.throws(() => integrify({}), Error, /Input must be rule or config/i);
t.throws(
() => integrify({ rule: 'UNKNOWN_RULE_4a4e261a2e37' }),
Error,
/Unknown rule/i
);

t.pass();
});

async function assertDocumentValueEventually(
docRef,
fieldPath,
Expand Down

0 comments on commit 4cee252

Please sign in to comment.