|
| 1 | +import { expect } from "chai"; |
| 2 | +import firebase from "../../src/app"; |
| 3 | +import { |
| 4 | + TEST_PROJECT, |
| 5 | + patchFakeAuthFunctions, |
| 6 | +} from "./helpers"; |
| 7 | +import "../../src/database"; |
| 8 | + |
| 9 | +describe.only('Database Tests', function() { |
| 10 | + var defaultApp; |
| 11 | + |
| 12 | + beforeEach(function() { |
| 13 | + defaultApp = firebase.initializeApp({databaseURL: TEST_PROJECT.databaseURL}); |
| 14 | + patchFakeAuthFunctions(defaultApp); |
| 15 | + }); |
| 16 | + |
| 17 | + afterEach(function() { |
| 18 | + return defaultApp.delete(); |
| 19 | + }); |
| 20 | + |
| 21 | + it('Can get database.', function() { |
| 22 | + var db = firebase.database(); |
| 23 | + expect(db).to.not.be.undefined; |
| 24 | + expect(db).not.to.be.null; |
| 25 | + }); |
| 26 | + |
| 27 | + it('Illegal to call constructor', function() { |
| 28 | + expect(function() { |
| 29 | + var db = new firebase.database.Database('url'); |
| 30 | + }).to.throw(/don't call new Database/i); |
| 31 | + }); |
| 32 | + |
| 33 | + it('Can get app', function() { |
| 34 | + var db = firebase.database(); |
| 35 | + expect(db.app).to.not.be.undefined; |
| 36 | + expect((db.app as any) instanceof firebase.app.App); |
| 37 | + }); |
| 38 | + |
| 39 | + it('Can get root ref', function() { |
| 40 | + var db = firebase.database(); |
| 41 | + |
| 42 | + var ref = db.ref(); |
| 43 | + |
| 44 | + expect(ref instanceof firebase.database.Reference).to.be.true; |
| 45 | + expect(ref.key).to.be.null; |
| 46 | + }); |
| 47 | + |
| 48 | + it('Can get child ref', function() { |
| 49 | + var db = firebase.database(); |
| 50 | + |
| 51 | + var ref = db.ref('child'); |
| 52 | + |
| 53 | + expect(ref instanceof firebase.database.Reference).to.be.true; |
| 54 | + expect(ref.key).to.equal('child'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('Can get deep child ref', function() { |
| 58 | + var db = firebase.database(); |
| 59 | + |
| 60 | + var ref = db.ref('child/grand-child'); |
| 61 | + |
| 62 | + expect(ref instanceof firebase.database.Reference).to.be.true; |
| 63 | + expect(ref.key).to.equal('grand-child'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('ref() validates arguments', function() { |
| 67 | + var db = firebase.database(); |
| 68 | + expect(function() { |
| 69 | + var ref = (db as any).ref('path', 'extra'); |
| 70 | + }).to.throw(/Expects no more than 1/); |
| 71 | + }); |
| 72 | + |
| 73 | + it('Can get refFromURL()', function() { |
| 74 | + var db = firebase.database(); |
| 75 | + var ref = db.refFromURL(TEST_PROJECT.databaseURL + '/path/to/data'); |
| 76 | + expect(ref.key).to.equal('data'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('refFromURL() validates domain', function() { |
| 80 | + var db = firebase.database(); |
| 81 | + expect(function() { |
| 82 | + var ref = db.refFromURL('https://thisisnotarealfirebase.firebaseio.com/path/to/data'); |
| 83 | + }).to.throw(/does not match.*database/i); |
| 84 | + }); |
| 85 | + |
| 86 | + it('refFromURL() validates argument', function() { |
| 87 | + var db = firebase.database(); |
| 88 | + expect(function() { |
| 89 | + var ref = (db as any).refFromURL(); |
| 90 | + }).to.throw(/Expects at least 1/); |
| 91 | + }); |
| 92 | +}); |
0 commit comments