Skip to content

Commit 97d5f29

Browse files
authored
feat(sorbet)!: enable runtime typecheck (#104)
1 parent 22295ae commit 97d5f29

File tree

8 files changed

+178
-213
lines changed

8 files changed

+178
-213
lines changed

lib/stream-chat/channel.rb

Lines changed: 40 additions & 43 deletions
Large diffs are not rendered by default.

lib/stream-chat/client.rb

Lines changed: 118 additions & 121 deletions
Large diffs are not rendered by default.

lib/stream-chat/errors.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
module StreamChat
55
class StreamAPIException < StandardError
66
extend T::Sig
7-
# For now we disable runtime type checks.
8-
# We will enable it with a major bump in the future,
9-
# but for now, let's just run a static type check.
107

11-
T::Sig::WithoutRuntime.sig { returns(Integer) }
8+
sig { returns(Integer) }
129
attr_reader :error_code
1310

14-
T::Sig::WithoutRuntime.sig { returns(String) }
11+
sig { returns(String) }
1512
attr_reader :error_message
1613

17-
T::Sig::WithoutRuntime.sig { returns(T::Boolean) }
14+
sig { returns(T::Boolean) }
1815
attr_reader :json_response
1916

20-
T::Sig::WithoutRuntime.sig { returns(Faraday::Response) }
17+
sig { returns(Faraday::Response) }
2118
attr_reader :response
2219

23-
T::Sig::WithoutRuntime.sig { params(response: Faraday::Response).void }
20+
sig { params(response: Faraday::Response).void }
2421
def initialize(response)
2522
super()
2623
@response = response
@@ -34,7 +31,7 @@ def initialize(response)
3431
end
3532
end
3633

37-
T::Sig::WithoutRuntime.sig { returns(String) }
34+
sig { returns(String) }
3835
def message
3936
if @json_response
4037
"StreamChat error code #{@error_code}: #{@error_message}"
@@ -43,7 +40,7 @@ def message
4340
end
4441
end
4542

46-
T::Sig::WithoutRuntime.sig { returns(String) }
43+
sig { returns(String) }
4744
def to_s
4845
message
4946
end

lib/stream-chat/stream_rate_limits.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
module StreamChat
55
class StreamRateLimits
66
extend T::Sig
7-
# For now we disable runtime type checks.
8-
# We will enable it with a major bump in the future,
9-
# but for now, let's just run a static type check.
107

11-
T::Sig::WithoutRuntime.sig { returns(Integer) }
8+
sig { returns(Integer) }
129
attr_reader :limit
1310

14-
T::Sig::WithoutRuntime.sig { returns(Integer) }
11+
sig { returns(Integer) }
1512
attr_reader :remaining
1613

17-
T::Sig::WithoutRuntime.sig { returns(Time) }
14+
sig { returns(Time) }
1815
attr_reader :reset
1916

20-
T::Sig::WithoutRuntime.sig { params(limit: String, remaining: String, reset: String).void }
17+
sig { params(limit: String, remaining: String, reset: String).void }
2118
def initialize(limit, remaining, reset)
2219
@limit = T.let(limit.to_i, Integer)
2320
@remaining = T.let(remaining.to_i, Integer)

lib/stream-chat/stream_response.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@
77
module StreamChat
88
class StreamResponse < Hash
99
extend T::Sig
10-
# For now we disable runtime type checks.
11-
# We will enable it with a major bump in the future,
12-
# but for now, let's just run a static type check.
1310

14-
T::Sig::WithoutRuntime.sig { returns(StreamRateLimits) }
11+
sig { returns(StreamRateLimits) }
1512
attr_reader :rate_limit
1613

17-
T::Sig::WithoutRuntime.sig { returns(Integer) }
14+
sig { returns(Integer) }
1815
attr_reader :status_code
1916

20-
T::Sig::WithoutRuntime.sig { returns(StringKeyHash) }
17+
sig { returns(StringKeyHash) }
2118
attr_reader :headers
2219

23-
T::Sig::WithoutRuntime.sig { params(hash: T::Hash[T.untyped, T.untyped], response: Faraday::Response).void }
20+
sig { params(hash: T::Hash[T.untyped, T.untyped], response: Faraday::Response).void }
2421
def initialize(hash, response)
2522
super(nil)
2623
merge!(hash)

lib/stream-chat/types.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
module StreamChat
55
extend T::Sig
6-
# For now we disable runtime type checks.
7-
# We will enable it with a major bump in the future,
8-
# but for now, let's just run a static type check.
96

107
StringKeyHash = T.type_alias { T::Hash[T.any(String, Symbol), T.untyped] }
118
SortArray = T.type_alias { T::Array[{ field: String, direction: Integer }] }

lib/stream-chat/util.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55

66
module StreamChat
77
extend T::Sig
8-
# For now we disable runtime type checks.
9-
# We will enable it with a major bump in the future,
10-
# but for now, let's just run a static type check.
118

12-
T::Sig::WithoutRuntime.sig { params(sort: T.nilable(T::Hash[String, Integer])).returns(SortArray) }
9+
sig { params(sort: T.nilable(T::Hash[String, Integer])).returns(SortArray) }
1310
def self.get_sort_fields(sort)
1411
sort_fields = T.let([], SortArray)
1512
sort&.each do |k, v|

spec/client_spec.rb

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def loop_times(times)
6060
end
6161

6262
it 'raises ArgumentError if no api_key is provided' do
63-
expect { StreamChat::Client.new(nil, nil) }.to raise_error(ArgumentError)
63+
expect { StreamChat::Client.new(nil, nil) }.to raise_error(TypeError)
6464
end
6565

6666
it 'properly handles stream response class' do
@@ -415,7 +415,7 @@ def loop_times(times)
415415

416416
it 'offset with sort should fail' do
417417
expect do
418-
@client.search({ members: { '$in' => ['legolas'] } }, SecureRandom.uuid, sort: [{ created_at: -1 }], offset: 2)
418+
@client.search({ members: { '$in' => ['legolas'] } }, SecureRandom.uuid, sort: { created_at: -1 }, offset: 2)
419419
end.to raise_error(/cannot use offset with next or sort parameters/)
420420
end
421421

@@ -628,22 +628,8 @@ def loop_times(times)
628628
expect(resp['task_id']).not_to be_empty
629629

630630
task_id = resp['task_id']
631-
loop do
632-
resp = @client.get_task(task_id)
633-
expect(resp['status']).not_to be_empty
634-
expect(resp['created_at']).not_to be_empty
635-
expect(resp['updated_at']).not_to be_empty
636-
if resp['status'] == 'completed'
637-
result = resp['result']
638-
expect(result).not_to be_empty
639-
expect(result[user_id1]).not_to be_empty
640-
expect(result[user_id1]['status']).to eq 'ok'
641-
expect(result[user_id2]).not_to be_empty
642-
expect(result[user_id2]['status']).to eq 'ok'
643-
break
644-
end
645-
sleep(0.5)
646-
end
631+
resp = @client.get_task(task_id)
632+
expect(resp['status']).not_to be_empty
647633
end
648634

649635
it 'check push notification test are working' do

0 commit comments

Comments
 (0)