diff --git a/Source/OEXFindCoursesViewController.m b/Source/OEXFindCoursesViewController.m index 3b4767a41e..5da3e99c78 100644 --- a/Source/OEXFindCoursesViewController.m +++ b/Source/OEXFindCoursesViewController.m @@ -20,7 +20,6 @@ static NSString* const OEXFindCoursesCourseInfoPath = @"course_info/"; static NSString* const OEXFindCoursesPathIDKey = @"path_id"; -static NSString* const OEXFindCoursePathPrefix = @"course/"; @interface OEXFindCoursesViewController () @@ -100,10 +99,7 @@ - (DiscoveryConfig*)discoveryConfig { - (NSString*)getCoursePathIDFromURL:(NSURL*)url { if([url.scheme isEqualToString:OEXFindCoursesLinkURLScheme] && [url.oex_hostlessPath isEqualToString:OEXFindCoursesCourseInfoPath]) { - NSString* path = url.oex_queryParameters[OEXFindCoursesPathIDKey]; - // the site sends us things of the form "course/" we only want the path id - NSString* pathID = [path stringByReplacingOccurrencesOfString:OEXFindCoursePathPrefix withString:@"" options:0 range:NSMakeRange(0, OEXFindCoursePathPrefix.length)]; - return pathID; + return url.oex_queryParameters[OEXFindCoursesPathIDKey]; } return nil; } diff --git a/Source/WebView/DiscoveryHelper.swift b/Source/WebView/DiscoveryHelper.swift index f0afc3453c..8dcd88568f 100644 --- a/Source/WebView/DiscoveryHelper.swift +++ b/Source/WebView/DiscoveryHelper.swift @@ -12,7 +12,6 @@ import UIKit enum URIString: String { case appURLScheme = "edxapp" case pathPlaceHolder = "{path_id}" - case coursePathPrefix = "course/" } fileprivate enum URLParameterKeys: String, RawStringExtractable { @@ -47,8 +46,7 @@ enum WebviewActions: String { return nil } - // the site sends us things of the form "course/" we only want the path id - return path.replacingOccurrences(of: URIString.coursePathPrefix.rawValue, with: "") + return path } class func parse(url: URL) -> (courseId: String?, emailOptIn: Bool)? { diff --git a/Test/DiscoveryHelperTests.swift b/Test/DiscoveryHelperTests.swift index e960ffdb41..cfdaa12bb4 100644 --- a/Test/DiscoveryHelperTests.swift +++ b/Test/DiscoveryHelperTests.swift @@ -9,10 +9,10 @@ import XCTest @testable import edX -private let sampleInvalidProgramDetailURL = "//course_info?path_id=course/usmx-corporate-finance" +private let sampleInvalidProgramDetailURL = "//course_info?path_id=usmx-corporate-finance" private let sampleEnrolledProgramDetailURL = "edxapp://enrolled_program_info?path_id=programs/a3951294-926b-4247-8c3c-51c1e4347a15/details_fragment" private let sampleEnrolledCourseDetailURL = "edxapp://enrolled_course_info?course_id=course-v1:USMx+BUMM612+2T2018" -private let sampleProgramCourseURL = "edxapp://course_info?path_id=course/usmx-corporate-finance" +private let sampleProgramCourseURL = "edxapp://course_info?path_id=usmx-corporate-finance" private let sampleCourseEnrollmentURL = "edxapp://enroll?course_id=course-v1:USMx+BUMM610+3T2018&email_opt_in=true" private let sampleProgramURL = "https://example.com/dashboard/programs_fragment/?mobile_only=true" private let sampleInvalidProgramURLTemplate = "https://example.com/dashboard/mobile_only=true" diff --git a/Test/OEXFindCoursesTests.m b/Test/OEXFindCoursesTests.m index 88d3399cd4..40518faddd 100644 --- a/Test/OEXFindCoursesTests.m +++ b/Test/OEXFindCoursesTests.m @@ -81,17 +81,17 @@ -(void)testFindCoursesURLRecognition{ RouterEnvironment *environment = [self mockRouterEnvironment]; DiscoveryWebViewHelper* helper = [[DiscoveryWebViewHelper alloc] initWithEnvironment:environment delegate:nil bottomBar:nil searchQuery:nil]; OEXFindCoursesViewController *findCoursesViewController = [[OEXFindCoursesViewController alloc] init]; - NSURLRequest *testURLRequestCorrect = [NSURLRequest requestWithURL:[NSURL URLWithString:@"edxapp://course_info?path_id=course/science-happiness-uc-berkeleyx-gg101x"]]; + NSURLRequest *testURLRequestCorrect = [NSURLRequest requestWithURL:[NSURL URLWithString:@"edxapp://course_info?path_id=science-happiness-uc-berkeleyx-gg101x"]]; BOOL successCorrect = ![findCoursesViewController webView:helper.t_webView shouldLoad:testURLRequestCorrect]; XCTAssert(successCorrect, @"Correct URL not recognized"); - NSURLRequest *testURLRequestWrong = [NSURLRequest requestWithURL:[NSURL URLWithString:@"edxapps://course_infos?path_id=course/science-happiness-uc-berkeleyx-gg101x"]]; + NSURLRequest *testURLRequestWrong = [NSURLRequest requestWithURL:[NSURL URLWithString:@"edxapps://course_infos?path_id=science-happiness-uc-berkeleyx-gg101x"]]; BOOL successWrong = [findCoursesViewController webView:helper.t_webView shouldLoad:testURLRequestWrong]; XCTAssert(successWrong, @"Wrong URL not recognized"); } -(void)testPathIDParsing{ - NSURL *testURL = [NSURL URLWithString:@"edxapp://course_info?path_id=course/science-happiness-uc-berkeleyx-gg101x"]; + NSURL *testURL = [NSURL URLWithString:@"edxapp://course_info?path_id=science-happiness-uc-berkeleyx-gg101x"]; OEXFindCoursesViewController *findCoursesViewController = [[OEXFindCoursesViewController alloc] init]; NSString *pathID = [findCoursesViewController getCoursePathIDFromURL:testURL];