Skip to content

Commit 19351b8

Browse files
committed
fix: tests for swift
1 parent b9460ab commit 19351b8

File tree

4 files changed

+11
-34
lines changed

4 files changed

+11
-34
lines changed

templates/apple/Sources/Client.swift.twig

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,9 @@ open class Client {
136136
/// @throws Exception
137137
///
138138
open func setEndpoint(_ endPoint: String) throws -> Client {
139-
guard endPoint.hasPrefix("http://") || endPoint.hasPrefix("https://") else {
139+
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
140140
throw {{spec.title | caseUcfirst}}Error(
141-
message: "Invalid endpoint URL: \(endPoint)",
142-
code: 0,
143-
type: "",
144-
response: ""
141+
message: "Invalid endpoint URL: \(endPoint)"
145142
)
146143
}
147144

@@ -162,12 +159,9 @@ open class Client {
162159
/// @throws Exception
163160
///
164161
open func setEndpointRealtime(_ endPoint: String) throws -> Client {
165-
guard endPoint.hasPrefix("ws://") || endPoint.hasPrefix("wss://") else {
162+
if !endPoint.hasPrefix("ws://") && !endPoint.hasPrefix("wss://") {
166163
throw {{spec.title | caseUcfirst}}Error(
167-
message: "Invalid realtime endpoint URL: \(endPoint)",
168-
code: 0,
169-
type: "",
170-
response: ""
164+
message: "Invalid realtime endpoint URL: \(endPoint)"
171165
)
172166
}
173167

templates/swift/Sources/Client.swift.twig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,10 @@ open class Client {
132132
/// @return Client
133133
/// @throws Exception
134134
///
135-
open func setEndpoint(_ endPoint: String) -> Client {
135+
open func setEndpoint(_ endPoint: String) throws -> Client {
136136
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
137137
throw {{spec.title | caseUcfirst}}Error(
138-
message: "Invalid endpoint URL: \(endPoint)",
139-
code: 0,
140-
type: "",
141-
response: ""
138+
message: "Invalid endpoint URL: \(endPoint)"
142139
)
143140
}
144141

templates/web/src/client.ts.twig

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,7 @@ class Client {
330330
* @returns {this}
331331
*/
332332
setEndpoint(endpoint: string): this {
333-
try {
334-
const url = new URL(endpoint);
335-
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
336-
throw new Error();
337-
}
338-
} catch {
333+
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
339334
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
340335
}
341336

@@ -353,13 +348,8 @@ class Client {
353348
* @returns {this}
354349
*/
355350
setEndpointRealtime(endpointRealtime: string): this {
356-
try {
357-
const url = new URL(endpointRealtime);
358-
if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
359-
throw new Error();
360-
}
361-
} catch {
362-
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpointRealtime);
351+
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
352+
throw new {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: ' + endpointRealtime);
363353
}
364354

365355
this.config.endpointRealtime = endpointRealtime;

tests/languages/apple/Tests.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ class Tests: XCTestCase {
3131
print(pingResult)
3232

3333
// reset configs
34-
try {
35-
client.setProject("console")
36-
.setEndpointRealtime("ws://cloud.appwrite.io/v1")
37-
} catch {
38-
print(error.localizedDescription)
39-
}
34+
client.setProject("console")
35+
try client.setEndpointRealtime("ws://cloud.appwrite.io/v1")
4036

4137
let foo = Foo(client)
4238
let bar = Bar(client)

0 commit comments

Comments
 (0)