flock_os 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 536333e971d283e30cc93652eeb16f985c2df8b3515ebbdf229b3a2471399ed0
4
- data.tar.gz: 4c6d7a2f00ef28ea772e8c802d24ea005d61921778fb0c0464dfc91d1ddd1f1e
3
+ metadata.gz: c2744e0d6da7cf08099fe98a00fcb03667bff47ba224f5a31a937bc3a52e3838
4
+ data.tar.gz: 34d4c7690b38cadd8c69de2ec39d5a1751216017c33597364d6f010775e467a7
5
5
  SHA512:
6
- metadata.gz: d91aa45f9ffbd707ceea1bba130a27e7cdd832df19345cb9ffda96d1762be802c2d2622eacc452ee366162ab35eb9b0e2f44e36af25fc44cebfe22f86fba0f8f
7
- data.tar.gz: 87e9d219b4200c98cb36deec4e3b9a441324b4d75d3efc9b0d0d57453c9c155a22b01146816acde98061844472560659cea478b27a98eb637703bb3affe88e46
6
+ metadata.gz: eafc8df537f37515b1ed94fc017558fe98a07e4a732d3500c86bda8cb81885615b0c07bf7a98a4fcaa952e6ef55bc82e82b0de0f1aabe0cf2a5996e4dc0aeb93
7
+ data.tar.gz: 606987185ba26f60429924fcbc8ce13ac0bee6454a081e2c75b73ab74e1810fc8ff8fa6a46643b87b9b3e5fc2e57370994a899119b07e3d19b61f63c487d58bf
@@ -35,12 +35,10 @@ module FlockOs
35
35
  FlockOs::Collection::Channel.new(response)
36
36
  end
37
37
 
38
- def list_members(channel_id)
39
- response = @client.post("#{PATH}.listMembers", {
40
- channelId: channel_id
41
- })
38
+ def list_members(params)
39
+ response = @client.post("#{PATH}.listMembers", params)
42
40
 
43
- FlockOs::Collection::Channel.new(response)
41
+ FlockOs::Collection::ChannelMember.new(response)
44
42
  end
45
43
 
46
44
  def remove_members(channel_id, members)
@@ -1,3 +1,3 @@
1
1
  module FlockOs
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -2,73 +2,32 @@ require 'spec_helper'
2
2
 
3
3
  describe FlockOs::Api::Channels do
4
4
  let(:client) { FlockOs::Client.new }
5
- let(:stub_fetch_response) do
6
- [
7
- {
8
- "from": "u:xxx",
9
- "to": "u:xxx",
10
- "uid": "fd4877b719b1",
11
- "text": "Hello"
12
- }
13
- ]
14
- end
15
-
16
- let(:send_message_params) do
5
+ let(:stub_add_members_response) do
17
6
  {
18
- "to": "u:xxx",
19
- "text": "Hello"
7
+ members: {
8
+ "u:id1": { status: "added" },
9
+ "u:id2": { status: "failed", error: "UserNotFound" }
10
+ }
20
11
  }
21
12
  end
22
-
23
- let(:stub_send_response) { { uid: 'uuid' } }
24
13
 
25
14
  subject(:chat) { described_class.new(client) }
15
+ subject(:add_member) { chat.add_members('channel_id', ['member']) }
26
16
 
27
17
  describe '#add_members' do
18
+ before do
19
+ allow_any_instance_of(FlockOs::Client).to receive(:post).and_return(stub_add_members_response)
20
+ end
21
+
28
22
  context 'when successfully fetch messages' do
29
23
  it 'return message collection class' do
30
- expect(chat.add_members('channel_id', ['member'])).to be_an FlockOs::Collection::Message
24
+ expect(add_member).to be_an FlockOs::Model::ModifyChannelMember
31
25
  end
32
26
 
33
- it 'return message collection class' do
34
- allow_any_instance_of(FlockOs::Client).to receive(:post).and_return(stub_fetch_response)
35
-
36
- response = chat.fetch_messages('chat', 'user_uids')
37
- messages = response.collection
38
- message = messages.first
39
-
40
- expect(messages.count).to eq 1
41
-
42
- expect(message.text).to eq stub_fetch_response.first[:text]
43
- expect(message.from).to eq stub_fetch_response.first[:from]
44
- expect(message.to).to eq stub_fetch_response.first[:to]
45
- expect(message.uid).to eq stub_fetch_response.first[:uid]
46
- end
47
- end
48
- end
49
-
50
- describe '#send_message' do
51
- context 'when successfully send message' do
52
- it 'return message model class' do
53
- expect(chat.send_message(send_message_params)).to be_an FlockOs::Model::SendMessage
54
- end
55
-
56
- it 'return uuid' do
57
- allow_any_instance_of(FlockOs::Client).to receive(:post).and_return(stub_send_response)
58
-
59
- response = chat.send_message(send_message_params)
60
-
61
- expect(response.uid).to eq stub_send_response[:uid]
62
- end
63
- end
64
-
65
- pending 'when send message failed' do
66
- it 'uuid nil' do
67
- allow_any_instance_of(FlockOs::Client).to receive(:post).and_return({})
27
+ it 'return correct attribute values' do
28
+ response = add_member
68
29
 
69
- response = chat.send_message(send_message_params)
70
-
71
- expect(response.uid).to eq nil
30
+ expect(response.members).to eq stub_add_members_response[:members]
72
31
  end
73
32
  end
74
33
  end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe FlockOs::Collection::ChannelMember do
4
+ let(:channel_members) do
5
+ (1..3).map do |n|
6
+ {
7
+ userId: "u:#{n}",
8
+ affiliation: "member"
9
+ }
10
+ end
11
+ end
12
+
13
+ subject(:collection) { described_class.new(channel_members) }
14
+
15
+ describe '#initialize' do
16
+ context 'without show public profile' do
17
+ it 'return described class' do
18
+ expect(collection).to be_an described_class
19
+ end
20
+
21
+ it 'collection is not empty' do
22
+ expect(collection.collection).to be_an Array
23
+ end
24
+
25
+ it 'first collection has correct attributes' do
26
+ first_collection = collection.collection.first
27
+
28
+ expect(first_collection.user_id).to eq 'u:1'
29
+ expect(first_collection.affiliation).to eq 'member'
30
+ expect(first_collection.public_profile).to eq nil
31
+ end
32
+ end
33
+
34
+ context 'with show public profile' do
35
+ let(:channel_members) do
36
+ (1..3).map do |n|
37
+ {
38
+ userId: "u:#{n}",
39
+ affiliation: "member",
40
+ publicProfile: {
41
+ id: "u:#{n}",
42
+ firstName: "Nicole #{n}",
43
+ lastName: "Sullivan",
44
+ profileImage: "https://i.flockusercontent.com/xxxxxx"
45
+ }
46
+ }
47
+ end
48
+ end
49
+
50
+ it 'return described class' do
51
+ expect(collection).to be_an described_class
52
+ end
53
+
54
+ it 'collection is not empty' do
55
+ expect(collection.collection).to be_an Array
56
+ end
57
+
58
+ it 'first collection has correct attributes' do
59
+ first_collection = collection.collection.first
60
+
61
+ expect(first_collection.user_id).to eq 'u:1'
62
+ expect(first_collection.affiliation).to eq 'member'
63
+ expect(first_collection.public_profile).to be_an Hash
64
+ expect(first_collection.public_profile[:firstName]).to eq 'Nicole 1'
65
+ end
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flock_os
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Risal Hidayat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-12 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -171,6 +171,7 @@ files:
171
171
  - lib/flock_os/version.rb
172
172
  - spec/api/channels_spec.rb
173
173
  - spec/api/chat_spec.rb
174
+ - spec/collection/channel_member_spec.rb
174
175
  - spec/flock_os_spec.rb
175
176
  - spec/helpers_spec.rb
176
177
  - spec/spec_helper.rb