Merge branch 'master' of github.com:invertase/react-native-firebase

This commit is contained in:
Elliot Hesp 2017-07-04 15:40:03 +01:00
commit ce0934d44c
8 changed files with 86 additions and 10 deletions

View File

@ -428,10 +428,26 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
*/
private StorageMetadata buildMetadataFromMap(ReadableMap metadata) {
StorageMetadata.Builder metadataBuilder = new StorageMetadata.Builder();
try {
Map<String, Object> m = Utils.recursivelyDeconstructReadableMap(metadata);
for (Map.Entry<String, Object> entry : m.entrySet()) {
metadataBuilder.setCustomMetadata(entry.getKey(), entry.getValue().toString());
Map<String, Object> customMetadata = (Map<String, Object>) m.get("customMetadata");
if (customMetadata != null) {
for (Map.Entry<String, Object> entry : customMetadata.entrySet()) {
metadataBuilder.setCustomMetadata(entry.getKey(), String.valueOf(entry.getValue()));
}
}
metadataBuilder.setCacheControl((String) m.get("cacheControl"));
metadataBuilder.setContentDisposition((String) m.get("contentDisposition"));
metadataBuilder.setContentEncoding((String) m.get("contentEncoding"));
metadataBuilder.setContentLanguage((String) m.get("contentLanguage"));
metadataBuilder.setContentType((String) m.get("contentType"));
} catch (Exception e) {
Log.e(TAG, "error while building meta data " + e.getMessage());
}
return metadataBuilder.build();

View File

@ -19,6 +19,7 @@
- [Remote Config](/modules/config)
- [Storage](/modules/storage)
- [Transactions](/modules/transactions)
- [Performance Monitoring](/modules/perf)
- Other
- [Project Board](https://github.com/invertase/react-native-firebase/projects)

View File

@ -1,3 +1,55 @@
# Testing
Currently due to the blackbox Firebase enviroment, we have found the best way to test the library is to directly test against the library using a live Firebase project. As some modules also work with the offical web SDK, we can directly compare the results against our own library. This is however restrictive as it doesn't directly test the native code/modules. Plans are in place to overhaul the entire testing setup.
## Running the test app
For convenience all of the required NPM scripts are packaged with the main library to run the test app.
### Step 1 - Clone
```bash
git clone git@github.com:invertase/react-native-firebase.git
```
### Step 2 - Install dependencies
```bash
npm run tests-npm-install
```
### Step 3 - Install [WML](https://github.com/wix/wml)
WML is a library which copies files & directories to a location. This allows us to copy any changes from the library directly into the tests app, so we can quickly test changes.
```bash
npm install -g wml
```
### Step 4 - Start the watcher
```bash
npm run tests-watch-init
npm run tests-watch-start
```
### Step 5 - Start the app
```bash
npm run tests-packager
```
#### Android
Open the `tests/android` directory from Android Studio and allow Gradle to sync. Now run the app on an emulator/device.
#### iOS
First install the Pods:
```
npm run tests-pod-install
```
Open the `tests/ios/ReactNativeFirebaseDemo.xcworkspace` file in XCode and build for your preffered device or simulator.

View File

@ -19,7 +19,7 @@ Unfortunately, due to the fact that Firebase is much easier to setup using Cocoa
### 2.0) If you don't already have Cocoapods set up
Follow the instructions to install Cocoapods and create your Podfile [here](https://firebase.google.com/docs/ios/setup#add_the_sdk).
**NOTE: The Podfile needs to be initialised in the `ios` directory of your project.**
**NOTE: The Podfile needs to be initialised in the `ios` directory of your project. Make sure to update cocoapods libs first by running `pod update`**
#### Troubleshooting
1) When running `pod install` you may encounter an error saying that a `tvOSTests` target is declared twice. This appears to be a bug with `pod init` and the way that react native is set up.

View File

@ -109,7 +109,7 @@ Add the packages to the `getPackages()` method as required:
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNFirebasePackage(), // <-- Add this line - it's the only one that's required
new RNFirebasePackage(), // <-- Keep this line - it's the only one that's required
// add these optional packages as appropriate
new RNFirebaseAdMobPackage(),

View File

@ -9,7 +9,7 @@ RNFirebase handles authentication for us out of the box, both with email/passwor
### Properties
##### `authenticated: boolean` - Returns the current Firebase authentication state.
##### `currentUser: User | null` - Returns the currently signed-in user (or null). See the [User](/docs/api/authentication.md#user) class documentation for further usage.
##### `currentUser: User | null` - Returns the currently signed-in user (or null). See the [User](/modules/authentication.md#user) class documentation for further usage.
### Methods

View File

@ -154,7 +154,7 @@ RCT_EXPORT_METHOD(getMetadata: (NSString *) path resolver:(RCTPromiseResolveBloc
*/
RCT_EXPORT_METHOD(updateMetadata: (NSString *) path metadata:(NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
FIRStorageReference *fileRef = [self getReference:path];
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata];
FIRStorageMetadata *firmetadata = [self buildMetadataFromMap:metadata];
[fileRef updateMetadata:firmetadata completion:^(FIRStorageMetadata * _Nullable metadata, NSError * _Nullable error) {
if (error != nil) {
@ -317,14 +317,14 @@ RCT_EXPORT_METHOD(putFile:(NSString *) path localPath:(NSString *)localPath meta
- (void) uploadFile:(NSURL *) url metadata:(NSDictionary *) metadata path:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
FIRStorageReference *fileRef = [self getReference:path];
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata];
FIRStorageMetadata *firmetadata = [self buildMetadataFromMap:metadata];
FIRStorageUploadTask *uploadTask = [fileRef putFile:url metadata:firmetadata];
[self addUploadObservers:uploadTask path:path resolver:resolve rejecter:reject];
}
- (void) uploadData:(NSData *) data metadata:(NSDictionary *) metadata path:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject{
FIRStorageReference *fileRef = [self getReference:path];
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata];
FIRStorageMetadata *firmetadata = [self buildMetadataFromMap:metadata];
FIRStorageUploadTask *uploadTask = [fileRef putData:data metadata:firmetadata];
[self addUploadObservers:uploadTask path:path resolver:resolve rejecter:reject];
}
@ -394,6 +394,13 @@ RCT_EXPORT_METHOD(putFile:(NSString *) path localPath:(NSString *)localPath meta
};
}
- (FIRStorageMetadata *)buildMetadataFromMap:(NSDictionary *)metadata {
NSMutableDictionary *result = [metadata mutableCopy];
result[@"metadata"] = metadata[@"customMetadata"];
[result removeObjectForKey:@"customMetadata"];
return [[FIRStorageMetadata alloc] initWithDictionary:result];
}
- (NSString *)getTaskStatus:(FIRStorageTaskStatus)status {
if (status == FIRStorageTaskStatusResume || status == FIRStorageTaskStatusProgress) {
return @"running";

View File

@ -56,7 +56,7 @@ export default class Crash {
* @param maxStackSize
*/
report(error: FirebaseError, maxStackSize: number = 10): void {
if (!error || !error.code || !error.message) return;
if (!error || !error.message) return;
let errorMessage = `Message: ${error.message}\r\n`;