mx-platform-ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +20 -0
  3. data/.gitignore +13 -0
  4. data/.rubocop.yml +44 -0
  5. data/Gemfile +5 -0
  6. data/LICENSE +21 -0
  7. data/README.md +60 -0
  8. data/Rakefile +11 -0
  9. data/lib/mx-platform-ruby.rb +44 -0
  10. data/lib/mx-platform-ruby/account.rb +107 -0
  11. data/lib/mx-platform-ruby/account_number.rb +57 -0
  12. data/lib/mx-platform-ruby/account_owner.rb +42 -0
  13. data/lib/mx-platform-ruby/category.rb +127 -0
  14. data/lib/mx-platform-ruby/challenge.rb +37 -0
  15. data/lib/mx-platform-ruby/client.rb +59 -0
  16. data/lib/mx-platform-ruby/connect_widget.rb +43 -0
  17. data/lib/mx-platform-ruby/credential.rb +54 -0
  18. data/lib/mx-platform-ruby/enhanced_transaction.rb +44 -0
  19. data/lib/mx-platform-ruby/error.rb +6 -0
  20. data/lib/mx-platform-ruby/holding.rb +87 -0
  21. data/lib/mx-platform-ruby/institution.rb +78 -0
  22. data/lib/mx-platform-ruby/member.rb +242 -0
  23. data/lib/mx-platform-ruby/member_status.rb +35 -0
  24. data/lib/mx-platform-ruby/merchant.rb +52 -0
  25. data/lib/mx-platform-ruby/oauth_window.rb +32 -0
  26. data/lib/mx-platform-ruby/pageable.rb +29 -0
  27. data/lib/mx-platform-ruby/statement.rb +70 -0
  28. data/lib/mx-platform-ruby/tag.rb +104 -0
  29. data/lib/mx-platform-ruby/tagging.rb +107 -0
  30. data/lib/mx-platform-ruby/transaction.rb +162 -0
  31. data/lib/mx-platform-ruby/transaction_rule.rb +112 -0
  32. data/lib/mx-platform-ruby/user.rb +112 -0
  33. data/lib/mx-platform-ruby/version.rb +5 -0
  34. data/lib/mx-platform-ruby/widget.rb +49 -0
  35. data/mx-platform-ruby.gemspec +31 -0
  36. data/spec/lib/mx-platform-ruby/account_number_spec.rb +100 -0
  37. data/spec/lib/mx-platform-ruby/account_owner_spec.rb +71 -0
  38. data/spec/lib/mx-platform-ruby/account_spec.rb +267 -0
  39. data/spec/lib/mx-platform-ruby/category_spec.rb +244 -0
  40. data/spec/lib/mx-platform-ruby/challenge_spec.rb +72 -0
  41. data/spec/lib/mx-platform-ruby/client_spec.rb +101 -0
  42. data/spec/lib/mx-platform-ruby/connect_widget_spec.rb +66 -0
  43. data/spec/lib/mx-platform-ruby/credential_spec.rb +90 -0
  44. data/spec/lib/mx-platform-ruby/enhanced_transaction_spec.rb +89 -0
  45. data/spec/lib/mx-platform-ruby/holding_spec.rb +178 -0
  46. data/spec/lib/mx-platform-ruby/institution_spec.rb +141 -0
  47. data/spec/lib/mx-platform-ruby/member_spec.rb +557 -0
  48. data/spec/lib/mx-platform-ruby/member_status_spec.rb +76 -0
  49. data/spec/lib/mx-platform-ruby/merchant_spec.rb +89 -0
  50. data/spec/lib/mx-platform-ruby/oauth_window_spec.rb +47 -0
  51. data/spec/lib/mx-platform-ruby/pageable_spec.rb +75 -0
  52. data/spec/lib/mx-platform-ruby/statement_spec.rb +130 -0
  53. data/spec/lib/mx-platform-ruby/tag_spec.rb +179 -0
  54. data/spec/lib/mx-platform-ruby/tagging_spec.rb +191 -0
  55. data/spec/lib/mx-platform-ruby/transaction_rule_spec.rb +207 -0
  56. data/spec/lib/mx-platform-ruby/transaction_spec.rb +449 -0
  57. data/spec/lib/mx-platform-ruby/user_spec.rb +196 -0
  58. data/spec/lib/mx-platform-ruby/widget_spec.rb +76 -0
  59. data/spec/lib/mx-platform-ruby_spec.rb +15 -0
  60. data/spec/sample.pdf +0 -0
  61. data/spec/spec_helper.rb +24 -0
  62. metadata +63 -3
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::MemberStatus do
6
+ let(:member_status_attributes) do
7
+ {
8
+ aggregated_at: '2016-10-13T18:07:57.000Z',
9
+ challenges: [
10
+ {
11
+ field_name: 'Who is this guy?',
12
+ guid: 'CRD-ce76d2e3-86bd-ec4a-ec52-eb53b5194bf5',
13
+ image_data: 'Who is this guy?',
14
+ image_options: [
15
+ {
16
+ data_uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUh ... more image data ...',
17
+ label: 'IMAGE_1',
18
+ value: 'image_data'
19
+ }
20
+ ],
21
+ label: 'Who is this guy?',
22
+ options: [
23
+ {
24
+ label: 'IMAGE_1',
25
+ value: 'image_data'
26
+ }
27
+ ],
28
+ type: 'IMAGE_DATA'
29
+ }
30
+ ],
31
+ connection_status: 'CONNECTED',
32
+ guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
33
+ has_processed_accounts: true,
34
+ has_processed_transactions: false,
35
+ is_authenticated: false,
36
+ is_being_aggregated: false,
37
+ successfully_aggregated_at: '2016-10-13T17:57:38.000Z'
38
+ }
39
+ end
40
+ let(:read_member_status_options) do
41
+ {
42
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
43
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
44
+ }
45
+ end
46
+
47
+ describe 'read_member_status' do
48
+ let(:read_member_status_response) { { 'member' => member_status_attributes } }
49
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(read_member_status_response) }
50
+
51
+ it 'returns member_status' do
52
+ response = described_class.read_member_status
53
+
54
+ expect(response).to be_kind_of(::MXPlatformRuby::MemberStatus)
55
+ expect(response.aggregated_at).to eq(member_status_attributes[:aggregated_at])
56
+ expect(response.challenges).to eq(member_status_attributes[:challenges])
57
+ expect(response.connection_status).to eq(member_status_attributes[:connection_status])
58
+ expect(response.guid).to eq(member_status_attributes[:guid])
59
+ expect(response.has_processed_accounts).to eq(member_status_attributes[:has_processed_accounts])
60
+ expect(response.has_processed_transactions).to eq(member_status_attributes[:has_processed_transactions])
61
+ expect(response.is_authenticated).to eq(member_status_attributes[:is_authenticated])
62
+ expect(response.is_being_aggregated).to eq(member_status_attributes[:is_being_aggregated])
63
+ expect(response.successfully_aggregated_at).to eq(member_status_attributes[:successfully_aggregated_at])
64
+ end
65
+
66
+ it 'makes a client request with the expected params' do
67
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
68
+ {
69
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/members/MBR-7c6f361b-e582-15b6-60c0-358f12466b4b/status',
70
+ http_method: :get
71
+ }
72
+ )
73
+ described_class.read_member_status(read_member_status_options)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::Merchant do
6
+ let(:merchant_attributes) do
7
+ {
8
+ created_at: '2017-04-20T19:30:12.000Z',
9
+ guid: 'MCH-7ed79542-884d-2b1b-dd74-501c5cc9d25b',
10
+ logo_url: 'https://s3.amazonaws.com/MD_Assets/merchant_logos/comcast.png',
11
+ name: 'Comcast',
12
+ updated_at: '2018-09-28T21:13:53.000Z',
13
+ website_url: 'https://www.xfinity.com'
14
+ }
15
+ end
16
+ let(:list_merchants_options) do
17
+ {
18
+ page: 1,
19
+ records_per_page: 10
20
+ }
21
+ end
22
+ let(:read_merchant_options) do
23
+ {
24
+ merchant_guid: 'MCH-7ed79542-884d-2b1b-dd74-501c5cc9d25b'
25
+ }
26
+ end
27
+ let(:pagination_attributes) do
28
+ {
29
+ 'current_page' => 1,
30
+ 'per_page' => 25,
31
+ 'total_pages' => 1,
32
+ 'total_entries' => 1
33
+ }
34
+ end
35
+
36
+ context 'list_merchants endpoints' do
37
+ let(:list_merchants_response) do
38
+ {
39
+ 'merchants' => [merchant_attributes],
40
+ 'pagination' => pagination_attributes
41
+ }
42
+ end
43
+
44
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(list_merchants_response) }
45
+
46
+ describe 'list_merchants' do
47
+ it 'returns a list of merchants' do
48
+ response = described_class.list_merchants
49
+
50
+ expect(response).to be_kind_of(::MXPlatformRuby::Page)
51
+ expect(response.first).to be_kind_of(::MXPlatformRuby::Merchant)
52
+ expect(response.first.created_at).to eq(merchant_attributes[:created_at])
53
+ expect(response.first.guid).to eq(merchant_attributes[:guid])
54
+ expect(response.first.logo_url).to eq(merchant_attributes[:logo_url])
55
+ expect(response.first.name).to eq(merchant_attributes[:name])
56
+ expect(response.first.updated_at).to eq(merchant_attributes[:updated_at])
57
+ expect(response.first.website_url).to eq(merchant_attributes[:website_url])
58
+ expect(response.length).to eq(1)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe 'read_merchant' do
64
+ let(:read_merchant_response) { { 'merchant' => merchant_attributes } }
65
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(read_merchant_response) }
66
+
67
+ it 'returns merchant' do
68
+ response = described_class.read_merchant
69
+
70
+ expect(response).to be_kind_of(::MXPlatformRuby::Merchant)
71
+ expect(response.created_at).to eq(merchant_attributes[:created_at])
72
+ expect(response.guid).to eq(merchant_attributes[:guid])
73
+ expect(response.logo_url).to eq(merchant_attributes[:logo_url])
74
+ expect(response.name).to eq(merchant_attributes[:name])
75
+ expect(response.updated_at).to eq(merchant_attributes[:updated_at])
76
+ expect(response.website_url).to eq(merchant_attributes[:website_url])
77
+ end
78
+
79
+ it 'makes a client request with the expected params' do
80
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
81
+ {
82
+ endpoint: '/merchants/MCH-7ed79542-884d-2b1b-dd74-501c5cc9d25b',
83
+ http_method: :get
84
+ }
85
+ )
86
+ described_class.read_merchant(read_merchant_options)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::OAuthWindow do
6
+ let(:oauth_window_attributes) do
7
+ {
8
+ guid: 'MBR-df96fd60-7122-4464-b3c2-ff11d8c74f6f',
9
+ oauth_window_uri: 'int-widgets.moneydesktop.com/oauth/predirect_to/MBR-df96fd60-7122-4464-b3c2-ff11d8c74f6f/zgknnw5k7dmztn2njmwlgz574mZlnft6vdrv7kzn9ptj325th6c5p0w6c7j83Ap1bqg01mhsr1bqjgf2fry3ly9wff497c6fcczbyrfgj7s39cygw95Akl7vlpmcAy2kmvh1mlkytg7jA1z3vnw1w3zx2r1wt65s6f6r3ryqqrysl9qA1kr6cAj6vhr1zl325Azz6hx52j1ll3vwbvvbv5xzy7d6csplyw25brA7147vAfq29ArjjAj4qmc6r6h457hkcj2946m0kjp2xzpkz6hz55lsp3Avmdb8dsq4xzqmzzqk68s6bp5tj9jsskw4wvcb95vm4fwh9w8phgp67hfj2flrtwcy5bxbtk74?skip_aggregation=false'
10
+ }
11
+ end
12
+ let(:request_oauth_window_options) do
13
+ {
14
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
15
+ referral_source: 'APP',
16
+ ui_message_webview_url_scheme: 'mx',
17
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
18
+ }
19
+ end
20
+
21
+ describe 'request_oauth_window' do
22
+ let(:request_oauth_window_response) { { 'member' => oauth_window_attributes } }
23
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(request_oauth_window_response) }
24
+
25
+ it 'returns oauth_window' do
26
+ response = described_class.request_oauth_window
27
+
28
+ expect(response).to be_kind_of(::MXPlatformRuby::OAuthWindow)
29
+ expect(response.guid).to eq(oauth_window_attributes[:guid])
30
+ expect(response.oauth_window_uri).to eq(oauth_window_attributes[:oauth_window_uri])
31
+ end
32
+
33
+ it 'makes a client request with the expected params' do
34
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
35
+ {
36
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/members/MBR-7c6f361b-e582-15b6-60c0-358f12466b4b/oauth_window_uri',
37
+ http_method: :get,
38
+ query_params: {
39
+ referral_source: 'APP',
40
+ ui_message_webview_url_scheme: 'mx'
41
+ }.compact
42
+ }
43
+ )
44
+ described_class.request_oauth_window(request_oauth_window_options)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ class Record
6
+ extend ::MXPlatformRuby::Pageable
7
+ include ::ActiveAttr::Model
8
+ attribute :record_attribute
9
+ end
10
+
11
+ RSpec.describe ::MXPlatformRuby::Pageable do
12
+ subject { ::Record }
13
+
14
+ let(:accept_header) { { 'Accept' => 'application/json' } }
15
+ let(:empty_response) do
16
+ {
17
+ 'records' => [],
18
+ 'pagination' => {
19
+ 'current_page' => 1,
20
+ 'per_page' => per_page,
21
+ 'total_entries' => 0,
22
+ 'total_pages' => 1
23
+ }
24
+ }
25
+ end
26
+ let(:first) { 1 }
27
+ let(:first_page) { ::MXPlatformRuby::Page.new(2, record) }
28
+ let(:first_page_response) do
29
+ {
30
+ 'records' => ::Array.new(2, record_response),
31
+ 'pagination' => {
32
+ 'current_page' => first,
33
+ 'per_page' => per_page,
34
+ 'total_entries' => total_entries,
35
+ 'total_pages' => total_pages
36
+ }
37
+ }
38
+ end
39
+ let(:options) do
40
+ {
41
+ accept_header: 'application/json',
42
+ endpoint: '/records',
43
+ resource: 'records'
44
+ }
45
+ end
46
+ let(:record) { ::Record.new('record_attribute' => 'record_value') }
47
+ let(:record_response) { { 'record_attribute' => 'record_value' } }
48
+ let(:per_page) { 2 }
49
+ let(:total_entries) { 3 }
50
+ let(:total_pages) { 2 }
51
+
52
+ before do
53
+ allow(::MXPlatformRuby.client).to receive(:make_request).with({ accept_header: 'application/json', endpoint: '/records', resource: 'records' })
54
+ .and_return(first_page_response)
55
+ end
56
+
57
+ describe '.paginate' do
58
+ it 'returns the first Page' do
59
+ page = subject.paginate(options)
60
+ expect(page).to eq(first_page)
61
+ expect(page.current_page).to eq(first)
62
+ expect(page.per_page).to eq(per_page)
63
+ expect(page.total_entries).to eq(total_entries)
64
+ expect(page.total_pages).to eq(total_pages)
65
+ end
66
+
67
+ context 'with no results' do
68
+ it 'returns an empty Page' do
69
+ allow(::MXPlatformRuby.client).to receive(:make_request).and_return(empty_response)
70
+ page = subject.paginate(options)
71
+ expect(page).to eq(::MXPlatformRuby::Page.new)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::Statement do
6
+ let(:statement_attributes) do
7
+ {
8
+ account_guid: 'ACT-06d7f44b-caae-0f6e-1384-01f52e75dcb1',
9
+ content_hash: 'ca53785b812d00ef821c3d94bfd6e5bbc0020504410589b7ea8552169f021981',
10
+ created_at: '2016-10-13T18:08:00+00:00',
11
+ guid: 'STA-737a344b-caae-0f6e-1384-01f52e75dcb1',
12
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
13
+ updated_at: '2016-10-13T18:09:00+00:00',
14
+ uri: 'uri/to/statement',
15
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
16
+ }
17
+ end
18
+ let(:download_statement_pdf_options) do
19
+ {
20
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
21
+ statement_guid: 'STA-737a344b-caae-0f6e-1384-01f52e75dcb1',
22
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
23
+ }
24
+ end
25
+ let(:list_statements_by_member_options) do
26
+ {
27
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
28
+ page: 1,
29
+ records_per_page: 10,
30
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
31
+ }
32
+ end
33
+ let(:read_statement_by_member_options) do
34
+ {
35
+ member_guid: 'MBR-7c6f361b-e582-15b6-60c0-358f12466b4b',
36
+ statement_guid: 'STA-737a344b-caae-0f6e-1384-01f52e75dcb1',
37
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
38
+ }
39
+ end
40
+ let(:pagination_attributes) do
41
+ {
42
+ 'current_page' => 1,
43
+ 'per_page' => 25,
44
+ 'total_pages' => 1,
45
+ 'total_entries' => 1
46
+ }
47
+ end
48
+
49
+ describe 'download_statement_pdf' do
50
+ let(:statement_file) { ::Tempfile.new('spec/sample.pdf') }
51
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(statement_file) }
52
+
53
+ it 'returns statement file' do
54
+ response = described_class.download_statement_pdf
55
+
56
+ expect(response).to be(statement_file)
57
+ end
58
+
59
+ it 'makes a client request with the expected params' do
60
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
61
+ {
62
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/members/MBR-7c6f361b-e582-15b6-60c0-358f12466b4b/statements/STA-737a344b-caae-0f6e-1384-01f52e75dcb1.pdf',
63
+ headers: {
64
+ 'Accept': 'application/vnd.mx.api.v1+pdf'
65
+ },
66
+ http_method: :get
67
+ }
68
+ )
69
+ described_class.download_statement_pdf(download_statement_pdf_options)
70
+ end
71
+ end
72
+
73
+ context 'list_statements_by_member endpoints' do
74
+ let(:list_statements_by_member_response) do
75
+ {
76
+ 'statements' => [statement_attributes],
77
+ 'pagination' => pagination_attributes
78
+ }
79
+ end
80
+
81
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(list_statements_by_member_response) }
82
+
83
+ describe 'list_statements_by_member' do
84
+ it 'returns a list of statements' do
85
+ response = described_class.list_statements_by_member
86
+
87
+ expect(response).to be_kind_of(::MXPlatformRuby::Page)
88
+ expect(response.first).to be_kind_of(::MXPlatformRuby::Statement)
89
+ expect(response.first.account_guid).to eq(statement_attributes[:account_guid])
90
+ expect(response.first.content_hash).to eq(statement_attributes[:content_hash])
91
+ expect(response.first.created_at).to eq(statement_attributes[:created_at])
92
+ expect(response.first.guid).to eq(statement_attributes[:guid])
93
+ expect(response.first.member_guid).to eq(statement_attributes[:member_guid])
94
+ expect(response.first.updated_at).to eq(statement_attributes[:updated_at])
95
+ expect(response.first.uri).to eq(statement_attributes[:uri])
96
+ expect(response.first.user_guid).to eq(statement_attributes[:user_guid])
97
+ expect(response.length).to eq(1)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe 'read_statement_by_member' do
103
+ let(:read_statement_by_member_response) { { 'statement' => statement_attributes } }
104
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(read_statement_by_member_response) }
105
+
106
+ it 'returns statement' do
107
+ response = described_class.read_statement_by_member
108
+
109
+ expect(response).to be_kind_of(::MXPlatformRuby::Statement)
110
+ expect(response.account_guid).to eq(statement_attributes[:account_guid])
111
+ expect(response.content_hash).to eq(statement_attributes[:content_hash])
112
+ expect(response.created_at).to eq(statement_attributes[:created_at])
113
+ expect(response.guid).to eq(statement_attributes[:guid])
114
+ expect(response.member_guid).to eq(statement_attributes[:member_guid])
115
+ expect(response.updated_at).to eq(statement_attributes[:updated_at])
116
+ expect(response.uri).to eq(statement_attributes[:uri])
117
+ expect(response.user_guid).to eq(statement_attributes[:user_guid])
118
+ end
119
+
120
+ it 'makes a client request with the expected params' do
121
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
122
+ {
123
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/members/MBR-7c6f361b-e582-15b6-60c0-358f12466b4b/statements/STA-737a344b-caae-0f6e-1384-01f52e75dcb1',
124
+ http_method: :get
125
+ }
126
+ )
127
+ described_class.read_statement_by_member(read_statement_by_member_options)
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::MXPlatformRuby::Tag do
6
+ let(:tag_attributes) do
7
+ {
8
+ guid: 'TAG-aef36e72-6294-4c38-844d-e573e80aed52',
9
+ name: 'MY TAG',
10
+ user_guid: 'USR-11141024-90b3-1bce-cac9-c06ced52ab4c'
11
+ }
12
+ end
13
+ let(:create_tag_options) do
14
+ {
15
+ name: 'MY TAG',
16
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
17
+ }
18
+ end
19
+ let(:delete_tag_options) do
20
+ {
21
+ tag_guid: 'TAG-aef36e72-6294-4c38-844d-e573e80aed52',
22
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
23
+ }
24
+ end
25
+ let(:list_tags_options) do
26
+ {
27
+ page: 1,
28
+ records_per_page: 10,
29
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
30
+ }
31
+ end
32
+ let(:read_tag_options) do
33
+ {
34
+ tag_guid: 'TAG-aef36e72-6294-4c38-844d-e573e80aed52',
35
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
36
+ }
37
+ end
38
+ let(:update_tag_options) do
39
+ {
40
+ name: 'MY TAG',
41
+ tag_guid: 'TAG-aef36e72-6294-4c38-844d-e573e80aed52',
42
+ user_guid: 'USR-fa7537f3-48aa-a683-a02a-b18940482f54'
43
+ }
44
+ end
45
+ let(:pagination_attributes) do
46
+ {
47
+ 'current_page' => 1,
48
+ 'per_page' => 25,
49
+ 'total_pages' => 1,
50
+ 'total_entries' => 1
51
+ }
52
+ end
53
+
54
+ describe 'create_tag' do
55
+ let(:create_tag_response) { { 'tag' => tag_attributes } }
56
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(create_tag_response) }
57
+
58
+ it 'returns tag' do
59
+ response = described_class.create_tag
60
+
61
+ expect(response).to be_kind_of(::MXPlatformRuby::Tag)
62
+ expect(response.guid).to eq(tag_attributes[:guid])
63
+ expect(response.name).to eq(tag_attributes[:name])
64
+ expect(response.user_guid).to eq(tag_attributes[:user_guid])
65
+ end
66
+
67
+ it 'makes a client request with the expected params' do
68
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
69
+ {
70
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/tags',
71
+ http_method: :post,
72
+ request_body: {
73
+ tag: {
74
+ name: 'MY TAG'
75
+ }
76
+ }
77
+ }
78
+ )
79
+ described_class.create_tag(create_tag_options)
80
+ end
81
+ end
82
+
83
+ describe 'delete_tag' do
84
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(nil) }
85
+
86
+ it 'returns nil' do
87
+ response = described_class.delete_tag
88
+
89
+ expect(response).to be(nil)
90
+ end
91
+
92
+ it 'makes a client request with the expected params' do
93
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
94
+ {
95
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/tags/TAG-aef36e72-6294-4c38-844d-e573e80aed52',
96
+ http_method: :delete
97
+ }
98
+ )
99
+ described_class.delete_tag(delete_tag_options)
100
+ end
101
+ end
102
+
103
+ context 'list_tags endpoints' do
104
+ let(:list_tags_response) do
105
+ {
106
+ 'tags' => [tag_attributes],
107
+ 'pagination' => pagination_attributes
108
+ }
109
+ end
110
+
111
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(list_tags_response) }
112
+
113
+ describe 'list_tags' do
114
+ it 'returns a list of tags' do
115
+ response = described_class.list_tags
116
+
117
+ expect(response).to be_kind_of(::MXPlatformRuby::Page)
118
+ expect(response.first).to be_kind_of(::MXPlatformRuby::Tag)
119
+ expect(response.first.guid).to eq(tag_attributes[:guid])
120
+ expect(response.first.name).to eq(tag_attributes[:name])
121
+ expect(response.first.user_guid).to eq(tag_attributes[:user_guid])
122
+ expect(response.length).to eq(1)
123
+ end
124
+ end
125
+ end
126
+
127
+ describe 'read_tag' do
128
+ let(:read_tag_response) { { 'tag' => tag_attributes } }
129
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(read_tag_response) }
130
+
131
+ it 'returns tag' do
132
+ response = described_class.read_tag
133
+
134
+ expect(response).to be_kind_of(::MXPlatformRuby::Tag)
135
+ expect(response.guid).to eq(tag_attributes[:guid])
136
+ expect(response.name).to eq(tag_attributes[:name])
137
+ expect(response.user_guid).to eq(tag_attributes[:user_guid])
138
+ end
139
+
140
+ it 'makes a client request with the expected params' do
141
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
142
+ {
143
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/tags/TAG-aef36e72-6294-4c38-844d-e573e80aed52',
144
+ http_method: :get
145
+ }
146
+ )
147
+ described_class.read_tag(read_tag_options)
148
+ end
149
+ end
150
+
151
+ describe 'update_tag' do
152
+ let(:update_tag_response) { { 'tag' => tag_attributes } }
153
+ before { allow(::MXPlatformRuby.client).to receive(:make_request).and_return(update_tag_response) }
154
+
155
+ it 'returns tag' do
156
+ response = described_class.update_tag
157
+
158
+ expect(response).to be_kind_of(::MXPlatformRuby::Tag)
159
+ expect(response.guid).to eq(tag_attributes[:guid])
160
+ expect(response.name).to eq(tag_attributes[:name])
161
+ expect(response.user_guid).to eq(tag_attributes[:user_guid])
162
+ end
163
+
164
+ it 'makes a client request with the expected params' do
165
+ expect(::MXPlatformRuby.client).to receive(:make_request).with(
166
+ {
167
+ endpoint: '/users/USR-fa7537f3-48aa-a683-a02a-b18940482f54/tags/TAG-aef36e72-6294-4c38-844d-e573e80aed52',
168
+ http_method: :put,
169
+ request_body: {
170
+ tag: {
171
+ name: 'MY TAG'
172
+ }
173
+ }
174
+ }
175
+ )
176
+ described_class.update_tag(update_tag_options)
177
+ end
178
+ end
179
+ end