Skip to content

Commit a77b21d

Browse files
committed
More complete tests + fixed the storage test config
1 parent 63a94f9 commit a77b21d

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

src/database/database.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ describe('AngularFireDatabase', () => {
4848
});
4949

5050
const FIREBASE_APP_NAME_TOO = (Math.random() + 1).toString(36).substring(7);
51-
const FIREBASE_DB_NAME = `https://test-${(Math.random() + 1).toString(36).substring(7)}.firebaseio.com/`;
51+
const FIREBASE_DB_NAME = `https://angularfire2-test2.firebaseio.com/`;
52+
const QUERY = (Math.random() + 1).toString(36).substring(7)
5253

5354
describe('AngularFireDatabase w/options', () => {
5455
let app: FirebaseApp;
@@ -86,9 +87,17 @@ describe('AngularFireDatabase w/options', () => {
8687
expect(db.database.app.name).toEqual(FIREBASE_APP_NAME_TOO);
8788
});
8889

89-
it('should be pointing to the provided DB instance', () => {
90+
it('database be pointing to the provided DB instance', () => {
9091
expect(db.database.ref().toString()).toEqual(FIREBASE_DB_NAME);
9192
});
93+
94+
it('list should be using the provided DB instance', () => {
95+
expect(db.list(QUERY).query.toString()).toEqual(`${FIREBASE_DB_NAME}${QUERY}`);
96+
});
97+
98+
it('object should be using the provided DB instance', () => {
99+
expect(db.object(QUERY).query.toString()).toEqual(`${FIREBASE_DB_NAME}${QUERY}`);
100+
});
92101
});
93102

94103
});

src/storage/storage.spec.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('AngularFireStorage', () => {
5454
it('should upload a file and observe the download url', (done) => {
5555
const data = { angular: "fire" };
5656
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
57-
const ref = afStorage.ref('afs.json');
57+
const ref = afStorage.ref('af.json');
5858
const task = ref.put(blob);
5959
const url$ = task.downloadURL();
6060
url$.subscribe(
@@ -67,7 +67,7 @@ describe('AngularFireStorage', () => {
6767
it('should resolve the task as a promise', (done) => {
6868
const data = { angular: "promise" };
6969
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
70-
const ref = afStorage.ref('afs.json');
70+
const ref = afStorage.ref('af.json');
7171
const task: AngularFireUploadTask = ref.put(blob);
7272
task.then(snap => {
7373
expect(snap).toBeDefined();
@@ -118,7 +118,7 @@ describe('AngularFireStorage', () => {
118118
});
119119

120120
const FIREBASE_APP_NAME_TOO = (Math.random() + 1).toString(36).substring(7);
121-
const FIREBASE_STORAGE_BUCKET = `gs://test-${(Math.random() + 1).toString(36).substring(7)}/`;
121+
const FIREBASE_STORAGE_BUCKET = 'angularfire2-test2';
122122

123123
describe('AngularFireStorage w/options', () => {
124124
let app: FirebaseApp;
@@ -160,8 +160,25 @@ describe('AngularFireStorage w/options', () => {
160160
expect(afStorage.storage.app.name).toEqual(FIREBASE_APP_NAME_TOO);
161161
});
162162

163-
it('should be pointing towards a different bucket', () => {
164-
expect(afStorage.storage.ref().toString()).toEqual(FIREBASE_STORAGE_BUCKET);
163+
it('storage be pointing towards a different bucket', () => {
164+
expect(afStorage.storage.ref().toString()).toEqual( `gs://${FIREBASE_STORAGE_BUCKET}/`);
165+
});
166+
167+
it('it should upload, download, and delete', (done) => {
168+
const data = { angular: "fire" };
169+
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
170+
const ref = afStorage.ref('af.json');
171+
const task = ref.put(blob);
172+
// Wait for the upload
173+
const sub = forkJoin(task.snapshotChanges())
174+
// get the url download
175+
.mergeMap(() => ref.getDownloadURL())
176+
// assert the URL
177+
.do(url => expect(url).toMatch(new RegExp(`https:\\/\\/firebasestorage\\.googleapis\\.com\\/v0\\/b\\/${FIREBASE_STORAGE_BUCKET}\\/o\\/af\\.json`)))
178+
// Delete the file
179+
.mergeMap(url => ref.delete())
180+
// finish the test
181+
.subscribe(done, done.fail);
165182
});
166183

167184
});

src/storage/test-config.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
export const COMMON_CONFIG = {
3-
apiKey: "AIzaSyAcDzMU79ou1QE5OvZm4JfpfkM8f2gwPno",
4-
authDomain: "day-of.firebaseapp.com",
5-
databaseURL: "https://day-of.firebaseio.com",
6-
projectId: "day-of",
7-
storageBucket: "day-of.appspot.com",
8-
messagingSenderId: "131965932953"
2+
apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA",
3+
authDomain: "angularfire2-test.firebaseapp.com",
4+
databaseURL: "https://angularfire2-test.firebaseio.com",
5+
projectId: "angularfire2-test",
6+
storageBucket: "angularfire2-test.appspot.com",
97
};

0 commit comments

Comments
 (0)