strutta-api 1.0.1

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.
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Strutta API Wrapper' do
4
+
5
+ before { WebMock.disable_net_connect!(allow_localhost: true, allow: /codeclimate/) }
6
+ after { WebMock.allow_net_connect! }
7
+
8
+ let(:token) { 'dc1479c52801fbfa0975947de092a1e7' }
9
+ let(:host) { 'http://api.strutta.dev:4000' }
10
+ let(:path) { '/v2/' }
11
+ let(:strutta) { Strutta::API.new token, host, path }
12
+
13
+ let(:game) { strutta.games.create }
14
+
15
+ describe '.games' do
16
+ context 'when no id is given' do
17
+ context '.get' do
18
+ it 'should throw error' do
19
+ expect { strutta.games.get }.to raise_error(Strutta::Errors::ObjectIDRequired)
20
+ end
21
+ end
22
+
23
+ context '.update' do
24
+ it 'should throw error' do
25
+ expect { strutta.games.update(title: 'title') }.to raise_error(Strutta::Errors::ObjectIDRequired)
26
+ end
27
+ end
28
+
29
+ context '.delete' do
30
+ it 'should throw error' do
31
+ expect { strutta.games.delete }.to raise_error(Strutta::Errors::ObjectIDRequired)
32
+ end
33
+ end
34
+
35
+ context '.rounds' do
36
+ it 'should throw error' do
37
+ expect { strutta.games.rounds }.to raise_error(Strutta::Errors::ObjectIDRequired)
38
+ end
39
+ end
40
+
41
+ context '.participants' do
42
+ it 'should throw error' do
43
+ expect { strutta.games.participants }.to raise_error(Strutta::Errors::ObjectIDRequired)
44
+ end
45
+ end
46
+
47
+ context '.flow' do
48
+ it 'should throw error' do
49
+ expect { strutta.games.flow }.to raise_error(Strutta::Errors::ObjectIDRequired)
50
+ end
51
+ end
52
+
53
+ context '.entries' do
54
+ it 'should throw error' do
55
+ expect { strutta.games.entries }.to raise_error(Strutta::Errors::ObjectIDRequired)
56
+ end
57
+ end
58
+
59
+ context '.all' do
60
+ before do
61
+ stub_request(:get, /.*games/)
62
+ .to_return(status: 200, body: GAME_INDEX.to_json, headers: {})
63
+ end
64
+ it 'should return array of games' do
65
+ games = strutta.games.all
66
+ results = games['results']
67
+ expect(results.is_a? Array).to be true
68
+ expect(results.first['id']).to_not be nil
69
+ expect(results.first['entries_count']).to_not be nil
70
+ expect(results.last['id']).to_not be nil
71
+ expect(results.last['entries_count']).to_not be nil
72
+ expect(games['paging']['min_id']).to equal VALID_GAME_01[:id]
73
+ expect(games['paging']['max_id']).to equal VALID_GAME_02[:id]
74
+ end
75
+ end
76
+
77
+ context '.create' do
78
+ before do
79
+ stub_request(:post, /.*games/)
80
+ .to_return(status: 201, body: VALID_GAME_01.to_json, headers: {})
81
+ end
82
+ it 'should return a new game hash' do
83
+ expect(game['id']).to eq VALID_GAME_01[:id]
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'when id is given' do
89
+ before do
90
+ stub_request(:post, /.*games/)
91
+ .to_return(status: 201, body: VALID_GAME_02.to_json, headers: {})
92
+ stub_request(:get, /.*games\/\d+/)
93
+ .to_return(status: 200, body: VALID_GAME_02.to_json, headers: {})
94
+ end
95
+ context '.get' do
96
+ it 'should return game hash' do
97
+ g = strutta.games(game['id']).get
98
+ expect(g['id']).to eq VALID_GAME_02[:id]
99
+ end
100
+ end
101
+
102
+ context '.update' do
103
+ before do
104
+ stub_request(:post, /.*games/)
105
+ .to_return(status: 200, body: VALID_GAME_01.to_json, headers: {})
106
+ stub_request(:patch, /.*games\/\d+/)
107
+ .to_return(status: 200, body: VALID_GAME_01_UPDATED.to_json, headers: {})
108
+ end
109
+ it 'should return updated game hash' do
110
+ updated = strutta.games(game['id']).update(title: 'updated')
111
+ expect(updated['title']).to eq('updated')
112
+ end
113
+ end
114
+
115
+ context '.delete' do
116
+ before do
117
+ stub_request(:post, /.*games/)
118
+ .to_return(status: 201, body: VALID_GAME_02.to_json, headers: {})
119
+ stub_request(:delete, /.*games\/\d+/)
120
+ .to_return(status: 204, body: nil, headers: {})
121
+ end
122
+ it 'should delete game' do
123
+ expect(strutta.games(game['id']).delete).to be true
124
+ end
125
+ end
126
+
127
+ context 'check proper object returns' do
128
+
129
+ before do
130
+ stub_request(:post, /.*games/)
131
+ .to_return(status: 201, body: VALID_GAME_02.to_json, headers: {})
132
+ end
133
+
134
+ context '.rounds' do
135
+ it 'should return a Rounds object' do
136
+ rounds = strutta.games(game['id']).rounds
137
+ expect(rounds.is_a? Strutta::Rounds).to be true
138
+ end
139
+ end
140
+
141
+ context '.participants' do
142
+ it 'should return a Participants object' do
143
+ participants = strutta.games(game['id']).participants
144
+ expect(participants.is_a? Strutta::Participants).to be true
145
+ end
146
+ end
147
+
148
+ context '.flow' do
149
+ it 'should return a Flow object' do
150
+ flow = strutta.games(game['id']).flow
151
+ expect(flow.is_a? Strutta::Flow).to be true
152
+ end
153
+ end
154
+
155
+ context '.entries' do
156
+ it 'should return a Entries object' do
157
+ entries = strutta.games(game['id']).entries
158
+ expect(entries.is_a? Strutta::Entries).to be true
159
+ end
160
+ end
161
+
162
+ context '.all' do
163
+ it 'should throw error' do
164
+ expect { strutta.games(game['id']).all }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
165
+ end
166
+ end
167
+
168
+ context '.create' do
169
+ it 'should throw error' do
170
+ expect { strutta.games(game['id']).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Strutta API Wrapper' do
4
+
5
+ before { WebMock.disable_net_connect!(allow_localhost: true, allow: /codeclimate/) }
6
+ after { WebMock.allow_net_connect! }
7
+
8
+ let(:token) { 'dc1479c52801fbfa0975947de092a1e7' }
9
+ let(:host) { 'http://api.strutta.dev:4000' }
10
+ let(:path) { '/v2/' }
11
+ let(:strutta) { Strutta::API.new token, host, path }
12
+
13
+ let(:new_game) { strutta.games.create }
14
+ let(:game) { strutta.games(VALID_GAME_01[:id]) }
15
+
16
+ let(:judgments) do
17
+ [
18
+ {
19
+ entry_id: 1234,
20
+ rank: 1,
21
+ metadata: {
22
+ comments: 'First place'
23
+ }
24
+ },
25
+ {
26
+ entry_id: 1235,
27
+ rank: 2,
28
+ metadata: {
29
+ comments: 'Second place'
30
+ }
31
+ },
32
+ {
33
+ entry_id: 1236,
34
+ rank: 3,
35
+ metadata: {
36
+ comments: 'Third place'
37
+ }
38
+ }
39
+ ]
40
+ end
41
+
42
+ describe 'games(:id).judging' do
43
+ context 'when no id is given' do
44
+
45
+ context '.create' do
46
+ context 'with valid parameters' do
47
+ before do
48
+ stub_request(:post, /.*judging/)
49
+ .to_return(status: 201, body: JUDGING_RESPONSE.to_json, headers: {})
50
+ end
51
+ it 'should return a new flow hash' do
52
+ judging = strutta.games(333).judging.create(judgments)
53
+ expect(judging['message']).to eq JUDGING_RESPONSE[:message]
54
+ end
55
+ end
56
+ end
57
+
58
+ context '.get' do
59
+ before do
60
+ stub_request(:get, /.*judging/)
61
+ .to_return(status: 200, body: JUDGING_GET_RESPONSE.to_json, headers: {})
62
+ end
63
+ it 'should throw disabled endpoint error' do
64
+ judging = strutta.games(333).judging.get(round_id: JUDGING_ROUND[:id])
65
+ expect(judging['round_id'].is_a? Integer).to be true
66
+ expect(judging['judging'].is_a? Array).to be true
67
+ expect(judging['judging'].first['judgments'].is_a? Array).to be true
68
+ end
69
+ end
70
+
71
+ context '.all' do
72
+ it 'should throw disabled endpoint error' do
73
+ expect { game.judging.all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
74
+ end
75
+ end
76
+
77
+ context '.update' do
78
+ it 'should throw disabled endpoint error' do
79
+ expect { game.judging.update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
80
+ end
81
+ end
82
+
83
+ context '.delete' do
84
+ it 'should throw disabled endpoint error' do
85
+ expect { game.judging.delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
86
+ end
87
+ end
88
+ end
89
+
90
+ context 'when id is given' do
91
+ context '.all' do
92
+ it 'should throw disabled endpoint error' do
93
+ expect { game.judging(1).all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
94
+ end
95
+ end
96
+
97
+ context '.update' do
98
+ it 'should throw disabled endpoint error' do
99
+ expect { game.judging(1).update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
100
+ end
101
+ end
102
+
103
+ context '.delete' do
104
+ it 'should throw disabled endpoint error' do
105
+ expect { game.judging(1).delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
106
+ end
107
+ end
108
+
109
+ context '.create' do
110
+ it 'should throw error' do
111
+ expect { game.judging(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
112
+ end
113
+ end
114
+
115
+ context '.get' do
116
+ it 'should throw error' do
117
+ expect { game.judging(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Strutta API Wrapper' do
4
+
5
+ before { WebMock.disable_net_connect!(allow_localhost: true, allow: /codeclimate/) }
6
+ after { WebMock.allow_net_connect! }
7
+
8
+ let(:token) { 'dc1479c52801fbfa0975947de092a1e7' }
9
+ let(:host) { 'http://api.strutta.dev:4000' }
10
+ let(:path) { '/v2/' }
11
+ let(:strutta) { Strutta::API.new token, host, path }
12
+
13
+ let(:new_game) { strutta.games.create }
14
+ let(:game) { strutta.games(VALID_GAME_01[:id]) }
15
+
16
+ let(:moderation_post) do
17
+ [
18
+ {
19
+ id: ENTRY_01[:id],
20
+ pass: true
21
+ },
22
+ {
23
+ id: ENTRY_02[:id],
24
+ pass: false
25
+ },
26
+ {
27
+ id: ENTRY_03[:id],
28
+ pass: false
29
+ }
30
+ ]
31
+ end
32
+
33
+ describe 'games(:id).moderation' do
34
+ context 'when no id is given' do
35
+
36
+ context '.create' do
37
+ context 'with valid parameters' do
38
+ before do
39
+ stub_request(:post, /.*moderation/)
40
+ .to_return(status: 201, body: MODERATION_POST_RESPONSE.to_json, headers: {})
41
+ end
42
+ it 'should return a new flow hash' do
43
+ moderation = strutta.games(333).moderation.create(moderation: moderation_post)
44
+ expect(moderation['results'].is_a? Array).to be true
45
+ expect(moderation['results'].first['id'].is_a? Integer).to be true
46
+ expect(moderation['results'].first['state'].is_a? Integer).to be true
47
+ end
48
+ end
49
+ end
50
+
51
+ context '.get' do
52
+ before do
53
+ stub_request(:get, /.*moderation/)
54
+ .to_return(status: 200, body: MODERATION_GET.to_json, headers: {})
55
+ end
56
+ it 'should throw disabled endpoint error' do
57
+ moderation = strutta.games(333).moderation.get
58
+ expect(moderation['results'].is_a? Array).to be true
59
+ expect(moderation['results'].first['id'].is_a? Integer).to be true
60
+ end
61
+ end
62
+
63
+ context '.all' do
64
+ it 'should throw disabled endpoint error' do
65
+ expect { game.moderation.all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
66
+ end
67
+ end
68
+
69
+ context '.update' do
70
+ it 'should throw disabled endpoint error' do
71
+ expect { game.moderation.update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
72
+ end
73
+ end
74
+
75
+ context '.delete' do
76
+ it 'should throw disabled endpoint error' do
77
+ expect { game.moderation.delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
78
+ end
79
+ end
80
+ end
81
+
82
+ context 'when id is given' do
83
+ context '.all' do
84
+ it 'should throw disabled endpoint error' do
85
+ expect { game.moderation(1).all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
86
+ end
87
+ end
88
+
89
+ context '.update' do
90
+ it 'should throw disabled endpoint error' do
91
+ expect { game.moderation(1).update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
92
+ end
93
+ end
94
+
95
+ context '.delete' do
96
+ it 'should throw disabled endpoint error' do
97
+ expect { game.moderation(1).delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
98
+ end
99
+ end
100
+
101
+ context '.create' do
102
+ it 'should throw error' do
103
+ expect { game.moderation(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
104
+ end
105
+ end
106
+
107
+ context '.get' do
108
+ it 'should throw error' do
109
+ expect { game.moderation(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Strutta API Wrapper' do
4
+
5
+ before { WebMock.disable_net_connect!(allow_localhost: true, allow: /codeclimate/) }
6
+ after { WebMock.allow_net_connect! }
7
+
8
+ let(:token) { 'dc1479c52801fbfa0975947de092a1e7' }
9
+ let(:host) { 'http://api.strutta.dev:4000' }
10
+ let(:path) { '/v2/' }
11
+ let(:strutta) { Strutta::API.new token, host, path }
12
+ let(:game) { strutta.games(VALID_GAME_01[:id]) }
13
+ let(:participant) { game.participants.create(email: 'test@test.com') }
14
+
15
+ describe 'games(:id).participants' do
16
+ context 'when no id is given' do
17
+ context '.get' do
18
+ it 'should throw error' do
19
+ expect { strutta.games.participants.get }.to raise_error(Strutta::Errors::ObjectIDRequired)
20
+ end
21
+ end
22
+
23
+ context '.update' do
24
+ it 'should throw error' do
25
+ expect { strutta.games.participants.update(title: 'title') }.to raise_error(Strutta::Errors::ObjectIDRequired)
26
+ end
27
+ end
28
+
29
+ context '.delete' do
30
+ it 'should throw error' do
31
+ expect { strutta.games.participants.delete }.to raise_error(Strutta::Errors::ObjectIDRequired)
32
+ end
33
+ end
34
+
35
+ context '.token_renew' do
36
+ it 'should throw error' do
37
+ expect { strutta.games.participants.token_renew }.to raise_error(Strutta::Errors::ObjectIDRequired)
38
+ end
39
+ end
40
+
41
+ context '.permissions' do
42
+ it 'should throw error' do
43
+ expect { strutta.games.participants.permissions }.to raise_error(Strutta::Errors::ObjectIDRequired)
44
+ end
45
+ end
46
+
47
+ context '.permissions_update' do
48
+ it 'should throw error' do
49
+ expect { strutta.games.participants.permissions_update }.to raise_error(Strutta::Errors::ObjectIDRequired)
50
+ end
51
+ end
52
+
53
+ context '.all' do
54
+ before do
55
+ stub_request(:get, /.*participants/)
56
+ .to_return(status: 200, body: PARTICIPANT_INDEX.to_json, headers: {})
57
+ end
58
+ it 'should return array of participants' do
59
+ participant_list = game.participants.all
60
+ expect(participant_list.is_a? Array).to be true
61
+ end
62
+ end
63
+
64
+ context '.create' do
65
+ context 'with valid parameters' do
66
+ before do
67
+ stub_request(:post, /.*participants/)
68
+ .to_return(status: 201, body: PARTICIPANT_01.to_json, headers: {})
69
+ end
70
+ it 'should return a new participant hash' do
71
+ expect(participant['id']).to_not be nil
72
+ end
73
+ end
74
+ end
75
+
76
+ context '.search' do
77
+ context 'with valid parameters and existing participant' do
78
+ before do
79
+ stub_request(:get, /.*participants\/search/)
80
+ .to_return(status: 200, body: PARTICIPANT_01.to_json, headers: {})
81
+ end
82
+ it 'should return a new participant hash' do
83
+ p = game.participants.search(email: PARTICIPANT_01[:email])
84
+ expect(p['id']).to_not be nil
85
+ end
86
+ end
87
+
88
+ context 'with valid parameters and no existing participant' do
89
+ before do
90
+ stub_request(:get, /.*participants\/search/)
91
+ .to_return(status: 404, body: { error: 'not found', message: 'not found' }.to_json, headers: {})
92
+ end
93
+ it 'should throw object not found error' do
94
+ expect { game.participants.search(email: PARTICIPANT_01[:email]) }.to raise_error(Strutta::Errors::ObjectNotFoundError)
95
+ end
96
+ end
97
+
98
+ context 'with invalid parameters' do
99
+ it 'should throw invalid parameters error' do
100
+ expect { game.participants.search(name: PARTICIPANT_01[:id]) }.to raise_error(Strutta::Errors::InvalidSearchParameters)
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ context 'when id is given' do
107
+ context '.get' do
108
+ before do
109
+ stub_request(:get, /.*participants\/\d+/)
110
+ .to_return(status: 200, body: PARTICIPANT_01.to_json, headers: {})
111
+ end
112
+ it 'should return participant hash' do
113
+ p = game.participants(PARTICIPANT_01[:id]).get
114
+ expect(p['id']).to_not be nil
115
+ end
116
+ end
117
+
118
+ context '.update' do
119
+ before do
120
+ stub_request(:patch, /.*participants\/\d+/)
121
+ .to_return(status: 200, body: PARTICIPANT_01_UPDATED.to_json, headers: {})
122
+ end
123
+ it 'should return updated game hash' do
124
+ metadata = { age: 20 }
125
+ updated = game.participants(PARTICIPANT_01[:id]).update(metadata: metadata)
126
+ expect(updated['metadata']['age']).to eq(20)
127
+ end
128
+ end
129
+
130
+ context '.token_renew' do
131
+ before do
132
+ stub_request(:patch, %r{.*participants\/\d+\/token})
133
+ .to_return(status: 200, body: PARTICIPANT_TOKEN_RENEW.to_json, headers: {})
134
+ end
135
+ it 'should return updated token information' do
136
+ body = game.participants(PARTICIPANT_01[:id]).token_renew
137
+ expect(body['token']).not_to be nil
138
+ expect(body['token_expired']).to be false
139
+ end
140
+ end
141
+
142
+ context '.permissions' do
143
+ before do
144
+ stub_request(:get, %r{.*participants\/\d+\/permissions})
145
+ .to_return(status: 200, body: PARTICIPANT_PERMISSIONS.to_json, headers: {})
146
+ end
147
+ it 'should return permissions array' do
148
+ body = game.participants(PARTICIPANT_01[:id]).permissions
149
+ expect(body['permissions'].is_a? Array).to be true
150
+ expect(body['permissions'].include?('api_basic')).to be true
151
+ expect(body['permissions'].include?('moderate')).to be true
152
+ end
153
+ end
154
+
155
+ context '.permissions_update' do
156
+ before do
157
+ stub_request(:patch, %r{.*participants\/\d+\/permissions})
158
+ .to_return(status: 200, body: PARTICIPANT_PERMISSIONS_UPDATED.to_json, headers: {})
159
+ end
160
+ it 'should return permissions array' do
161
+ body = game.participants(PARTICIPANT_01[:id]).permissions_update
162
+ expect(body['permissions'].is_a? Array).to be true
163
+ expect(body['permissions'].include?('api_basic')).to be true
164
+ expect(body['permissions'].include?('moderate')).to be false
165
+ end
166
+ end
167
+
168
+ context '.delete' do
169
+ before do
170
+ stub_request(:delete, /.*participants\/\d+/)
171
+ .to_return(status: 204, body: '', headers: {})
172
+ end
173
+ it 'should delete participant' do
174
+ expect(game.participants(PARTICIPANT_01[:id]).delete).to be true
175
+ end
176
+ end
177
+
178
+ context '.all' do
179
+ it 'should throw error' do
180
+ expect { game.participants(PARTICIPANT_01[:id]).all }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
181
+ end
182
+ end
183
+
184
+ context '.create' do
185
+ it 'should throw error' do
186
+ expect { game.participants(PARTICIPANT_01[:id]).create(email: 'test@email.com') }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end