mrkt 0.9.0 → 0.10.0

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.
@@ -19,8 +19,9 @@ module Mrkt
19
19
  primaryAttributeValue: primary_attribute_value,
20
20
  attributes: converted_attributes
21
21
  }]
22
- post('/rest/v1/activities/external.json') do |req|
23
- json_payload(req, input: input)
22
+
23
+ post_json('/rest/v1/activities/external.json') do
24
+ { input: input }
24
25
  end
25
26
  end
26
27
 
@@ -8,45 +8,44 @@ module Mrkt
8
8
  end
9
9
 
10
10
  def describe_custom_object(name)
11
- fail Mrkt::Errors::Unknown unless name
11
+ raise Mrkt::Errors::Unknown unless name
12
12
 
13
13
  get("/rest/v1/customobjects/#{name}/describe.json")
14
14
  end
15
15
 
16
16
  def createupdate_custom_objects(name, input, action: 'createOrUpdate', dedupe_by: 'dedupeFields')
17
- post("/rest/v1/customobjects/#{name}.json") do |req|
18
- params = {
17
+ post_json("/rest/v1/customobjects/#{name}.json") do
18
+ {
19
19
  input: input,
20
20
  action: action,
21
21
  dedupeBy: dedupe_by
22
22
  }
23
- json_payload(req, params)
24
23
  end
25
24
  end
26
25
 
27
26
  def delete_custom_objects(name, input, delete_by: 'dedupeFields')
28
- post("/rest/v1/customobjects/#{name}/delete.json") do |req|
29
- params = {
27
+ post_json("/rest/v1/customobjects/#{name}/delete.json") do
28
+ {
30
29
  input: input,
31
30
  deleteBy: delete_by
32
31
  }
33
-
34
- json_payload(req, params)
35
32
  end
36
33
  end
37
34
 
38
35
  def get_custom_objects(name, input, filter_type: 'dedupeFields', fields: nil, next_page_token: nil, batch_size: nil)
39
- post("/rest/v1/customobjects/#{name}.json?_method=GET") do |req|
36
+ post_json("/rest/v1/customobjects/#{name}.json?_method=GET") do
40
37
  params = {
41
38
  input: input,
42
39
  filterType: filter_type
43
40
  }
44
41
 
45
- params[:fields] = fields if fields
46
- params[:nextPageToken] = next_page_token if next_page_token
47
- params[:batchSize] = batch_size if batch_size
42
+ optional = {
43
+ fields: fields,
44
+ nextPageToken: next_page_token,
45
+ batchSize: batch_size
46
+ }
48
47
 
49
- json_payload(req, params)
48
+ merge_params(params, optional)
50
49
  end
51
50
  end
52
51
  end
@@ -4,6 +4,13 @@ module Mrkt
4
4
  lead_ids.map { |id| { id: id } }
5
5
  end
6
6
 
7
+ def post_json(url)
8
+ post(url) do |req|
9
+ payload = block_given? ? yield(req) : {}
10
+ json_payload(req, payload)
11
+ end
12
+ end
13
+
7
14
  def json_payload(req, payload)
8
15
  req.headers[:content_type] = 'application/json'
9
16
  req.body = JSON.generate(payload)
@@ -1,28 +1,42 @@
1
1
  module Mrkt
2
2
  module CrudLeads
3
+ def get_lead_by_id(id, fields: nil)
4
+ optional = {
5
+ fields: fields&.join(',')
6
+ }
7
+
8
+ get("/rest/v1/lead/#{id}.json", {}, optional)
9
+ end
10
+
3
11
  def get_leads(filter_type, filter_values, fields: nil, batch_size: nil, next_page_token: nil)
4
12
  params = {
5
13
  filterType: filter_type,
6
14
  filterValues: filter_values.join(',')
7
15
  }
8
- params[:fields] = fields if fields
9
- params[:batchSize] = batch_size if batch_size
10
- params[:nextPageToken] = next_page_token if next_page_token
11
16
 
12
- get('/rest/v1/leads.json', params)
17
+ optional = {
18
+ fields: fields,
19
+ batchSize: batch_size,
20
+ nextPageToken: next_page_token
21
+ }
22
+
23
+ get('/rest/v1/leads.json', params, optional)
13
24
  end
14
25
 
15
26
  def createupdate_leads(leads, action: 'createOrUpdate', lookup_field: nil, partition_name: nil, async_processing: nil)
16
- post('/rest/v1/leads.json') do |req|
27
+ post_json('/rest/v1/leads.json') do
17
28
  params = {
18
29
  action: action,
19
30
  input: leads
20
31
  }
21
- params[:lookupField] = lookup_field if lookup_field
22
- params[:partitionName] = partition_name if partition_name
23
- params[:asyncProcessing] = async_processing if async_processing
24
32
 
25
- json_payload(req, params)
33
+ optional = {
34
+ lookupField: lookup_field,
35
+ partitionName: partition_name,
36
+ asyncProcessing: async_processing
37
+ }
38
+
39
+ merge_params(params, optional)
26
40
  end
27
41
  end
28
42
 
@@ -36,9 +50,7 @@ module Mrkt
36
50
  params = Faraday::Utils::ParamsHash.new
37
51
  params[:cookie] = cookie
38
52
 
39
- post("/rest/v1/leads/#{id}/associate.json?#{params.to_query}") do |req|
40
- json_payload(req, {})
41
- end
53
+ post_json("/rest/v1/leads/#{id}/associate.json?#{params.to_query}")
42
54
  end
43
55
 
44
56
  def merge_leads(winning_lead_id, losing_lead_ids, merge_in_crm: false)
@@ -46,10 +58,11 @@ module Mrkt
46
58
  params[:mergeInCRM] = merge_in_crm
47
59
  params[:leadIds] = losing_lead_ids.join(',') if losing_lead_ids
48
60
 
49
- post("/rest/v1/leads/#{winning_lead_id}/merge.json?#{params.to_query}") do |req|
50
- json_payload(req,{})
51
- end
61
+ post_json("/rest/v1/leads/#{winning_lead_id}/merge.json?#{params.to_query}")
52
62
  end
53
63
 
64
+ def describe_lead
65
+ get('/rest/v1/leads/describe.json')
66
+ end
54
67
  end
55
68
  end
@@ -1,21 +1,24 @@
1
1
  module Mrkt
2
2
  module CrudLists
3
3
  def get_leads_by_list(list_id, fields: nil, batch_size: nil, next_page_token: nil)
4
- params = {}
5
- params[:fields] = fields if fields
6
- params[:batchSize] = batch_size if batch_size
7
- params[:nextPageToken] = next_page_token if next_page_token
4
+ optional = {
5
+ fields: fields,
6
+ batchSize: batch_size,
7
+ nextPageToken: next_page_token
8
+ }
8
9
 
9
- get("/rest/v1/list/#{list_id}/leads.json", params)
10
+ get("/rest/v1/list/#{list_id}/leads.json", {}, optional)
10
11
  end
11
12
 
12
13
  def add_leads_to_list(list_id, lead_ids)
13
- post("/rest/v1/lists/#{list_id}/leads.json") do |req|
14
- params = {
15
- input: map_lead_ids(lead_ids)
16
- }
14
+ post_json("/rest/v1/lists/#{list_id}/leads.json") do
15
+ { input: map_lead_ids(lead_ids) }
16
+ end
17
+ end
17
18
 
18
- json_payload(req, params)
19
+ def remove_leads_from_list(list_id, lead_ids)
20
+ delete("/rest/v1/lists/#{list_id}/leads.json") do |req|
21
+ json_payload(req, input: map_lead_ids(lead_ids))
19
22
  end
20
23
  end
21
24
  end
@@ -1,12 +1,13 @@
1
1
  module Mrkt
2
2
  module CrudPrograms
3
3
  def browse_programs(offset: nil, max_return: nil, status: nil)
4
- params = {}
5
- params[:offset] = offset if offset
6
- params[:maxReturn] = max_return if max_return
7
- params[:status] = status if status
4
+ optional = {
5
+ offset: offset,
6
+ maxReturn: max_return,
7
+ status: status
8
+ }
8
9
 
9
- get('/rest/asset/v1/programs.json', params)
10
+ get('/rest/asset/v1/programs.json', {}, optional)
10
11
  end
11
12
 
12
13
  def get_program_by_id(id)
@@ -5,11 +5,14 @@ module Mrkt
5
5
  format: format,
6
6
  file: Faraday::UploadIO.new(file, 'text/csv')
7
7
  }
8
- params[:lookupField] = lookup_field if lookup_field
9
- params[:listId] = list_id if list_id
10
- params[:partitionName] = partition_name if partition_name
11
8
 
12
- post('/bulk/v1/leads.json', params)
9
+ optional = {
10
+ lookupField: lookup_field,
11
+ listId: list_id,
12
+ partitionName: partition_name
13
+ }
14
+
15
+ post('/bulk/v1/leads.json', params, optional)
13
16
  end
14
17
 
15
18
  def import_lead_status(id)
@@ -25,6 +25,7 @@ class Mrkt::Errors
25
25
  610 => 'RequestedResourceNotFound',
26
26
  611 => 'System',
27
27
  612 => 'InvalidContentType',
28
+ 702 => 'RecordNotFound',
28
29
  703 => 'DisabledFeature',
29
30
  1001 => 'TypeMismatch',
30
31
  1002 => 'MissingParamater',
@@ -40,9 +41,9 @@ class Mrkt::Errors
40
41
  1012 => 'InvalidCookieValue',
41
42
  1013 => 'ObjectNotFound',
42
43
  1014 => 'FailedToCreateObject'
43
- }
44
+ }.freeze
44
45
 
45
- RESPONSE_CODE_TO_ERROR.values.each do |class_name|
46
+ RESPONSE_CODE_TO_ERROR.each_value do |class_name|
46
47
  const_set(class_name, create_class)
47
48
  end
48
49
 
@@ -1,3 +1,3 @@
1
1
  module Mrkt
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'.freeze
3
3
  end
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'mrkt/version'
5
4
 
@@ -16,19 +15,18 @@ Gem::Specification.new do |spec|
16
15
  spec.files = `git ls-files`.split($RS)
17
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = %w(lib)
18
+ spec.require_paths = %w[lib]
20
19
 
21
- spec.required_ruby_version = '~> 2.0'
20
+ spec.required_ruby_version = '~> 2.3'
22
21
 
23
- spec.add_dependency 'faraday', '> 0.9.0', '< 0.14.0'
24
- spec.add_dependency 'faraday_middleware', '> 0.9.0', '< 0.13.0'
22
+ spec.add_dependency 'faraday', '> 0.9.0', '< 0.16.0'
23
+ spec.add_dependency 'faraday_middleware', '> 0.9.0', '< 0.16.0'
25
24
 
26
25
  spec.add_development_dependency 'bundler', '~> 1.3'
27
- spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
27
+ spec.add_development_dependency 'pry-byebug', '~> 3.7'
28
+ spec.add_development_dependency 'rake', '~> 12.3'
28
29
  spec.add_development_dependency 'rspec', '~> 3.2'
29
- spec.add_development_dependency 'webmock', '~> 1.21.0'
30
- spec.add_development_dependency 'simplecov', '~> 0.14.1'
31
- spec.add_development_dependency 'pry-byebug', '~> 3.4.0'
32
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
33
- spec.add_development_dependency 'rubocop', '~> 0.45.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.66.0'
31
+ spec.add_development_dependency 'webmock', '~> 3.1'
34
32
  end
@@ -32,6 +32,8 @@ describe Mrkt::Authentication do
32
32
  context 'when the token has expired and @retry_authentication = true' do
33
33
  before { remove_request_stub(@authentication_request_stub) }
34
34
 
35
+ let(:retry_count) { 3 }
36
+
35
37
  let(:expired_authentication_stub) do
36
38
  { access_token: SecureRandom.uuid, token_type: 'bearer', expires_in: 0, scope: 'RestClient' }
37
39
  end
@@ -40,7 +42,17 @@ describe Mrkt::Authentication do
40
42
  { access_token: SecureRandom.uuid, token_type: 'bearer', expires_in: 1234, scope: 'RestClient' }
41
43
  end
42
44
 
43
- subject(:client) { Mrkt::Client.new(host: host, client_id: client_id, client_secret: client_secret, retry_authentication: true) }
45
+ let(:client_options) do
46
+ {
47
+ host: host,
48
+ client_id: client_id,
49
+ client_secret: client_secret,
50
+ retry_authentication: true,
51
+ retry_authentication_count: retry_count
52
+ }
53
+ end
54
+
55
+ subject(:client) { Mrkt::Client.new(client_options) }
44
56
 
45
57
  before do
46
58
  stub_request(:get, "https://#{host}/identity/oauth/token")
@@ -55,12 +67,14 @@ describe Mrkt::Authentication do
55
67
  expect(client.authenticated?).to be true
56
68
  end
57
69
 
58
- it 'should stop retrying after @retry_authentication_count tries and then raise an error' do
59
- client = Mrkt::Client.new(host: host, client_id: client_id, client_secret: client_secret, retry_authentication: true, retry_authentication_count: 2)
70
+ context 'when retry_authentication_count is low' do
71
+ let(:retry_count) { 2 }
60
72
 
61
- expect(client.authenticated?).to_not be true
73
+ it 'should stop retrying after @retry_authentication_count tries and then raise an error' do
74
+ expect(client.authenticated?).to_not be true
62
75
 
63
- expect { client.authenticate! }.to raise_error(Mrkt::Errors::Error, 'Client not authenticated')
76
+ expect { client.authenticate! }.to raise_error(Mrkt::Errors::Error, 'Client not authenticated')
77
+ end
64
78
  end
65
79
  end
66
80
  end
@@ -110,7 +110,7 @@ describe Mrkt::CrudActivities do
110
110
 
111
111
  before do
112
112
  stub_request(:get, "https://#{host}/rest/v1/activities.json")
113
- .with(query: { nextPageToken: URI.encode(token) })
113
+ .with(query: { nextPageToken: token })
114
114
  .to_return(json_stub(response_stub))
115
115
  end
116
116
 
@@ -152,7 +152,7 @@ describe Mrkt::CrudActivities do
152
152
  before do
153
153
  stub_request(:get, "https://#{host}/rest/v1/activities.json")
154
154
  .with(query: {
155
- nextPageToken: URI.encode(token),
155
+ nextPageToken: token,
156
156
  activityTypeIds: activity_type_ids.join(',')
157
157
  })
158
158
  .to_return(json_stub(response_stub))
@@ -196,7 +196,7 @@ describe Mrkt::CrudActivities do
196
196
 
197
197
  before do
198
198
  stub_request(:get, "https://#{host}/rest/v1/activities.json")
199
- .with(query: { nextPageToken: URI.encode(token), leadIds: lead_ids.join(',') })
199
+ .with(query: { nextPageToken: token, leadIds: lead_ids.join(',') })
200
200
  .to_return(json_stub(response_stub))
201
201
  end
202
202
 
@@ -204,15 +204,15 @@ describe Mrkt::CrudActivities do
204
204
  end
205
205
 
206
206
  context 'specifying arrays values as empty strings' do
207
- let(:activity_type_ids) { "" }
208
- let(:lead_ids) { "" }
207
+ let(:activity_type_ids) { '' }
208
+ let(:lead_ids) { '' }
209
209
  subject do
210
210
  client.get_activities(token, activity_type_ids: activity_type_ids, lead_ids: lead_ids)
211
211
  end
212
212
 
213
213
  before do
214
214
  stub_request(:get, "https://#{host}/rest/v1/activities.json")
215
- .with(query: { nextPageToken: URI.encode(token) })
215
+ .with(query: { nextPageToken: token })
216
216
  .to_return(json_stub(response_stub))
217
217
  end
218
218
 
@@ -227,7 +227,7 @@ describe Mrkt::CrudActivities do
227
227
  before do
228
228
  stub_request(:get, "https://#{host}/rest/v1/activities.json")
229
229
  .with(query: {
230
- nextPageToken: URI.encode(token),
230
+ nextPageToken: token,
231
231
  activityTypeIds: activity_type_ids.join(','),
232
232
  leadIds: lead_ids.join(',')
233
233
  })
@@ -237,4 +237,43 @@ describe Mrkt::CrudActivities do
237
237
  it { is_expected.to eq(response_stub) }
238
238
  end
239
239
  end
240
+
241
+ describe '#get_deleted_leads' do
242
+ let(:token) { '4GAX7YNCIJKO2VAED5LH5PQIYPUM7WCVKTQWEDMP2L24AXZT54LA====' }
243
+ let(:response_stub) do
244
+ {
245
+ requestId: '8105#1650074c30c',
246
+ result: [
247
+ {
248
+ id: 12_751,
249
+ marketoGUID: '12751',
250
+ leadId: 277,
251
+ activityDate: '2018-08-03T14:58:53Z',
252
+ activityTypeId: 37,
253
+ campaignId: 5227,
254
+ primaryAttributeValueId: 277,
255
+ primaryAttributeValue: 'Delete Me',
256
+ attributes: [
257
+ {
258
+ name: 'Campaign',
259
+ value: 'Run Action Delete Lead 2018-08-03 04:58:50 pm'
260
+ }
261
+ ]
262
+ }
263
+ ],
264
+ success: true,
265
+ nextPageToken: 'XQH6SLHODNIM7CY6MKJ6GAOR3JYOQXIN3THAHKYZXSOYN4HOPR2Q====',
266
+ moreResult: false
267
+ }
268
+ end
269
+ subject { client.get_deleted_leads(token) }
270
+
271
+ before do
272
+ stub_request(:get, "https://#{host}/rest/v1/activities/deletedleads.json")
273
+ .with(query: { nextPageToken: token })
274
+ .to_return(json_stub(response_stub))
275
+ end
276
+
277
+ it { is_expected.to eq(response_stub) }
278
+ end
240
279
  end
@@ -0,0 +1,273 @@
1
+ describe Mrkt::CrudAssetFolders do
2
+ include_context 'initialized client'
3
+
4
+ let(:response_folder_result) do
5
+ {
6
+ name: 'Test Folder Name',
7
+ description: 'Optional folder description',
8
+ createdAt: '2019-03-15T23:31:00Z+0000',
9
+ updatedAt: '2019-03-15T23:31:00Z+0000',
10
+ url: 'https://app-devlocal1.marketo.com/#ML0A1ZN75',
11
+ folderId: {
12
+ id: 75,
13
+ type: 'Folder'
14
+ },
15
+ folderType: 'Zone',
16
+ parent: {
17
+ id: 5,
18
+ type: 'Folder'
19
+ },
20
+ path: '/Lead Database/Default/Test Folder Name',
21
+ isArchive: false,
22
+ isSystem: false,
23
+ accessZoneId: 1,
24
+ workspace: 'Default',
25
+ id: 75
26
+ }
27
+ end
28
+
29
+ describe '#create_folder' do
30
+ subject { client.create_folder(name, parent, description: description) }
31
+
32
+ let(:name) { 'Test Folder Name' }
33
+ let(:parent) do
34
+ { id: 5, type: 'Folder' }
35
+ end
36
+ let(:description) { 'Optional folder description' }
37
+ let(:response_stub) do
38
+ {
39
+ requestId: 'bf7d#16983b1c7e3',
40
+ result: [
41
+ response_folder_result
42
+ ],
43
+ success: true,
44
+ errors: [],
45
+ warnings: []
46
+ }
47
+ end
48
+
49
+ let(:json_parent) { JSON.generate(parent) }
50
+ let(:request_body) do
51
+ {
52
+ name: name,
53
+ parent: json_parent,
54
+ description: description
55
+ }
56
+ end
57
+
58
+ before do
59
+ stub_request(:post, "https://#{host}/rest/asset/v1/folders.json")
60
+ .with(body: request_body)
61
+ .to_return(json_stub(response_stub))
62
+ end
63
+
64
+ it { is_expected.to eq(response_stub) }
65
+ end
66
+
67
+ describe '#get_folder_by_id' do
68
+ subject { client.get_folder_by_id(id, type: type) }
69
+
70
+ let(:id) { 77 }
71
+
72
+ before do
73
+ stub_request(:get, "https://#{host}/rest/asset/v1/folder/#{id}.json?type=#{type}")
74
+ .to_return(json_stub(response_stub))
75
+ end
76
+
77
+ context 'when a folder with the given id exists' do
78
+ let(:type) { 'Folder' }
79
+ let(:response_stub) do
80
+ {
81
+ requestId: '12756#16983bd0ee5',
82
+ result: [
83
+ response_folder_result
84
+ ],
85
+ success: true,
86
+ errors: [],
87
+ warnings: []
88
+ }
89
+ end
90
+
91
+ it { is_expected.to eq(response_stub) }
92
+ end
93
+
94
+ context 'when a folder with the given id does not exist' do
95
+ let(:type) { 'Folder' }
96
+ let(:response_stub) do
97
+ {
98
+ requestId: '18087#16983c04cdf',
99
+ success: true,
100
+ errors: [],
101
+ warnings: [
102
+ 'No assets found for the given search criteria.'
103
+ ]
104
+ }
105
+ end
106
+
107
+ it { is_expected.to eq(response_stub) }
108
+ end
109
+
110
+ context 'when the given type is not acceptable' do
111
+ let(:type) { 'Unacceptable' }
112
+ let(:response_stub) do
113
+ {
114
+ requestId: '12776#16983c25b1d',
115
+ success: false,
116
+ warnings: [],
117
+ errors: [
118
+ {
119
+ code: '1001',
120
+ message: "Invalid value 'Unacceptable'. Required of type 'FolderVariantType'"
121
+ }
122
+ ]
123
+ }
124
+ end
125
+
126
+ it 'should raise an Error' do
127
+ expect { subject }.to raise_error(Mrkt::Errors::TypeMismatch)
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '#get_folder_by_name' do
133
+ subject { client.get_folder_by_name(name, type: type, root: root, work_space: work_space) }
134
+
135
+ let(:name) { 'Test Folder Name' }
136
+ let(:type) { 'Folder' }
137
+ let(:root) do
138
+ {
139
+ id: 5,
140
+ type: 'Folder'
141
+ }
142
+ end
143
+ let(:work_space) { 'Default' }
144
+
145
+ let(:json_root) { JSON.generate(root) }
146
+ let(:request_query) { "name=#{name}&type=#{type}&root=#{json_root}&workSpace=#{work_space}" }
147
+
148
+ before do
149
+ stub_request(:get, "https://#{host}/rest/asset/v1/folder/byName.json?#{request_query}")
150
+ .to_return(json_stub(response_stub))
151
+ end
152
+
153
+ context 'when a folder with the given name exists' do
154
+ let(:response_stub) do
155
+ {
156
+ requestId: '541#16983d2f549',
157
+ result: [
158
+ response_folder_result
159
+ ],
160
+ success: true,
161
+ errors: [],
162
+ warnings: []
163
+ }
164
+ end
165
+
166
+ it { is_expected.to eq(response_stub) }
167
+ end
168
+
169
+ context 'when a folder with the given name does not exist' do
170
+ let(:response_stub) do
171
+ {
172
+ requestId: '105ad#16983d557c5',
173
+ success: true,
174
+ errors: [],
175
+ warnings: [
176
+ 'No assets found for the given search criteria.'
177
+ ]
178
+ }
179
+ end
180
+
181
+ it { is_expected.to eq(response_stub) }
182
+ end
183
+
184
+ context 'when the given work_space does not exist' do
185
+ let(:response_stub) do
186
+ {
187
+ requestId: '17af3#16983da0349',
188
+ success: false,
189
+ warnings: [],
190
+ errors: [
191
+ {
192
+ code: '611',
193
+ message: 'Unable to get folder'
194
+ }
195
+ ]
196
+ }
197
+ end
198
+
199
+ it 'should raise an Error' do
200
+ expect { subject }.to raise_error(Mrkt::Errors::System)
201
+ end
202
+ end
203
+
204
+ context 'when the given type is not acceptable' do
205
+ let(:response_stub) do
206
+ {
207
+ requestId: '2225#16983db0b71',
208
+ success: false,
209
+ warnings: [],
210
+ errors: [
211
+ {
212
+ code: '1003',
213
+ message: 'Invalid request. Please check and try again.'
214
+ }
215
+ ]
216
+ }
217
+ end
218
+
219
+ it 'should raise an Error' do
220
+ expect { subject }.to raise_error(Mrkt::Errors::UnspecifiedAction)
221
+ end
222
+ end
223
+ end
224
+
225
+ describe '#delete_folder' do
226
+ subject { client.delete_folder(id) }
227
+
228
+ let(:id) { 75 }
229
+
230
+ before do
231
+ stub_request(:post, "https://#{host}/rest/asset/v1/folder/#{id}/delete.json")
232
+ .to_return(json_stub(response_stub))
233
+ end
234
+
235
+ context 'when a folder with the given id exists' do
236
+ let(:response_stub) do
237
+ {
238
+ requestId: '1a1a#16983eaa800',
239
+ result: [
240
+ {
241
+ id: 75
242
+ }
243
+ ],
244
+ success: true,
245
+ errors: [],
246
+ warnings: []
247
+ }
248
+ end
249
+
250
+ it { is_expected.to eq(response_stub) }
251
+ end
252
+
253
+ context 'when a folder with the given id does not exist' do
254
+ let(:response_stub) do
255
+ {
256
+ requestId: '102ee#16983f320fb',
257
+ success: false,
258
+ warnings: [],
259
+ errors: [
260
+ {
261
+ code: '702',
262
+ message: '75 Folder not found'
263
+ }
264
+ ]
265
+ }
266
+ end
267
+
268
+ it 'should raise an Error' do
269
+ expect { subject }.to raise_error(Mrkt::Errors::RecordNotFound)
270
+ end
271
+ end
272
+ end
273
+ end