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,34 @@
1
+ FLOW = {
2
+ flow: [
3
+ {
4
+ id: 4279,
5
+ pass_round: 4284,
6
+ fail_round: nil,
7
+ start: true,
8
+ title: 'my sub round',
9
+ type: 'submission',
10
+ start_date: 1406670635,
11
+ end_date: 1406680635
12
+ },
13
+ {
14
+ id: 4284,
15
+ pass_round: 4285,
16
+ fail_round: nil,
17
+ start: nil,
18
+ title: 'my rb round',
19
+ type: 'random_draw',
20
+ start_date: 1406680639,
21
+ end_date: 1406690639
22
+ },
23
+ {
24
+ id: 4285,
25
+ pass_round: nil,
26
+ fail_round: nil,
27
+ start: nil,
28
+ title: 'my pf round',
29
+ type: 'prize_fulfillment',
30
+ start_date: 1406700640,
31
+ end_date: 1406710640
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,131 @@
1
+ VALID_GAME_01 = {
2
+ id: 2534,
3
+ title: nil,
4
+ metadata: nil,
5
+ flow:
6
+ [
7
+ {
8
+ id: 2780,
9
+ pass_round: 2781,
10
+ fail_round: nil,
11
+ start: true,
12
+ title: 'my sub round',
13
+ type: 'submission',
14
+ start_date: 1406065397,
15
+ end_date: 1406075397
16
+ },
17
+ {
18
+ id: 2781,
19
+ pass_round: 2782,
20
+ fail_round: nil,
21
+ start: nil,
22
+ title: 'my rb round',
23
+ type: 'random_draw',
24
+ start_date: 1406075397,
25
+ end_date: 1406085397
26
+ },
27
+ {
28
+ id: 2782,
29
+ pass_round: nil,
30
+ fail_round: nil,
31
+ start: nil,
32
+ title: 'my pf round',
33
+ type: 'prize_fulfillment',
34
+ start_date: 1406095398,
35
+ end_date: 1406105398
36
+ }
37
+ ],
38
+ entries_count: 1,
39
+ rounds_count: 3,
40
+ participants_count: 1
41
+ }
42
+ VALID_GAME_01_UPDATED = {
43
+ id: 2680,
44
+ title: 'updated',
45
+ metadata: nil,
46
+ flow:
47
+ [
48
+ {
49
+ id: 2780,
50
+ pass_round: 2781,
51
+ fail_round: nil,
52
+ start: true,
53
+ title: 'my sub round',
54
+ type: 'submission',
55
+ start_date: 1406065397,
56
+ end_date: 1406075397
57
+ },
58
+ {
59
+ id: 2781,
60
+ pass_round: 2782,
61
+ fail_round: nil,
62
+ start: nil,
63
+ title: 'my rb round',
64
+ type: 'random_draw',
65
+ start_date: 1406075397,
66
+ end_date: 1406085397
67
+ },
68
+ {
69
+ id: 2782,
70
+ pass_round: nil,
71
+ fail_round: nil,
72
+ start: nil,
73
+ title: 'my pf round',
74
+ type: 'prize_fulfillment',
75
+ start_date: 1406095398,
76
+ end_date: 1406105398
77
+ }
78
+ ],
79
+ entries_count: 1,
80
+ rounds_count: 3,
81
+ participants_count: 1
82
+ }
83
+ VALID_GAME_02 = {
84
+ id: 2677,
85
+ title: nil,
86
+ metadata: nil,
87
+ flow:
88
+ [
89
+ {
90
+ id: 2771,
91
+ pass_round: 2772,
92
+ fail_round: nil,
93
+ start: true,
94
+ title: 'my sub round',
95
+ type: 'submission',
96
+ start_date: 1406065391,
97
+ end_date: 1406075391
98
+ },
99
+ {
100
+ id: 2772,
101
+ pass_round: 2773,
102
+ fail_round: nil,
103
+ start: nil,
104
+ title: 'my rb round',
105
+ type: 'random_draw',
106
+ start_date: 1406075392,
107
+ end_date: 1406085392
108
+ },
109
+ {
110
+ id: 2773,
111
+ pass_round: nil,
112
+ fail_round: nil,
113
+ start: nil,
114
+ title: 'my pf round',
115
+ type: 'prize_fulfillment',
116
+ start_date: 1406095392,
117
+ end_date: 1406105392
118
+ }
119
+ ],
120
+ entries_count: 0,
121
+ rounds_count: 3,
122
+ participants_count: 1
123
+ }
124
+ GAME_INDEX = {
125
+ results: [VALID_GAME_01, VALID_GAME_02],
126
+ paging: {
127
+ min_id: VALID_GAME_01[:id],
128
+ max_id: VALID_GAME_02[:id],
129
+ next_max_id: VALID_GAME_01[:id] - 1
130
+ }
131
+ }
@@ -0,0 +1,72 @@
1
+ JUDGING_GET_RESPONSE = {
2
+ round_id: 4444,
3
+ judging: [
4
+ {
5
+ judge_id: 55555,
6
+ judgments: [
7
+ {
8
+ id: 1234,
9
+ entry_id: 878787,
10
+ score: 3,
11
+ metadata: {
12
+ comments: 'This entry was very well designed.'
13
+ },
14
+ created: 1413889551
15
+ },
16
+ {
17
+ id: 1235,
18
+ entry_id: 878788,
19
+ score: 2,
20
+ metadata: {
21
+ comments: 'This entry was decent.'
22
+ },
23
+ created: 1413889599
24
+ },
25
+ {
26
+ id: 1236,
27
+ entry_id: 878789,
28
+ score: 1,
29
+ metadata: {
30
+ comments: 'This entry was third in my books.'
31
+ },
32
+ created: 1413889655
33
+ }
34
+ ]
35
+ },
36
+ {
37
+ judge_id: 55556,
38
+ judgments: [
39
+ {
40
+ id: 1237,
41
+ entry_id: 878788,
42
+ score: 3,
43
+ metadata: {
44
+ comments: 'This entry was excellent.'
45
+ },
46
+ created: 1413889551
47
+ },
48
+ {
49
+ id: 1238,
50
+ entry_id: 878789,
51
+ score: 2,
52
+ metadata: {
53
+ comments: 'This entry was relatively good.'
54
+ },
55
+ created: 1413889599
56
+ },
57
+ {
58
+ id: 1239,
59
+ entry_id: 878787,
60
+ score: 1,
61
+ metadata: {
62
+ comments: 'This entry half-hearted.'
63
+ },
64
+ created: 1413889655
65
+ }
66
+ ]
67
+ }
68
+ ]
69
+ }
70
+ JUDGING_RESPONSE = {
71
+ message: 'Judging was successful'
72
+ }
@@ -0,0 +1,56 @@
1
+ MODERATION_GET = {
2
+ results: [
3
+ {
4
+ id: 9898,
5
+ participant_id: 6767,
6
+ state: 1234,
7
+ metadata: {
8
+ image: 'http://placehold.it/350x150',
9
+ title: 'Image Entry',
10
+ description: 'This is a picture of my house'
11
+ }
12
+ },
13
+ {
14
+ id: 9899,
15
+ participant_id: 6767,
16
+ state: 1234,
17
+ metadata: {
18
+ image: 'http://placehold.it/350x150',
19
+ title: 'Image Entry #2',
20
+ description: 'This is another picture of my house'
21
+ }
22
+ },
23
+ {
24
+ id: 3322,
25
+ participant_id: 4433,
26
+ state: 3324,
27
+ metadata: {
28
+ title: 'Entry in state 3324'
29
+ }
30
+ },
31
+ {
32
+ id: 9899,
33
+ participant_id: 6767,
34
+ state: 3324,
35
+ metadata: {
36
+ title: 'Another Entry in state 3324'
37
+ }
38
+ }
39
+ ]
40
+ }
41
+ MODERATION_POST_RESPONSE = {
42
+ results: [
43
+ {
44
+ id: ENTRY_01[:id],
45
+ state: 444
46
+ },
47
+ {
48
+ id: ENTRY_02[:id],
49
+ state: 555
50
+ },
51
+ {
52
+ id: ENTRY_03[:id],
53
+ state: 555
54
+ }
55
+ ]
56
+ }
@@ -0,0 +1,43 @@
1
+ PARTICIPANT_01 = {
2
+ id: 6738,
3
+ game_id: 3924,
4
+ metadata: nil,
5
+ name: nil,
6
+ email: 'test@test.com',
7
+ password: nil
8
+ }
9
+ PARTICIPANT_01_UPDATED = {
10
+ id: 6738,
11
+ game_id: 3924,
12
+ metadata: { age: 20 },
13
+ name: nil,
14
+ email: 'test@test.com',
15
+ password: nil
16
+ }
17
+ PARTICIPANT_02 = {
18
+ id: 6739,
19
+ game_id: 3924,
20
+ metadata: nil,
21
+ name: nil,
22
+ email: 'test123@test.com',
23
+ password: nil
24
+ }
25
+ PARTICIPANT_INDEX = [PARTICIPANT_01, PARTICIPANT_02]
26
+ PARTICIPANT_TOKEN_RENEW = {
27
+ token: '3e9dsgskj32f8fj3fae0vfnsi217dnds',
28
+ token_expired: false
29
+ }
30
+ PARTICIPANT_PERMISSIONS = {
31
+ permissions: [
32
+ 'api_basic',
33
+ 'registered',
34
+ 'administrate',
35
+ 'moderate'
36
+ ]
37
+ }
38
+ PARTICIPANT_PERMISSIONS_UPDATED = {
39
+ permissions: [
40
+ 'api_basic',
41
+ 'registered'
42
+ ]
43
+ }
@@ -0,0 +1,4 @@
1
+ POINTS_RESPONSE = {
2
+ id: 76767,
3
+ weight: 5
4
+ }
@@ -0,0 +1,68 @@
1
+ SUBMISSION_ROUND = {
2
+ id: 4279,
3
+ title: 'my round',
4
+ start_date: 1406652331,
5
+ end_date: 1406655931,
6
+ type: 'submission',
7
+ rules: {
8
+ num_entries: 100,
9
+ interval: 'day'
10
+ }
11
+ }
12
+ SUBMISSION_ROUND_UPDATED = {
13
+ id: 4279,
14
+ title: 'updated',
15
+ start_date: 1406652331,
16
+ end_date: 1406655931,
17
+ type: 'submission',
18
+ rules: {
19
+ num_entries: 100,
20
+ interval: 'day'
21
+ }
22
+ }
23
+ RANDOM_DRAW_ROUND = {
24
+ id: 4279,
25
+ title: 'my random draw round',
26
+ start_date: 1406652331,
27
+ end_date: 1406655931,
28
+ type: 'random_draw',
29
+ rules: {
30
+ winners: 10,
31
+ percentage: false
32
+ }
33
+ }
34
+ PRIZE_FULFILLMENT_ROUND = {
35
+ id: 4279,
36
+ title: 'my prize fulfillment round',
37
+ start_date: 1406652331,
38
+ end_date: 1406655931,
39
+ type: 'webhook',
40
+ rules: {
41
+ webhook: 'http://www.strutta.com'
42
+ }
43
+ }
44
+ POINTS_ROUND = {
45
+ id: 4399,
46
+ title: 'my points round',
47
+ start_date: 1406652888,
48
+ end_date: 1406656999,
49
+ type: 'points',
50
+ rules: {
51
+ winners: 10,
52
+ interval: 'game',
53
+ min_allowed: 0,
54
+ max_allowed: 10
55
+ }
56
+ }
57
+ JUDGING_ROUND = {
58
+ id: 5532,
59
+ title: 'my judging round',
60
+ start_date: 1406652888,
61
+ end_date: 1406656999,
62
+ type: 'judging',
63
+ rules: {
64
+ winners: 10,
65
+ ranking_size: 5
66
+ }
67
+ }
68
+ ROUND_INDEX = [SUBMISSION_ROUND, RANDOM_DRAW_ROUND, PRIZE_FULFILLMENT_ROUND]
@@ -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
+ let(:flow_no_game) { strutta.games.flow }
16
+ let(:flow_params) do
17
+ {
18
+ definition: [
19
+ {
20
+ id: SUBMISSION_ROUND[:id],
21
+ pass_round: RANDOM_DRAW_ROUND[:id],
22
+ fail_round: nil,
23
+ start: true
24
+ },
25
+ {
26
+ id: RANDOM_DRAW_ROUND[:id],
27
+ pass_round: PRIZE_FULFILLMENT_ROUND[:id],
28
+ fail_round: nil
29
+ },
30
+ {
31
+ id: PRIZE_FULFILLMENT_ROUND[:id],
32
+ pass_round: nil,
33
+ fail_round: nil
34
+ }
35
+ ]
36
+ }
37
+ end
38
+ let(:flow) { game.flow.create(flow_params) }
39
+
40
+ describe 'games(:id).flow' do
41
+ context 'when no id is given' do
42
+
43
+ context '.get' do
44
+ before do
45
+ stub_request(:get, /.*flow/)
46
+ .to_return(status: 200, body: FLOW.to_json, headers: {})
47
+ end
48
+ it 'should return flow hash' do
49
+ f = game.flow.get
50
+ expect(f['flow'].is_a? Array).to be true
51
+ end
52
+ end
53
+
54
+ context '.delete' do
55
+ before do
56
+ stub_request(:delete, /.*flow/)
57
+ .to_return(status: 204, body: '', headers: {})
58
+ end
59
+ it 'should delete flow' do
60
+ expect(game.flow.delete).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, /.*flow/)
68
+ .to_return(status: 201, body: FLOW.to_json, headers: {})
69
+ end
70
+ it 'should return a new flow hash' do
71
+ expect(flow['flow'].is_a? Array).to be true
72
+ expect(flow['flow'].first['id']).to eq(SUBMISSION_ROUND[:id])
73
+ end
74
+ end
75
+ end
76
+
77
+ context '.update' do
78
+ it 'should throw error' do
79
+ expect { game.flow.update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
80
+ end
81
+ end
82
+
83
+ context '.all' do
84
+ it 'should throw error' do
85
+ expect { game.flow.all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
86
+ end
87
+ end
88
+ end
89
+
90
+ context 'when id is given' do
91
+ context '.get' do
92
+ it 'should throw error' do
93
+ expect { game.flow(1).get }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
94
+ end
95
+ end
96
+
97
+ context '.delete' do
98
+ it 'should throw error' do
99
+ expect { game.flow(1).delete }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
100
+ end
101
+ end
102
+
103
+ context '.create' do
104
+ it 'should throw error' do
105
+ expect { game.flow(1).create(flow_params) }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
106
+ end
107
+ end
108
+
109
+ context '.update' do
110
+ it 'should throw error' do
111
+ expect { game.flow(1).update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
112
+ end
113
+ end
114
+
115
+ context '.all' do
116
+ it 'should throw error' do
117
+ expect { game.flow(1).all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end