Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
chore: remove code in the code base around discover hardcoded path (#…
Browse files Browse the repository at this point in the history
…1793)

* chore: remove code in the code base around discover hardcoded path

* fix: fix test cases

* fix: fix broken tests
  • Loading branch information
saeedbashir committed Sep 11, 2023
1 parent 170ac0e commit e2037c5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
6 changes: 1 addition & 5 deletions Source/OEXFindCoursesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

static NSString* const OEXFindCoursesCourseInfoPath = @"course_info/";
static NSString* const OEXFindCoursesPathIDKey = @"path_id";
static NSString* const OEXFindCoursePathPrefix = @"course/";

@interface OEXFindCoursesViewController () <WebViewNavigationDelegate, InterfaceOrientationOverriding>

Expand Down Expand Up @@ -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/<path_id>" 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;
}
Expand Down
4 changes: 1 addition & 3 deletions Source/WebView/DiscoveryHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import UIKit
enum URIString: String {
case appURLScheme = "edxapp"
case pathPlaceHolder = "{path_id}"
case coursePathPrefix = "course/"
}

fileprivate enum URLParameterKeys: String, RawStringExtractable {
Expand Down Expand Up @@ -47,8 +46,7 @@ enum WebviewActions: String {
return nil
}

// the site sends us things of the form "course/<path_id>" 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)? {
Expand Down
4 changes: 2 additions & 2 deletions Test/DiscoveryHelperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions Test/OEXFindCoursesTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit e2037c5

Please sign in to comment.