-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from dalenguyen/dev
Added support for app name #27
- Loading branch information
Showing
9 changed files
with
140 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,86 @@ | ||
import { expect } from 'chai' | ||
import request from 'request-promise' | ||
import * as firestoreService from '../dist' | ||
import { serviceAccount } from './serviceAccount' | ||
import { expect } from 'chai'; | ||
import request from 'request-promise'; | ||
import * as firestoreService from '../dist'; | ||
import { serviceAccount } from './serviceAccount'; | ||
|
||
const app = firestoreService.initializeApp( | ||
serviceAccount, | ||
serviceAccount.databaseUrl | ||
) | ||
); | ||
const backupAPI = | ||
'https://firebasestorage.googleapis.com/v0/b/firbase-function-helper-qa.appspot.com/o/import-to-firestore.json?alt=media&token=a0530902-8983-45a4-90c2-72c345c7a3d5' | ||
'https://firebasestorage.googleapis.com/v0/b/firbase-function-helper-qa.appspot.com/o/import-to-firestore.json?alt=media&token=a0530902-8983-45a4-90c2-72c345c7a3d5'; | ||
|
||
describe('initializeApp function test', () => { | ||
it('Initialize app', () => { | ||
expect(app).to.equal(true) | ||
}) | ||
expect(app).to.equal(true); | ||
}); | ||
|
||
it('Restore data from API', async () => { | ||
const backupData = await request(backupAPI) | ||
const backupData = await request(backupAPI); | ||
const status = await firestoreService.restore(JSON.parse(backupData), { | ||
dates: ['date'], | ||
geos: ['location'] | ||
}) | ||
expect(status.status).ok | ||
}) | ||
geos: ['location'], | ||
}); | ||
expect(status.status).ok; | ||
}); | ||
|
||
it('Get all collections', async () => { | ||
try { | ||
const all = await firestoreService.backups() | ||
expect(Object.keys(all).length).is.greaterThan(0) | ||
const all = await firestoreService.backups(); | ||
expect(Object.keys(all).length).is.greaterThan(0); | ||
} catch (error) { | ||
console.log(error) | ||
console.log(error); | ||
} | ||
}) | ||
}); | ||
|
||
it('Get an array of collections', async () => { | ||
const all = await firestoreService.backups(['test', 'users']) | ||
expect(Object.keys(all).length).is.equal(2) | ||
}) | ||
const all = await firestoreService.backups(['test', 'users']); | ||
expect(Object.keys(all).length).is.equal(2); | ||
}); | ||
|
||
it('Restore data with document id', async () => { | ||
let status = await firestoreService.restore( | ||
'test/import-to-firestore.json', | ||
{ | ||
dates: ['date', 'schedule.time', 'three.level.time'], | ||
geos: ['location', 'locations'], | ||
refs: ['secondRef', 'arrayRef'] | ||
refs: ['secondRef', 'arrayRef'], | ||
} | ||
) | ||
expect(status.status).ok | ||
); | ||
expect(status.status).ok; | ||
|
||
const result = await firestoreService.backup('test') | ||
const result = await firestoreService.backup('test'); | ||
|
||
expect(result.test['first-key'].email).is.equal('dungnq@itbox4vn.com') | ||
expect(result.test['first-key'].schedule.time._seconds).equals(1534046400) | ||
expect(typeof result.test['first-key'].secondRef).is.equal('object') | ||
expect(result.test['first-key'].email).is.equal('dungnq@itbox4vn.com'); | ||
expect(result.test['first-key'].schedule.time._seconds).equals(1534046400); | ||
expect(typeof result.test['first-key'].secondRef).is.equal('object'); | ||
// locations | ||
expect(result.test['first-key'].location._latitude).equal(49.290683) | ||
expect(result.test['first-key'].locations[0]._latitude).equal(50.290683) | ||
expect(result.test['first-key'].locations[1]._latitude).equal(51.290683) | ||
expect(result.test['first-key'].location._latitude).equal(49.290683); | ||
expect(result.test['first-key'].locations[0]._latitude).equal(50.290683); | ||
expect(result.test['first-key'].locations[1]._latitude).equal(51.290683); | ||
expect( | ||
result.test['first-key'].subCollection['test/first-key/details'][ | ||
'33J2A10u5902CXagoBP6' | ||
].dogName | ||
).is.equal('hello') | ||
}) | ||
).is.equal('hello'); | ||
}); | ||
|
||
it('Restore data as an array without document id', async () => { | ||
let status = await firestoreService.restore( | ||
'test/import-array-to-firestore.json' | ||
) | ||
expect(status.status).ok | ||
}) | ||
); | ||
expect(status.status).ok; | ||
}); | ||
|
||
it('Get a colection with sub-collection', async () => { | ||
try { | ||
const data = await firestoreService.backup('test') | ||
const subCol = data['test']['first-key']['subCollection'] | ||
const data = await firestoreService.backup('test'); | ||
const subCol = data['test']['first-key']['subCollection']; | ||
|
||
expect(subCol).is.exist | ||
expect(Object.values(subCol).length).is.greaterThan(0) | ||
expect(subCol).is.exist; | ||
expect(Object.values(subCol).length).is.greaterThan(0); | ||
} catch (error) { | ||
console.log(error) | ||
console.log(error); | ||
} | ||
}) | ||
}) | ||
}); | ||
}); |
Oops, something went wrong.