citrix 0.2.0 → 0.2.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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -4
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +5 -5
  5. data/Rakefile +7 -4
  6. data/citrix.gemspec +17 -15
  7. data/lib/citrix.rb +2 -2
  8. data/lib/citrix/training.rb +15 -15
  9. data/lib/citrix/training/helpers/http_client.rb +5 -5
  10. data/lib/citrix/training/namespace/registrants.rb +8 -8
  11. data/lib/citrix/training/namespace/trainings.rb +9 -9
  12. data/lib/citrix/training/serializer/registrant.rb +7 -7
  13. data/lib/citrix/training/serializer/training.rb +9 -9
  14. data/lib/citrix/version.rb +1 -1
  15. data/test/citrix/training/client_test.rb +18 -0
  16. data/test/citrix/training/credentials_test.rb +27 -0
  17. data/test/citrix/training/helpers/http_client_test.rb +45 -0
  18. data/test/citrix/training/helpers/initializer_test.rb +15 -0
  19. data/test/citrix/training/namespace/registrants_test.rb +95 -0
  20. data/test/citrix/training/namespace/trainings_test.rb +111 -0
  21. data/test/citrix/training/resource/registrant_test.rb +23 -0
  22. data/test/citrix/training/resource/training_test.rb +25 -0
  23. data/test/citrix/training/serializer/registrant_test.rb +53 -0
  24. data/test/citrix/training/serializer/training_date_test.rb +21 -0
  25. data/test/citrix/training/serializer/training_test.rb +82 -0
  26. data/{spec → test}/fixtures/register.json +0 -0
  27. data/{spec → test}/fixtures/registrant.json +1 -1
  28. data/{spec → test}/fixtures/registrants.json +0 -0
  29. data/{spec → test}/fixtures/training.json +0 -0
  30. data/{spec → test}/fixtures/trainings.json +0 -0
  31. data/{spec/spec_helper.rb → test/test_helper.rb} +24 -37
  32. metadata +67 -40
  33. data/.rspec +0 -1
  34. data/spec/citrix/training/client_spec.rb +0 -22
  35. data/spec/citrix/training/credentials_spec.rb +0 -31
  36. data/spec/citrix/training/helpers/http_client_spec.rb +0 -54
  37. data/spec/citrix/training/helpers/initializer_spec.rb +0 -15
  38. data/spec/citrix/training/namespace/registrants_spec.rb +0 -94
  39. data/spec/citrix/training/namespace/trainings_spec.rb +0 -109
  40. data/spec/citrix/training/resource/registrant_spec.rb +0 -11
  41. data/spec/citrix/training/resource/training_spec.rb +0 -11
  42. data/spec/citrix/training/serializer/registrant_spec.rb +0 -50
  43. data/spec/citrix/training/serializer/training_date_spec.rb +0 -21
  44. data/spec/citrix/training/serializer/training_spec.rb +0 -79
@@ -0,0 +1,45 @@
1
+ require "test_helper"
2
+
3
+ class HttpClientTest < Minitest::Test
4
+ let(:helper) { Object.new.extend(Citrix::Training::Helpers::HttpClient) }
5
+ let(:config) { helper.http_client.configuration }
6
+
7
+ test "returns json parser" do
8
+ assert_equal Aitch::ResponseParser::JSONParser.engine, helper.json_parser
9
+ end
10
+
11
+ test "returns url" do
12
+ url = helper.url_for("trainings", 1234)
13
+ assert_equal File.join(Citrix::Training::API_ENDPOINT, "trainings", "1234"), url
14
+ end
15
+
16
+ test "enabled debug mode" do
17
+ $DEBUG = true
18
+ assert_kind_of Logger, config.logger
19
+ end
20
+
21
+ test "skips debug mode" do
22
+ $DEBUG = false
23
+ refute config.logger
24
+ end
25
+
26
+ test "sets user agent" do
27
+ assert_equal "Citrix::Rubygems/#{Citrix::VERSION}", config.user_agent
28
+ end
29
+
30
+ test "sets content type" do
31
+ assert_equal "application/json", config.default_headers["Content-Type"]
32
+ end
33
+
34
+ test "sets accept" do
35
+ assert_equal "application/json", config.default_headers["Accept"]
36
+ end
37
+
38
+ test "sets authorization" do
39
+ credentials = mock(oauth_token: "OAUTH_TOKEN")
40
+ helper.expects(:credentials).returns(credentials)
41
+ auth_header = config.default_headers["Authorization"].call
42
+
43
+ assert_equal "OAuth oauth_token=OAUTH_TOKEN", auth_header
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ class InitializerTest < Minitest::Test
4
+ test "assigns properties" do
5
+ klass = Class.new do
6
+ include Citrix::Training::Helpers::Initializer
7
+ attr_accessor :name, :email
8
+ end
9
+
10
+ instance = klass.new(name: "John", email: "john@example.com")
11
+
12
+ assert_equal "John", instance.name
13
+ assert_equal "john@example.com", instance.email
14
+ end
15
+ end
@@ -0,0 +1,95 @@
1
+ require "test_helper"
2
+
3
+ module RegistrantsTest
4
+ class NamespaceCreateTest < Minitest::Test
5
+ let(:client) { build_client }
6
+ let(:training) { build_training }
7
+ let(:serializer) { Citrix::Training::Serializer::Registrant }
8
+
9
+ test "performs request" do
10
+ stub_request(:post, /.+/).to_return(
11
+ body: "{}",
12
+ headers: {"Content-Type" => "application/json"}
13
+ )
14
+
15
+ url = url_for("organizers", client.credentials.organizer_key, "trainings", training.key, "registrants")
16
+ attrs = build_registrant_attributes
17
+ serialized_attrs = serialize(attrs)
18
+ client.registrants(training).create(attrs)
19
+
20
+ assert_equal :post, last_request.method
21
+ assert_equal url, last_request.uri.normalize.to_s
22
+ assert_equal JSON.dump(serialized_attrs), last_request.body
23
+ end
24
+
25
+ test "updates registrant with additional attributes" do
26
+ attrs = JSON.load(fixtures.join("register.json").read)
27
+
28
+ stub_request(:post, /.+/).to_return(
29
+ body: JSON.dump(attrs),
30
+ headers: {"Content-Type" => "application/json"}
31
+ )
32
+
33
+ response, registrant = client.registrants(training).create({first_name: "John"})
34
+
35
+ assert_equal "John", registrant.first_name
36
+ assert_equal attrs["joinUrl"], registrant.join_url
37
+ assert_equal attrs["confirmationUrl"], registrant.confirmation_url
38
+ assert_equal attrs["registrantKey"], registrant.key
39
+ end
40
+ end
41
+
42
+ class NamespaceAllTest < Minitest::Test
43
+ let(:client) { build_client }
44
+ let(:training) { build_training }
45
+
46
+ test "performs request" do
47
+ stub_request(:get, /.+/).to_return(
48
+ body: "[]",
49
+ headers: {"Content-Type" => "application/json"}
50
+ )
51
+
52
+ url = url_for("organizers", client.credentials.organizer_key, "trainings", training.key, "registrants")
53
+ client.registrants(training).all
54
+
55
+ assert_equal :get, last_request.method
56
+ assert_equal url, last_request.uri.normalize.to_s
57
+ end
58
+
59
+ test "returns registrants" do
60
+ stub_request(:get, /.+/).to_return(
61
+ status: 200,
62
+ body: fixtures.join("registrants.json").read,
63
+ headers: {"Content-Type" => "application/json"}
64
+ )
65
+
66
+ response, registrants = client.registrants(training).all
67
+
68
+ assert_equal 3, registrants.size
69
+ assert_kind_of Citrix::Training::Resource::Registrant, registrants.first
70
+ end
71
+ end
72
+
73
+ class NamespaceRemoveTest < Minitest::Test
74
+ let(:client) { build_client }
75
+ let(:training) { build_training }
76
+ let(:registrant) { build_registrant }
77
+
78
+ test "performs request" do
79
+ stub_request(:delete, /.+/)
80
+
81
+ url = url_for("organizers", client.credentials.organizer_key, "trainings", training.key, "registrants", registrant.key)
82
+ client.registrants(training).remove(registrant)
83
+
84
+ assert_equal :delete, last_request.method
85
+ assert_equal url, last_request.uri.normalize.to_s
86
+ end
87
+
88
+ test "returns response" do
89
+ stub_request(:delete, /.+/)
90
+ response = client.registrants(training).remove(registrant)
91
+
92
+ assert_kind_of Aitch::Response, response
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,111 @@
1
+ require "test_helper"
2
+
3
+ module TrainingsTest
4
+ class NamespaceCreateTest < Minitest::Test
5
+ let(:client) { build_client }
6
+ let(:serializer) { Citrix::Training::Serializer::Training }
7
+
8
+ test "performs request" do
9
+ stub_request(:post, /.+/)
10
+ .to_return(body: "[]", headers: {"Content-Type" => "application/json"})
11
+
12
+ url = url_for("organizers", client.credentials.organizer_key, "trainings")
13
+ attrs = build_training_attributes
14
+ serialized_attrs = serialize(attrs)
15
+ client.trainings.create(attrs)
16
+
17
+ assert_equal :post, last_request.method
18
+ assert_equal url, last_request.uri.normalize.to_s
19
+ assert_equal JSON.dump(serialized_attrs), last_request.body
20
+ end
21
+
22
+ test "returns response" do
23
+ stub_request(:post, /.+/)
24
+ response, training = client.trainings.create({})
25
+ assert_kind_of Aitch::Response, response
26
+ end
27
+
28
+ test "returns training instance" do
29
+ stub_request(:post, /.+/)
30
+ response, training = client.trainings.create({})
31
+ assert_kind_of Citrix::Training::Resource::Training, training
32
+ end
33
+
34
+ test "sets training key" do
35
+ stub_request(:post, /.+/).to_return(body: %["1234"], status: 201)
36
+ response, training = client.trainings.create({})
37
+ assert_equal "1234", training.key
38
+ end
39
+ end
40
+
41
+ class NamespaceAllTest < Minitest::Test
42
+ let(:client) { build_client }
43
+
44
+ test "performs request" do
45
+ stub_request(:get, /.+/).to_return(body: "[]", headers: {"Content-Type" => "application/json"})
46
+
47
+ url = url_for("organizers", client.credentials.organizer_key, "trainings")
48
+ client.trainings.all
49
+
50
+ assert_equal :get, last_request.method
51
+ assert_equal url, last_request.uri.normalize.to_s
52
+ end
53
+
54
+ test "returns trainings" do
55
+ stub_request(:get, /.+/)
56
+ .to_return(status: 200, body: fixtures.join("trainings.json").read, headers: {"Content-Type" => "application/json"})
57
+
58
+ response, trainings = client.trainings.all
59
+
60
+ assert_equal 1, trainings.size
61
+ assert_kind_of Citrix::Training::Resource::Training, trainings.first
62
+ end
63
+ end
64
+
65
+ class NamespaceFindTest < Minitest::Test
66
+ let(:client) { build_client }
67
+
68
+ test "performs request" do
69
+ stub_request(:get, /.+/)
70
+ .to_return(status: 200, body: fixtures.join("training.json").read, headers: {"Content-Type" => "application/json"})
71
+ client.trainings.find("1234")
72
+
73
+ url = url_for("organizers", client.credentials.organizer_key, "trainings", "1234")
74
+
75
+ assert_equal :get, last_request.method
76
+ assert_equal url, last_request.uri.normalize.to_s
77
+ end
78
+
79
+ test "returns training" do
80
+ stub_request(:get, /.+/)
81
+ .to_return(status: 200, body: fixtures.join("training.json").read, headers: {"Content-Type" => "application/json"})
82
+
83
+ response, training = client.trainings.find("1234")
84
+
85
+ assert_kind_of Citrix::Training::Resource::Training, training
86
+ end
87
+ end
88
+
89
+ class NamespaceRemoveTest < Minitest::Test
90
+ let(:client) { build_client }
91
+
92
+ test "performs request" do
93
+ stub_request(:delete, /.+/)
94
+
95
+ training = build_training
96
+ url = url_for("organizers", client.credentials.organizer_key, "trainings", training.key)
97
+ client.trainings.remove(training)
98
+
99
+ assert_equal :delete, last_request.method
100
+ assert_equal url, last_request.uri.normalize.to_s
101
+ end
102
+
103
+ test "returns response" do
104
+ stub_request(:delete, /.+/)
105
+ training = build_training
106
+ response = client.trainings.remove(training)
107
+
108
+ assert_kind_of Aitch::Response, response
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ module RegistrantTest
4
+ class ResourceTest < Minitest::Test
5
+ let(:attributes) {
6
+ JSON.load(fixtures.join("registrant.json").read)
7
+ }
8
+
9
+ test "loads all attributes" do
10
+ resource = Citrix::Training::Resource::Registrant.new(
11
+ Citrix::Training::Resource::Registrant.deserialize(attributes)
12
+ )
13
+
14
+ assert_equal "Charley", resource.first_name
15
+ assert_equal "Waters", resource.last_name
16
+ assert_equal "c.waters@test.com", resource.email
17
+ assert_equal "https://global.gototraining.com/join/training/3480581380460709633/107445004", resource.join_url
18
+ assert_equal "https://attendee.gototraining.com/registration/confirmation.tmpl?registrant=5646167387902096129&training=3480581380460709633", resource.confirmation_url
19
+ assert_equal "5646167387902096129", resource.key
20
+ assert_equal "approved", resource.status
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ module TrainingTest
4
+ class ResourceTest < Minitest::Test
5
+ let(:attributes) {
6
+ JSON.load(fixtures.join("training.json").read)
7
+ }
8
+
9
+ test "loads all attributes" do
10
+ resource = Citrix::Training::Resource::Training.new(
11
+ Citrix::Training::Resource::Training.deserialize(attributes)
12
+ )
13
+
14
+ assert_equal "Intro to HTML, CSS and JavaScript", resource.name
15
+ assert_equal "Create basic webpages and sites using HTML 5, CSS3 and basic JavaScript.", resource.description
16
+ assert_equal "America/New_York", resource.timezone
17
+ assert_equal "8178251407424893697", resource.key
18
+ assert resource.confirmation_email
19
+ assert resource.web_registration
20
+ assert_equal 1, resource.dates.size
21
+ assert_equal "2014-03-26T15:00:00Z", resource.dates.first.starts_at.iso8601
22
+ assert_equal "2014-03-26T23:00:00Z", resource.dates.first.ends_at.iso8601
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,53 @@
1
+ require "test_helper"
2
+
3
+ module RegistrantTest
4
+ class SerializerTest < Minitest::Test
5
+ let(:serializer) { Citrix::Training::Serializer::Registrant }
6
+
7
+ test "returns first name" do
8
+ assert_equal "NAME", serialize(first_name: "NAME")[:givenName]
9
+ end
10
+
11
+ test "returns last name" do
12
+ assert_equal "NAME", serialize(last_name: "NAME")[:surname]
13
+ end
14
+
15
+ test "returns email" do
16
+ assert_equal "EMAIL", serialize(email: "EMAIL")[:email]
17
+ end
18
+ end
19
+
20
+ class DeserializerTest < Minitest::Test
21
+ let(:serializer) { Citrix::Training::Serializer::Registrant }
22
+ let(:raw_attrs) { JSON.load(fixtures.join("registrant.json").read) }
23
+ let(:attrs) { deserialize(raw_attrs) }
24
+
25
+ test "returns first name" do
26
+ assert_equal raw_attrs["givenName"], attrs[:first_name]
27
+ end
28
+
29
+ test "returns last name" do
30
+ assert_equal raw_attrs["surname"], attrs[:last_name]
31
+ end
32
+
33
+ test "returns email" do
34
+ assert_equal raw_attrs["email"], attrs[:email]
35
+ end
36
+
37
+ test "returns join url" do
38
+ assert_equal raw_attrs["joinUrl"], attrs[:join_url]
39
+ end
40
+
41
+ test "returns confirmation url" do
42
+ assert_equal raw_attrs["confirmationUrl"], attrs[:confirmation_url]
43
+ end
44
+
45
+ test "returns registrant key" do
46
+ assert_equal raw_attrs["registrantKey"], attrs[:key]
47
+ end
48
+
49
+ test "returns status" do
50
+ assert_equal raw_attrs["status"].downcase, attrs[:status]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ class SerializerTrainingDateTest < Minitest::Test
4
+ let(:serializer) { Citrix::Training::Serializer::TrainingDate }
5
+
6
+ test "returns starting date" do
7
+ starting = Time.now
8
+ ending = starting + 3600
9
+ params = serialize(starts_at: starting, ends_at: ending)
10
+
11
+ assert_equal starting.iso8601, params[:startDate]
12
+ end
13
+
14
+ test "returns ending date" do
15
+ starting = Time.now
16
+ ending = starting + 3600
17
+ params = serialize(starts_at: starting, ends_at: ending)
18
+
19
+ assert_equal ending.iso8601, params[:endDate]
20
+ end
21
+ end
@@ -0,0 +1,82 @@
1
+ require "test_helper"
2
+
3
+ module TrainingTest
4
+ class SerializerTest < Minitest::Test
5
+ let(:serializer) { Citrix::Training::Serializer::Training }
6
+
7
+ test "returns name" do
8
+ assert_equal "NAME", serialize(name: "NAME")[:name]
9
+ end
10
+
11
+ test "returns description" do
12
+ assert_equal "DESCRIPTION", serialize(description: "DESCRIPTION")[:description]
13
+ end
14
+
15
+ test "returns time zone" do
16
+ assert_equal "TZ", serialize(timezone: "TZ")[:timeZone]
17
+ end
18
+
19
+ test "returns registration settings (web registration)" do
20
+ params = serialize(web_registration: true)
21
+ assert_equal false, params[:registrationSettings][:disableWebRegistration]
22
+ end
23
+
24
+ test "returns registration settings (confirmation email)" do
25
+ params = serialize(confirmation_email: true)
26
+ assert_equal false, params[:registrationSettings][:disableConfirmationEmail]
27
+ end
28
+
29
+ test "returns dates" do
30
+ date = Citrix::Training::Resource::TrainingDate.new(Time.now, Time.now + 3600)
31
+ params = serialize(dates: [date])
32
+
33
+ assert_equal 1, params[:times].size
34
+ assert_equal date.starts_at.iso8601, params[:times].first[:startDate]
35
+ assert_equal date.ends_at.iso8601, params[:times].first[:endDate]
36
+ end
37
+ end
38
+
39
+ class DeserializerTest < Minitest::Test
40
+ let(:serializer) { Citrix::Training::Serializer::Training }
41
+ let(:attrs) {
42
+ JSON.load(fixtures.join("training.json").read)
43
+ }
44
+
45
+ test "returns name" do
46
+ assert_equal attrs["name"], deserialize(attrs)[:name]
47
+ end
48
+
49
+ test "returns description" do
50
+ assert_equal attrs["description"], deserialize(attrs)[:description]
51
+ end
52
+
53
+ test "returns time zone" do
54
+ assert_equal attrs["timeZone"], deserialize(attrs)[:timezone]
55
+ end
56
+
57
+ test "returns key" do
58
+ assert_equal attrs["trainingKey"], deserialize(attrs)[:key]
59
+ end
60
+
61
+ test "returns dates" do
62
+ params = deserialize(attrs)
63
+
64
+ starts_at = Time.parse(attrs["times"][0]["startDate"])
65
+ ends_at = Time.parse(attrs["times"][0]["endDate"])
66
+
67
+ assert_equal 1, params[:dates].size
68
+ assert_equal starts_at.to_i, params[:dates].first.starts_at.to_i
69
+ assert_equal ends_at.to_i, params[:dates].first.ends_at.to_i
70
+ end
71
+
72
+ test "returns web registration" do
73
+ params = deserialize(attrs)
74
+ assert_equal true, params[:web_registration]
75
+ end
76
+
77
+ test "returns confirmation e-mail" do
78
+ params = deserialize(attrs)
79
+ assert_equal true, params[:confirmation_email]
80
+ end
81
+ end
82
+ end