aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example
diff options
context:
space:
mode:
authorGravatar Sebastian Schmidt <mrschmidt@google.com>2017-09-06 14:37:04 -0700
committerGravatar GitHub <noreply@github.com>2017-09-06 14:37:04 -0700
commite8e0916c2ae24ec14130b1dc00f9574d78940462 (patch)
tree92554ccf9e084f62546b85ad035e71c005a3d67a /Example
parent96685dfbb9936ec9b875491ccad9891231afd7ba (diff)
Firebase Storage: Allowing metadata to be cleared (#197)
* Allowing metadata to be cleared
Diffstat (limited to 'Example')
-rw-r--r--Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m72
-rw-r--r--Example/Storage/Tests/Unit/FIRStorageMetadataTests.m49
-rw-r--r--Example/Storage/Tests/Unit/FIRStorageUpdateMetadataTests.m4
3 files changed, 124 insertions, 1 deletions
diff --git a/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m b/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m
index 882d45e..0e07d97 100644
--- a/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m
+++ b/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m
@@ -454,6 +454,78 @@ NSTimeInterval kFIRStorageIntegrationTestTimeout = 30;
[self waitForExpectations];
}
+- (void)assertMetadata:(FIRStorageMetadata *) actualMetadata
+ contentType:(NSString *) expectedContentType
+ customMetadata:(NSDictionary *) expectedCustomMetadata {
+ XCTAssertEqualObjects(actualMetadata.cacheControl, @"cache-control");
+ XCTAssertEqualObjects(actualMetadata.contentDisposition, @"content-disposition");
+ XCTAssertEqualObjects(actualMetadata.contentEncoding, @"gzip");
+ XCTAssertEqualObjects(actualMetadata.contentLanguage, @"de");
+ XCTAssertEqualObjects(actualMetadata.contentType, expectedContentType);
+ for (NSString* key in expectedCustomMetadata) {
+ XCTAssertEqualObjects([actualMetadata.customMetadata objectForKey:key],
+ [expectedCustomMetadata objectForKey:key]);
+ }
+}
+
+- (void)assertMetadataNil:(FIRStorageMetadata *) actualMetadata {
+ XCTAssertNil(actualMetadata.cacheControl);
+ XCTAssertNil(actualMetadata.contentDisposition);
+ XCTAssertEqualObjects(actualMetadata.contentEncoding, @"identity");
+ XCTAssertNil(actualMetadata.contentLanguage);
+ XCTAssertNil(actualMetadata.contentType);
+ XCTAssertNil([actualMetadata.customMetadata objectForKey:@"a"]);
+ XCTAssertNil([actualMetadata.customMetadata objectForKey:@"c"]);
+ XCTAssertNil([actualMetadata.customMetadata objectForKey:@"f"]);
+}
+
+- (void)testUpdateMetadata {
+ XCTestExpectation *expectation = [self expectationWithDescription:@"testUpdateMetadata"];
+
+ FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
+
+ // Update all available metadata
+ FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] init];
+ metadata.cacheControl = @"cache-control";
+ metadata.contentDisposition = @"content-disposition";
+ metadata.contentEncoding = @"gzip";
+ metadata.contentLanguage = @"de";
+ metadata.contentType = @"content-type-a";
+ metadata.customMetadata = @{@"a" : @"b"};
+
+ [ref updateMetadata:metadata completion:^(FIRStorageMetadata *updatedMetadata, NSError *error) {
+ XCTAssertNil(error);
+ [self assertMetadata:updatedMetadata contentType:@"content-type-a" customMetadata:@{@"a" : @"b"}];
+
+ // Update a subset of the metadata using the existing object.
+ FIRStorageMetadata *metadata = updatedMetadata;
+ metadata.contentType = @"content-type-b";
+ metadata.customMetadata = @{@"a" : @"b", @"c" : @"d"};
+
+ [ref updateMetadata:metadata completion:^(FIRStorageMetadata *updatedMetadata, NSError *error) {
+ XCTAssertNil(error);
+ [self assertMetadata:updatedMetadata contentType:@"content-type-b" customMetadata: @{@"a" : @"b", @"c" : @"d"}];
+
+ // Clear all metadata.
+ FIRStorageMetadata *metadata = updatedMetadata;
+ metadata.cacheControl = nil;
+ metadata.contentDisposition = nil;
+ metadata.contentEncoding = nil;
+ metadata.contentLanguage = nil;
+ metadata.contentType = nil;
+ metadata.customMetadata = [NSDictionary dictionary];
+
+ [ref updateMetadata:metadata completion:^(FIRStorageMetadata *updatedMetadata, NSError *error) {
+ XCTAssertNil(error);
+ [self assertMetadataNil:updatedMetadata];
+ [expectation fulfill];
+ }];
+ }];
+ }];
+
+ [self waitForExpectations];
+}
+
- (void)testUnauthenticatedResumeGetFile {
XCTestExpectation *expectation =
[self expectationWithDescription:@"testUnauthenticatedResumeGetFile"];
diff --git a/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m b/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m
index 92e96bb..e750bdf 100644
--- a/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m
+++ b/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m
@@ -244,6 +244,55 @@
XCTAssertEqualObjects(metadata0, metadata1);
}
+- (void)testUpdatedMetadata {
+ NSDictionary *oldMetadata = @{
+ kFIRStorageMetadataContentLanguage : @"old",
+ kFIRStorageMetadataCustomMetadata : @{@"foo" : @"old", @"bar" : @"old"}
+ };
+ FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:oldMetadata];
+ metadata.contentLanguage = @"new";
+ metadata.customMetadata = @{@"foo" : @"new", @"bar" : @"old"};
+
+ NSDictionary *update = [metadata updatedMetadata];
+
+ NSDictionary *expectedUpdate = @{
+ kFIRStorageMetadataContentLanguage : @"new",
+ kFIRStorageMetadataCustomMetadata : @{@"foo" : @"new"}
+ };
+ XCTAssertEqualObjects(update, expectedUpdate);
+}
+
+- (void)testUpdatedMetadataWithEmptyUpdate {
+ NSDictionary *oldMetadata = @{
+ kFIRStorageMetadataContentLanguage : @"old",
+ kFIRStorageMetadataCustomMetadata : @{@"foo" : @"old", @"bar" : @"old"}
+ };
+ FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:oldMetadata];
+
+ NSDictionary *update = [metadata updatedMetadata];
+
+ NSDictionary *expectedUpdate = @{ kFIRStorageMetadataCustomMetadata : @{} };
+ XCTAssertEqualObjects(update, expectedUpdate);
+}
+
+- (void)testUpdatedMetadataWithDelete {
+ NSDictionary *oldMetadata = @{
+ kFIRStorageMetadataContentLanguage : @"old",
+ kFIRStorageMetadataCustomMetadata : @{@"foo" : @"old", @"bar" : @"old"}
+ };
+ FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:oldMetadata];
+ metadata.contentLanguage = nil;
+ metadata.customMetadata = @{@"foo" : @"old"};
+
+ NSDictionary *update = [metadata updatedMetadata];
+
+ NSDictionary *expectedUpdate = @{
+ kFIRStorageMetadataContentLanguage : [NSNull null],
+ kFIRStorageMetadataCustomMetadata : @{@"bar" : [NSNull null]}
+ };
+ XCTAssertEqualObjects(update, expectedUpdate);
+}
+
- (void)testMetadataHashEquality {
NSDictionary *metaDict = @{
kFIRStorageMetadataBucket : @"bucket",
diff --git a/Example/Storage/Tests/Unit/FIRStorageUpdateMetadataTests.m b/Example/Storage/Tests/Unit/FIRStorageUpdateMetadataTests.m
index a85d181..d2d2950 100644
--- a/Example/Storage/Tests/Unit/FIRStorageUpdateMetadataTests.m
+++ b/Example/Storage/Tests/Unit/FIRStorageUpdateMetadataTests.m
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#import "FIRStorageMetadata_Private.h"
#import "FIRStorageTestHelpers.h"
#import "FIRStorageUpdateMetadataTask.h"
@@ -63,7 +64,7 @@
#pragma clang diagnostic ignored "-Warc-retain-cycles"
XCTAssertEqualObjects(fetcher.request.URL, [FIRStorageTestHelpers objectURL]);
XCTAssertEqualObjects(fetcher.request.HTTPMethod, @"PATCH");
- NSData *bodyData = [NSData frs_dataFromJSONDictionary:[self.metadata dictionaryRepresentation]];
+ NSData *bodyData = [NSData frs_dataFromJSONDictionary:[self.metadata updatedMetadata]];
XCTAssertEqualObjects(fetcher.request.HTTPBody, bodyData);
NSDictionary *HTTPHeaders = fetcher.request.allHTTPHeaderFields;
XCTAssertEqualObjects(HTTPHeaders[@"Content-Type"], @"application/json; charset=UTF-8");
@@ -75,6 +76,7 @@
HTTPVersion:kHTTPVersion
headerFields:nil];
response(httpResponse, nil, nil);
+ self.fetcherService.testBlock = nil;
};
FIRStoragePath *path = [FIRStorageTestHelpers objectPath];