wix-hive-ruby 0.9.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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rubocop.yml +487 -0
- data/.yardopts +6 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +641 -0
- data/Rakefile +33 -0
- data/e2e/activities_api_spec.rb +334 -0
- data/e2e/contacts_api_spec.rb +364 -0
- data/e2e/e2e_helper.rb +35 -0
- data/e2e/insights_api_spec.rb +29 -0
- data/lib/hive/activities/contact/contact_create_activity.rb +109 -0
- data/lib/hive/activities/contact/contact_form_activity.rb +31 -0
- data/lib/hive/activities/conversion/conversion_complete_activity.rb +33 -0
- data/lib/hive/activities/e_commerce/purchase_activity.rb +150 -0
- data/lib/hive/activities/factory.rb +71 -0
- data/lib/hive/activities/hotels/hotels_cancel_activity.rb +52 -0
- data/lib/hive/activities/hotels/hotels_confirmation_activity.rb +133 -0
- data/lib/hive/activities/hotels/hotels_purchase_activity.rb +48 -0
- data/lib/hive/activities/hotels/hotels_purchase_failed_activity.rb +59 -0
- data/lib/hive/activities/messaging/send_activity.rb +75 -0
- data/lib/hive/activities/music/album_fan_activity.rb +36 -0
- data/lib/hive/activities/music/album_share_activity.rb +23 -0
- data/lib/hive/activities/music/track_lyrics_activity.rb +38 -0
- data/lib/hive/activities/music/track_play_activity.rb +31 -0
- data/lib/hive/activities/music/track_played_activity.rb +31 -0
- data/lib/hive/activities/music/track_share_activity.rb +32 -0
- data/lib/hive/activities/music/track_skipped_activity.rb +31 -0
- data/lib/hive/activities/scheduler/scheduler_appointment_activity.rb +73 -0
- data/lib/hive/activity.rb +60 -0
- data/lib/hive/activity_summary.rb +24 -0
- data/lib/hive/connect/request/wix_api_request.rb +92 -0
- data/lib/hive/connect/response/error.rb +88 -0
- data/lib/hive/connect/response/parse_json.rb +29 -0
- data/lib/hive/connect/response/raise_error.rb +17 -0
- data/lib/hive/connect/wix_client.rb +148 -0
- data/lib/hive/contact.rb +153 -0
- data/lib/hive/cursor.rb +48 -0
- data/lib/hive/errors.rb +5 -0
- data/lib/hive/extensions/hashie_hash.rb +16 -0
- data/lib/hive/extensions/hashie_validate_enum.rb +11 -0
- data/lib/hive/rest/activities.rb +55 -0
- data/lib/hive/rest/api.rb +13 -0
- data/lib/hive/rest/contacts.rb +114 -0
- data/lib/hive/rest/insights.rb +17 -0
- data/lib/hive/util.rb +20 -0
- data/lib/hive/version.rb +14 -0
- data/lib/wix-hive-ruby.rb +5 -0
- data/samples/quick_start.rb +49 -0
- data/spec/hive/activities/contact/contact_create_activity_spec.rb +25 -0
- data/spec/hive/activities/contact/contact_form_activity_spec.rb +9 -0
- data/spec/hive/activities/conversion/conversion_complete_activity_spec.rb +9 -0
- data/spec/hive/activities/e_commerce/purchase_activity_spec.rb +19 -0
- data/spec/hive/activities/factory_spec.rb +78 -0
- data/spec/hive/activities/hotels/hotels_cancel_activity_spec.rb +22 -0
- data/spec/hive/activities/hotels/hotels_confirmation_activity_spec.rb +34 -0
- data/spec/hive/activities/hotels/hotels_purchase_activity_spec.rb +22 -0
- data/spec/hive/activities/hotels/hotels_purchase_failed_activity_spec.rb +22 -0
- data/spec/hive/activities/messaging/send_activity_spec.rb +13 -0
- data/spec/hive/activities/scheduler/scheduler_appointment_activity_spec.rb +10 -0
- data/spec/hive/activity_spec.rb +18 -0
- data/spec/hive/connect/request/wix_api_request_spec.rb +54 -0
- data/spec/hive/connect/response/error_spec.rb +31 -0
- data/spec/hive/connect/response/parse_json_spec.rb +28 -0
- data/spec/hive/connect/response/raise_error_spec.rb +19 -0
- data/spec/hive/connect/wix_client_spec.rb +103 -0
- data/spec/hive/contact_spec.rb +148 -0
- data/spec/hive/cursor_spec.rb +75 -0
- data/spec/hive/hashie_hash_spec.rb +23 -0
- data/spec/hive/rest/activities_spec.rb +87 -0
- data/spec/hive/rest/contacts_spec.rb +225 -0
- data/spec/hive/rest/insights_spec.rb +17 -0
- data/spec/hive/util_spec.rb +36 -0
- data/spec/spec_helper.rb +59 -0
- data/wix-hive-ruby.gemspec +38 -0
- metadata +392 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'HOTELS_PURCHASE' do
|
4
|
+
guest = { total: 1, adults: 1, children: 0 }
|
5
|
+
|
6
|
+
day_ago = (Time.now - (60 * 60 * 24)).iso8601(3)
|
7
|
+
stay = { checkin: day_ago, checkout: Time.now.iso8601(3) }
|
8
|
+
|
9
|
+
invoice = {total: '1', subtotal: '1', currency: 'EUR'}
|
10
|
+
|
11
|
+
payment = {total: '1', subtotal: '1', currency: 'EUR', source: 'Cash'}
|
12
|
+
|
13
|
+
subject(:create_activity) {ACTIVITIES_FACTORY::HOTELS_PURCHASE.klass.new( source: 'GUEST', guests: guest, stay: stay, invoice: invoice, payment: payment ) }
|
14
|
+
|
15
|
+
it '.add_rate' do
|
16
|
+
create_activity.add_rate( date: 'date', subtotal: '1', total: '1', currency: 'EUR' )
|
17
|
+
end
|
18
|
+
|
19
|
+
it '.add_room' do
|
20
|
+
create_activity.add_room( maxOccupancy: 1 )
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'HOTELS_PURCHASE_FAILED' do
|
4
|
+
guest = { total: 1, adults: 1, children: 0 }
|
5
|
+
|
6
|
+
day_ago = (Time.now - (60 * 60 * 24)).iso8601(3)
|
7
|
+
stay = { checkin: day_ago, checkout: Time.now.iso8601(3) }
|
8
|
+
|
9
|
+
invoice = {total: '1', subtotal: '1', currency: 'EUR'}
|
10
|
+
|
11
|
+
payment = {total: '1', subtotal: '1', currency: 'EUR', source: 'Cash'}
|
12
|
+
|
13
|
+
subject(:create_activity) {ACTIVITIES_FACTORY::HOTELS_PURCHASE_FAILED.klass.new( source: 'GUEST', guests: guest, stay: stay, invoice: invoice, payment: payment ) }
|
14
|
+
|
15
|
+
it '.add_rate' do
|
16
|
+
create_activity.add_rate( date: 'date', subtotal: '1', total: '1', currency: 'EUR' )
|
17
|
+
end
|
18
|
+
|
19
|
+
it '.add_room' do
|
20
|
+
create_activity.add_room( maxOccupancy: 1 )
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'MESSAGING_SEND' do
|
4
|
+
recipient = {method: 'EMAIL', destination: {name: {first: 'Alex'}, target: 'localhost'}}
|
5
|
+
conversion_target = { conversionType: 'PAGEVIEW' }
|
6
|
+
subject(:create_activity) { ACTIVITIES_FACTORY::MESSAGING_SEND.klass.new( recipient: recipient, conversionTarget: conversion_target ) }
|
7
|
+
|
8
|
+
context 'MESSAGING_SEND::Metadata' do
|
9
|
+
it '.add_metadata' do
|
10
|
+
create_activity.conversionTarget.add_metadata( property: 'custom', value: 'value' )
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'SCHEDULER_APPOINTMENT' do
|
4
|
+
|
5
|
+
subject(:create_activity) { ACTIVITIES_FACTORY::SCHEDULER_APPOINTMENT.klass.new( title: 'title', description: 'desc' ) }
|
6
|
+
|
7
|
+
it '.add_attendee' do
|
8
|
+
create_activity.add_attendee( contactId: 'id' )
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Activity do
|
4
|
+
|
5
|
+
context 'transforms the activityInfo field' do
|
6
|
+
it 'with a handled activity type' do
|
7
|
+
activity = described_class.new({ activityType: 'music/album-fan', activityInfo: { album: { name: 'lala', id: '1' } } })
|
8
|
+
|
9
|
+
expect(activity.activityInfo).to be_a Hive::Activities::MUSIC_ALBUM_FAN.klass
|
10
|
+
end
|
11
|
+
it 'with a unknown activity type' do
|
12
|
+
activityInfo = { invalid: 'invalid' }
|
13
|
+
activity = described_class.new({activityType: 'invalid', activityInfo: activityInfo })
|
14
|
+
|
15
|
+
expect(activity.activityInfo).to eq activityInfo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Request::WixAPIRequest do
|
4
|
+
|
5
|
+
let(:client) { instance_double(Hive::Client, api_version: '1.0.0', secret_key: 's3cret', app_id: '1111111', instance_id: '11111') }
|
6
|
+
subject(:wix_request) { Hive::Request::WixAPIRequest.new(client, 'get', '/path') }
|
7
|
+
|
8
|
+
context '.perform' do
|
9
|
+
it 'calls the client wix_request method' do
|
10
|
+
allow(client).to receive(:wix_request).with(wix_request).and_return(instance_double(Faraday::Response, body: 'mock'))
|
11
|
+
wix_request.perform
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'appends the signature just before the request is performed' do
|
15
|
+
expect(wix_request.headers).not_to include 'x-wix-signature'
|
16
|
+
allow(client).to receive(:wix_request).with(wix_request).and_return(instance_double(Faraday::Response, body: 'mock'))
|
17
|
+
wix_request.perform
|
18
|
+
expect(wix_request.headers).to include 'x-wix-signature'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it '.perform_with_object' do
|
23
|
+
contact = double('Contact')
|
24
|
+
allow(client).to receive(:wix_request).with(wix_request).and_return(instance_double(Faraday::Response, body: 'mock'))
|
25
|
+
allow(contact).to receive(:new).with('mock')
|
26
|
+
wix_request.perform_with_object(contact)
|
27
|
+
end
|
28
|
+
|
29
|
+
it '.perform_with_cursor' do
|
30
|
+
contact = double('Contact')
|
31
|
+
allow(client).to receive(:wix_request).with(wix_request).and_return(instance_double(Faraday::Response, body: {results: [{mock: 'mock'}]}))
|
32
|
+
allow(contact).to receive(:new).with(mock: 'mock')
|
33
|
+
wix_request.perform_with_cursor(contact).is_a? Hive::Cursor
|
34
|
+
end
|
35
|
+
|
36
|
+
it '.options' do
|
37
|
+
local = wix_request.options
|
38
|
+
local[:params].merge!({another: 'param'})
|
39
|
+
|
40
|
+
expect(wix_request.options).not_to eq local
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'CaseSensitiveString' do
|
44
|
+
subject(:header) { Hive::Request::CaseSensitiveString.new('test') }
|
45
|
+
|
46
|
+
it 'returns the original string when you call downcase' do
|
47
|
+
header == header.downcase
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns the original string when you call capitalize' do
|
51
|
+
header == header.capitalize
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Response::Error do
|
4
|
+
body = {message: 'error', errorCode: 403, wixErrorCode: '-20302'}
|
5
|
+
let(:response) { double('Response') }
|
6
|
+
subject(:error) { described_class.new }
|
7
|
+
|
8
|
+
context '.from_response' do
|
9
|
+
it 'should return a empty error when no body is present' do
|
10
|
+
expect(response).to receive(:body).and_return(nil)
|
11
|
+
described_class.from_response(response)
|
12
|
+
end
|
13
|
+
it 'should put the body in the exception message unless its a hash' do
|
14
|
+
expect(response).to receive(:body).and_return('Error')
|
15
|
+
expect(described_class.from_response(response).error_message).to eq 'Error'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should put the body in the exception message unless its a hash' do
|
19
|
+
expect(response).to receive(:body).and_return(body)
|
20
|
+
error = described_class.from_response(response)
|
21
|
+
expect(error.error_message).to eq 'error'
|
22
|
+
expect(error.error_code).to eq 403
|
23
|
+
expect(error.wix_error_code).to eq '-20302'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it '.to_s' do
|
28
|
+
expect(response).to receive(:body).and_return(body)
|
29
|
+
expect(described_class.from_response(response).to_s).to eq "#{body[:message]}, errorCode: #{body[:errorCode]}, wixErrorCode: #{body[:wixErrorCode]}"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Response::ParseJson do
|
4
|
+
let(:response) { double('Response') }
|
5
|
+
subject(:parse_json) { described_class.new }
|
6
|
+
|
7
|
+
context '.on_complete' do
|
8
|
+
it 'returns a parsed response when response code is 200' do
|
9
|
+
expect(response).to receive(:body).and_return('{"mock":1}')
|
10
|
+
expect(response).to receive(:status).and_return(200)
|
11
|
+
expect(response).to receive(:body=).with(mock: 1)
|
12
|
+
parse_json.on_complete(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'leaves the body of the response unchanged if the response contains a unparsable response code' do
|
16
|
+
expect(response).to receive(:status).and_return(302)
|
17
|
+
parse_json.on_complete(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets the body to nil when its a whitespace' do
|
21
|
+
expect(response).to receive(:body).and_return(' ')
|
22
|
+
expect(response).to receive(:status).and_return(200)
|
23
|
+
expect(response).to receive(:body=).with(nil)
|
24
|
+
parse_json.on_complete(response)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Response::RaiseError do
|
4
|
+
let(:response) { double('Response') }
|
5
|
+
subject(:error_raiser) { described_class.new } # a better name would be raise_error but that's a namespace conflict.
|
6
|
+
|
7
|
+
context '.on_complete' do
|
8
|
+
it 'raises a Forbidden error when the response code is 403' do
|
9
|
+
expect(response).to receive(:status).and_return(403)
|
10
|
+
expect(response).to receive(:body).and_return({message: 'error', errorCode: 403, wixErrorCode: '-20302'})
|
11
|
+
expect{ error_raiser.on_complete(response) }.to raise_error(Hive::Response::Error::Forbidden)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns nil when the response code is 200' do
|
15
|
+
expect(response).to receive(:status).and_return(200)
|
16
|
+
expect(error_raiser.on_complete(response)).to be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Client do
|
4
|
+
|
5
|
+
let(:secret_key) { '21c9be40-fda0-4f01-8091-3a525db5dcb6' }
|
6
|
+
let(:app_id) { '13832826-96d2-70f0-7eb7-8e107a37f1d2' }
|
7
|
+
let(:instance_id) { '138328bd-0cde-04e3-d7be-8f5500e362e7' }
|
8
|
+
let(:instance) {'Ikf28Yx7zaY_J0jKyHwvumeSzKde0nuOn-N9ZqzXo_k.eyJpbnN0YW5jZUlkIjoiMTM4MzI4YmQtMGNkZS0wNGUzLWQ3YmUtOGY1NTAwZTM2MmU3Iiwic2lnbkRhdGUiOiIyMDE0LTA5LTA3VDA2OjU5OjEwLjk0NC0wNTowMCIsInVpZCI6ImExMWJiMzM0LWZkZDQtNDUxZi05YWU1LTM5M2U2MTJlNzZhYSIsInBlcm1pc3Npb25zIjoiT1dORVIiLCJpcEFuZFBvcnQiOiJudWxsL251bGwiLCJ2ZW5kb3JQcm9kdWN0SWQiOm51bGwsImRlbW9Nb2RlIjpmYWxzZX0'}
|
9
|
+
subject(:client) {
|
10
|
+
Hive::Client.new do |config|
|
11
|
+
config.secret_key = secret_key
|
12
|
+
config.app_id = app_id
|
13
|
+
config.instance_id = instance_id
|
14
|
+
end
|
15
|
+
}
|
16
|
+
|
17
|
+
context '.new' do
|
18
|
+
it 'when no secret key is provided' do
|
19
|
+
expect { Hive::Client.new }.to raise_error Hive::ConfigurationError
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'when no app id is provided' do
|
23
|
+
expect { Hive::Client.new( secret_key: secret_key) }.to raise_error Hive::ConfigurationError
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'when no instance id is provided' do
|
27
|
+
expect { Hive::Client.new( secret_key: secret_key, app_id: app_id) }.to raise_error Hive::ConfigurationError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '.parse_instance_data' do
|
32
|
+
it 'can parse the instance data' do
|
33
|
+
wixInstance = Hive::Client.parse_instance_data(instance, secret_key)
|
34
|
+
|
35
|
+
expect(instance_id).to eq wixInstance.instanceId
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'throws an error when the signatures dont match' do
|
39
|
+
expect { Hive::Client.parse_instance_data(instance, 'invalid') }.to raise_error Hive::SignatureError
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'throws an error when the invalid instance data is provided' do
|
43
|
+
expect { Hive::Client.parse_instance_data('invalid', secret_key) }.to raise_error Hive::SignatureError
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it '.headers= appends headers to the default ones' do
|
48
|
+
expect(client.headers = {custom: 'custom'})
|
49
|
+
stub_get('/v1/actions').with { |request| request.headers.key?('Custom') }.to_return(body: '', headers: {content_type: 'application/json; charset=utf-8'})
|
50
|
+
client.request('get', '/v1/actions')
|
51
|
+
expect(a_get('/v1/actions')).to have_been_made
|
52
|
+
end
|
53
|
+
|
54
|
+
context '.wix_request' do
|
55
|
+
it 'should perform a request given a wix_request' do
|
56
|
+
time_now = Time.now
|
57
|
+
allow(Time).to receive(:now) { time_now }
|
58
|
+
|
59
|
+
request = Hive::Request::WixAPIRequest.new(client, 'get', '/path')
|
60
|
+
allow(client).to receive(:request).with(request.verb, request.path, request.options).and_return(instance_double(Faraday::Response, body: 'mock'))
|
61
|
+
|
62
|
+
client.wix_request(request)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context '.request' do
|
67
|
+
it 'passes the custom headers to the request' do
|
68
|
+
custom_headers = {custom: '1', custom2: '2'}
|
69
|
+
stub_get('/v1/actions').with { |request| request.headers.update(custom_headers) }.to_return(body: '', headers: {content_type: 'application/json; charset=utf-8'})
|
70
|
+
client.request('get', '/v1/actions', headers: custom_headers)
|
71
|
+
expect(a_get('/v1/actions')).to have_been_made
|
72
|
+
end
|
73
|
+
it 'passes the parameters to the request' do
|
74
|
+
params = {a: 'a', b: 'b'}
|
75
|
+
stub_get('/v1/actions').with(query: params).to_return(body: '', headers: {content_type: 'application/json; charset=utf-8'})
|
76
|
+
client.request('get', '/v1/actions', params: params)
|
77
|
+
expect(a_get('/v1/actions').with(query: params)).to have_been_made
|
78
|
+
end
|
79
|
+
it 'catches and reraises Faraday timeout errors' do
|
80
|
+
allow(client).to receive(:connection).and_raise(Faraday::Error::TimeoutError.new('execution expired'))
|
81
|
+
expect { client.send(:request, :get, '/path') }.to raise_error(Hive::Response::Error::RequestTimeout)
|
82
|
+
end
|
83
|
+
it 'catches and reraises Timeout errors' do
|
84
|
+
allow(client).to receive(:connection).and_raise(Timeout::Error.new('execution expired'))
|
85
|
+
expect { client.send(:request, :get, '/path') }.to raise_error(Hive::Response::Error::RequestTimeout)
|
86
|
+
end
|
87
|
+
it 'catches and reraises Faraday client errors' do
|
88
|
+
allow(client).to receive(:connection).and_raise(Faraday::Error::ClientError.new('connection failed'))
|
89
|
+
expect { client.send(:request, :get, '/path') }.to raise_error(Hive::Response::Error)
|
90
|
+
end
|
91
|
+
it 'catches and reraises JSON::ParserError errors' do
|
92
|
+
allow(client).to receive(:connection).and_raise(JSON::ParserError.new('unexpected token'))
|
93
|
+
expect { client.send(:request, :get, '/path') }.to raise_error(Hive::Response::Error)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context '#connection' do
|
98
|
+
it 'looks like Faraday connection' do
|
99
|
+
expect(client.send(:connection)).to respond_to(:run_request)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Contact do
|
4
|
+
context '.add_email' do
|
5
|
+
before(:all) do
|
6
|
+
@contact = described_class.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should add an email to the Contact.emails array' do
|
10
|
+
@contact.add_email(email: 'john@wix.com', tag: 'work')
|
11
|
+
expect(@contact.emails.size).to eq 1
|
12
|
+
expect(@contact.emails.first.email).to be_truthy
|
13
|
+
expect(@contact.emails.first.tag).to be_truthy
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should append an email to the existing Contact.emails array' do
|
17
|
+
@contact.add_email(email: 'wayne@wix.com', tag: 'work')
|
18
|
+
expect(@contact.emails.size).to eq 2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '.add_phone' do
|
23
|
+
before(:all) do
|
24
|
+
@contact = described_class.new
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should add a phone to the Contact.phones array' do
|
28
|
+
@contact.add_phone(phone: '1234567', tag: 'work')
|
29
|
+
expect(@contact.phones.size).to eq 1
|
30
|
+
expect(@contact.phones.first.phone).to be_truthy
|
31
|
+
expect(@contact.phones.first.tag).to be_truthy
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should append a phone to the existing Contact.phones array' do
|
35
|
+
@contact.add_phone(phone: '7654321', tag: 'work')
|
36
|
+
expect(@contact.phones.size).to eq 2
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context '.add_phone' do
|
41
|
+
before(:all) do
|
42
|
+
@contact = described_class.new
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should add a phone to the Contact.phones array' do
|
46
|
+
@contact.add_phone(phone: '1234567', tag: 'work')
|
47
|
+
expect(@contact.phones.size).to eq 1
|
48
|
+
expect(@contact.phones.first.phone).to be_truthy
|
49
|
+
expect(@contact.phones.first.tag).to be_truthy
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should append a phone to the existing Contact.phones array' do
|
53
|
+
@contact.add_phone(phone: '7654321', tag: 'work')
|
54
|
+
expect(@contact.phones.size).to eq 2
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context '.add_address' do
|
59
|
+
before(:all) do
|
60
|
+
@contact = described_class.new
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should add a address to the Contact.addresses array' do
|
64
|
+
@contact.add_address(tag: 'home', address: '16th Mall St.')
|
65
|
+
expect(@contact.addresses.size).to eq 1
|
66
|
+
expect(@contact.addresses.first.tag).to be_truthy
|
67
|
+
expect(@contact.addresses.first.address).to be_truthy
|
68
|
+
expect(@contact.addresses.first.city).to be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should append a address to the existing Contact.addresses array' do
|
72
|
+
@contact.add_address(tag: 'work', address: '20208 Larimer St.')
|
73
|
+
expect(@contact.addresses.size).to eq 2
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context '.add_url' do
|
78
|
+
before(:all) do
|
79
|
+
@contact = described_class.new
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should add a url to the Contact.urls array' do
|
83
|
+
@contact.add_url(url: 'example.com', tag: 'blog')
|
84
|
+
expect(@contact.urls.size).to eq 1
|
85
|
+
expect(@contact.urls.first.url).to be_truthy
|
86
|
+
expect(@contact.urls.first.tag).to be_truthy
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should append a url to the existing Contact.urls array' do
|
90
|
+
@contact.add_url(url: 'example.com', tag: 'cv')
|
91
|
+
expect(@contact.urls.size).to eq 2
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context '.add_date' do
|
96
|
+
before(:all) do
|
97
|
+
@contact = described_class.new
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should add a date to the Contact.dates array' do
|
101
|
+
@contact.add_date(date: '2014-08-06T06:52:54.586Z', tag: 'first')
|
102
|
+
expect(@contact.dates.size).to eq 1
|
103
|
+
expect(@contact.dates.first.date).to be_truthy
|
104
|
+
expect(@contact.dates.first.date).to be_truthy
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should append a date to the existing Contact.dates array' do
|
108
|
+
@contact.add_date(date: '2014-08-06T06:52:54.586Z', tag: 'second')
|
109
|
+
expect(@contact.dates.size).to eq 2
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context '.add_note' do
|
114
|
+
before(:all) do
|
115
|
+
@contact = described_class.new
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should add a note to the Contact.notes array' do
|
119
|
+
@contact.add_note(modifiedAt: '2014-08-06T06:52:54.586Z', content: 'content')
|
120
|
+
expect(@contact.notes.size).to eq 1
|
121
|
+
expect(@contact.notes.first.modifiedAt).to be_truthy
|
122
|
+
expect(@contact.notes.first.content).to be_truthy
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should append a date to the existing Contact.dates array' do
|
126
|
+
@contact.add_note(modifiedAt: '2014-08-06T06:52:54.586Z', tag: 'content2')
|
127
|
+
expect(@contact.notes.size).to eq 2
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context '.add_custom' do
|
132
|
+
before(:all) do
|
133
|
+
@contact = described_class.new
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should add a custom to the Contact.custom array' do
|
137
|
+
@contact.add_custom(field: 'field', value: 'value')
|
138
|
+
expect(@contact.custom.size).to eq 1
|
139
|
+
expect(@contact.custom.first.field).to be_truthy
|
140
|
+
expect(@contact.custom.first.value).to be_truthy
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should append a date to the existing Contact.dates array' do
|
144
|
+
@contact.add_custom(field: 'field2', value: 'value2')
|
145
|
+
expect(@contact.custom.size).to eq 2
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|