1#import <XCTest/XCTest.h> 2 3#import "EXClientTestCase.h" 4#import "EXEnvironment.h" 5#import "EXFileDownloader.h" 6 7@interface EXFileDownloaderTests : EXClientTestCase 8 9@end 10 11@implementation EXFileDownloaderTests 12 13- (void)setUp 14{ 15 [super setUp]; 16 17 if ([EXEnvironment sharedEnvironment].testEnvironment == EXTestEnvironmentNone) { 18 [EXEnvironment sharedEnvironment].testEnvironment = EXTestEnvironmentLocal; 19 } 20} 21 22#pragma mark - file downloader 23 24- (void)testIsExpoSDKVersionHeaderConfigured 25{ 26 NSURLRequest *request = [self _mockJsBundleDownloadRequest]; 27 NSString *sdkVersionHeader = [request valueForHTTPHeaderField:@"Exponent-SDK-Version"]; 28 NSArray *sdkVersions = [sdkVersionHeader componentsSeparatedByString:@","]; 29 XCTAssert(sdkVersions.count > 0, @"Expo SDK version header should contain at least one comma-separated SDK version"); 30} 31 32- (void)testAreOtherHeadersConfigured 33{ 34 NSURLRequest *request = [self _mockJsBundleDownloadRequest]; 35 NSArray<NSString *> *requiredHeaderFields = @[ 36 @"Exponent-SDK-Version", 37 @"Exponent-Platform", 38 @"Exponent-Accept-Signature", 39 ]; 40 for (NSString *header in requiredHeaderFields) { 41 NSString *headerValue = [request valueForHTTPHeaderField:header]; 42 XCTAssert((headerValue != nil), @"HTTP header %@ should be set", header); 43 } 44} 45 46- (void)testDoesDefaultFileDownloaderDownloadSomething 47{ 48 XCTestExpectation *expectToDownload = [[XCTestExpectation alloc] initWithDescription:@"Default EXFileDownloader should download a json file"]; 49 EXFileDownloader *fileDownloader = [[EXFileDownloader alloc] init]; 50 NSURL *jsonFileUrl = [NSURL URLWithString:@"https://expo.io/@exponent/home/index.exp"]; 51 [fileDownloader downloadFileFromURL:jsonFileUrl successBlock:^(NSData * _Nonnull data, NSURLResponse * _Nonnull response) { 52 [expectToDownload fulfill]; 53 } errorBlock:^(NSError * _Nonnull error, NSURLResponse * _Nonnull response) {}]; 54 [self waitForExpectations:@[ expectToDownload ] timeout:10.0]; 55} 56 57#pragma mark - internal 58 59- (NSMutableURLRequest *)_mockJsBundleDownloadRequest 60{ 61 // mock a url request for a JS bundle 62 NSMutableURLRequest *jsBundleDownloadRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://exp.host/@exponent/home/bundle"]]; 63 EXFileDownloader *downloader = [[EXFileDownloader alloc] init]; 64 [downloader setHTTPHeaderFields:jsBundleDownloadRequest]; 65 return jsBundleDownloadRequest; 66} 67 68@end 69