1// Copyright 2021-present 650 Industries. All rights reserved.
2
3#import <XCTest/XCTest.h>
4
5#import <EXDevLauncher/EXDevLauncherUpdatesHelper.h>
6
7@interface EXDevLauncherUpdatesHelperTests : XCTestCase
8
9@end
10
11@implementation EXDevLauncherUpdatesHelperTests
12
13- (void)testCreateUpdatesConfiguration_scopeKey
14{
15  NSString *urlString1 = @"https://exp.host/@test/first-app";
16  NSURL *url1 = [NSURL URLWithString:urlString1];
17  NSDictionary *configuration1 = [EXDevLauncherUpdatesHelper createUpdatesConfigurationWithURL:url1 projectURL:url1 installationID:@"test-installation-id"];
18
19  NSString *urlString2 = @"https://exp.host/@test/second-app";
20  NSURL *url2 = [NSURL URLWithString:urlString2];
21  NSDictionary *configuration2 = [EXDevLauncherUpdatesHelper createUpdatesConfigurationWithURL:url2 projectURL:url2 installationID:@"test-installation-id"];
22
23  NSString *scopeKey1 = configuration1[@"EXUpdatesScopeKey"];
24  NSString *scopeKey2 = configuration2[@"EXUpdatesScopeKey"];
25  XCTAssertNotEqualObjects(scopeKey1, scopeKey2);
26  XCTAssertEqualObjects(urlString1, scopeKey1);
27  XCTAssertEqualObjects(urlString2, scopeKey2);
28}
29
30- (void)testCreateUpdatesConfiguration_differentProjectURL
31{
32  NSString *urlString = @"https://u.expo.dev/update/421ba616-9145-4236-8fe8-7be9f2782a30";
33  NSString *projectURLString = @"https://u.expo.dev/2f662161-8616-4f16-9f88-911dfb2d3cd6?channel-name=production";
34  NSDictionary *configuration = [EXDevLauncherUpdatesHelper createUpdatesConfigurationWithURL:[NSURL URLWithString:urlString] projectURL:[NSURL URLWithString:projectURLString] installationID:@"test"];
35
36  NSString *updatesURL = configuration[@"EXUpdatesURL"];
37  NSString *updatesScopeKey = configuration[@"EXUpdatesScopeKey"];
38
39  XCTAssertNotEqualObjects(updatesURL, updatesScopeKey);
40  XCTAssertEqualObjects(urlString, updatesURL);
41  XCTAssertEqualObjects(projectURLString, updatesScopeKey);
42}
43
44- (void)testCreateUpdatesConfiguration_installationID
45{
46  NSString *installationID = @"test-installation-id";
47  NSURL *url = [NSURL URLWithString:@"https://exp.host/@test/test"];
48  NSDictionary *configuration = [EXDevLauncherUpdatesHelper createUpdatesConfigurationWithURL:url projectURL:url installationID:installationID];
49
50  NSDictionary *requestHeaders = configuration[@"EXUpdatesRequestHeaders"];
51  XCTAssertNotNil(requestHeaders);
52  XCTAssertEqualObjects(installationID, requestHeaders[@"Expo-Dev-Client-ID"]);
53}
54
55@end
56