New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore project preview deep-links #538
Changes from all commits
feb024a
6303888
9c2afe1
60fa45d
2cf8a14
75cfd98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ public enum Navigation { | |
case signup | ||
case tab(Tab) | ||
case project(Param, Navigation.Project, refTag: RefTag?) | ||
case projectPreview(Param, Navigation.Project, refTag: RefTag?, token: String) | ||
case user(Param, Navigation.User) | ||
|
||
public enum Checkout { | ||
|
@@ -91,6 +92,9 @@ public func == (lhs: Navigation, rhs: Navigation) -> Bool { | |
return lhs == rhs | ||
case let (.project(lhsParam, lhsProject, lhsRefTag), .project(rhsParam, rhsProject, rhsRefTag)): | ||
return lhsParam == rhsParam && lhsProject == rhsProject && lhsRefTag == rhsRefTag | ||
case let (.projectPreview(lhsParam, lhsProject, lhsRefTag, lhsToken), | ||
.projectPreview(rhsParam, rhsProject, rhsRefTag, rhsToken)): | ||
return lhsParam == rhsParam && lhsProject == rhsProject && lhsRefTag == rhsRefTag && lhsToken == rhsToken | ||
case let (.user(lhsParam, lhsUser), .user(rhsParam, rhsUser)): | ||
return lhsParam == rhsParam && lhsUser == rhsUser | ||
default: | ||
|
@@ -401,10 +405,22 @@ private func signup(_: RouteParams) -> Decoded<Navigation> { | |
} | ||
|
||
private func project(_ params: RouteParams) -> Decoded<Navigation> { | ||
return curry(Navigation.project) | ||
let projectPreview = curry(Navigation.projectPreview) | ||
<^> params <| "project_param" | ||
<*> .success(.root) | ||
<*> params <|? "ref" | ||
<*> params <| "token" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Treats |
||
|
||
// If we're certain this is not a project preview link, try to decode it as a normal project link. | ||
if case .failure = projectPreview { | ||
return curry(Navigation.project) | ||
<^> params <| "project_param" | ||
<*> .success(.root) | ||
<*> params <|? "ref" | ||
} | ||
|
||
// Fail here as we don't currently support project preview links. | ||
return .failure(.custom("Project preview links are unsupported")) | ||
} | ||
|
||
private func thanks(_ params: RouteParams) -> Decoded<Navigation> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import Prelude | |
import XCTest | ||
@testable import Library | ||
|
||
private func KSRAssertMatch(_ expected: Navigation, | ||
private func KSRAssertMatch(_ expected: Navigation?, | ||
_ path: String, | ||
file: StaticString = #file, | ||
line: UInt = #line) { | ||
|
@@ -38,6 +38,10 @@ public final class NavigationTests: XCTestCase { | |
KSRAssertMatch(.project(.slug("project"), .root, refTag: nil), | ||
"/projects/creator/project") | ||
|
||
KSRAssertMatch(nil, "/projects/creator/project?token=4") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just proves that we get a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder whether we should also add |
||
|
||
KSRAssertMatch(nil, "/projects/creator/project?ref=discovery&token=4") | ||
|
||
KSRAssertMatch(.project(.slug("project"), .checkout(1, .thanks(racing: nil)), refTag: nil), | ||
"/projects/creator/project/checkouts/1/thanks") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is essentially the same as the one above it but it explicitly uses a known project preview link (containing
token
query param) to test that it will be ignored.