Skip to content

Commit

Permalink
fix(API): Fixing issue with CN endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisebas committed Dec 12, 2024
1 parent 2a17a77 commit 001c485
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extension AppSyncRealTimeClientFactory {
return url
}

guard host.hasSuffix("amazonaws.com") else {
guard host.hasSuffix("amazonaws.com") || host.hasSuffix("amazonaws.com.cn") else {
return url.appendingPathComponent("realtime")
}

Expand All @@ -163,7 +163,7 @@ extension AppSyncRealTimeClientFactory {
return url
}

guard host.hasSuffix("amazonaws.com") else {
guard host.hasSuffix("amazonaws.com") || host.hasSuffix("amazonaws.com.cn") else {
if url.lastPathComponent == "realtime" {
return url.deletingLastPathComponent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint),
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com/graphql")
)

let appSyncEndpointCN = URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")!
XCTAssertEqual(
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN),
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")
)
}

func testAppSyncRealTimeEndpoint_withAWSAppSyncRealTimeDomain_returnTheSameDomain() {
Expand All @@ -25,6 +31,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint),
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com/graphql")
)

let appSyncEndpointCN = URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")!
XCTAssertEqual(
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN),
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")
)
}

func testAppSyncRealTimeEndpoint_withCustomDomain_returnCorrectRealtimePath() {
Expand All @@ -33,6 +45,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint),
URL(string: "https://test.example.com/graphql/realtime")
)

let appSyncEndpointCN = URL(string: "https://test.example.com.cn/graphql")!
XCTAssertEqual(
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN),
URL(string: "https://test.example.com.cn/graphql/realtime")
)
}

func testAppSyncApiEndpoint_withAWSAppSyncRealTimeDomain_returnCorrectApiDomain() {
Expand All @@ -41,6 +59,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint),
URL(string: "https://abc.appsync-api.amazonaws.com/graphql")
)

let appSyncEndpointCN = URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")!
XCTAssertEqual(
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN),
URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")
)
}

func testAppSyncApiEndpoint_withAWSAppSyncApiDomain_returnTheSameDomain() {
Expand All @@ -49,6 +73,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint),
URL(string: "https://abc.appsync-api.amazonaws.com/graphql")
)

let appSyncEndpointCN = URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")!
XCTAssertEqual(
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN),
URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")
)
}

func testAppSyncApiEndpoint_withCustomDomain_returnCorrectRealtimePath() {
Expand All @@ -57,5 +87,11 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint),
URL(string: "https://test.example.com/graphql")
)

let appSyncEndpointCN = URL(string: "https://test.example.com.cn/graphql")!
XCTAssertEqual(
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN),
URL(string: "https://test.example.com.cn/graphql")
)
}
}

0 comments on commit 001c485

Please sign in to comment.