intercom_export 0.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,226 @@
1
+ require 'spec_helper'
2
+ require 'intercom_export/differ/intercom_zendesk'
3
+ require 'intercom_export/model/zendesk_user'
4
+ require 'intercom_export/model/zendesk_ticket'
5
+
6
+
7
+ RSpec.describe IntercomExport::Differ::IntercomZendesk do
8
+
9
+ describe '#diff' do
10
+ context 'when comparing tickets' do
11
+ context 'when the remote object does not exist' do
12
+ it 'returns the commands' do
13
+ expect(
14
+ subject.diff(
15
+ IntercomExport::Model::IntercomConversation.new(
16
+ id: '4347072250',
17
+ created_at: 1458220933,
18
+ updated_at: 1458290738,
19
+ user: IntercomExport::Reference.new('someuser'),
20
+ assignee: IntercomExport::Reference.new('someadmin'),
21
+ open: false,
22
+ read: true,
23
+ tags: ['foo'],
24
+ conversation_message: {
25
+ id: '23964139',
26
+ subject: '<p>Register</p>',
27
+ body: '<p>Sorry but Ive got to go</p>',
28
+ author: IntercomExport::Reference.new('someuser'),
29
+ attachments: []
30
+ },
31
+ conversation_parts: [
32
+ {
33
+ id: '82997204',
34
+ part_type: 'close',
35
+ body: '<p>Hello<br>There</p><p>Help</p>',
36
+ created_at: 1458221859,
37
+ updated_at: 1458221859,
38
+ notified_at: 1458221859,
39
+ assigned_to: IntercomExport::Reference.new('someadmin'),
40
+ author: IntercomExport::Reference.new('someadmin'),
41
+ attachments: []
42
+ },
43
+ {
44
+ id: '83193198',
45
+ part_type: 'comment',
46
+ body: '<p>Please fix this</p>',
47
+ created_at: 1458241272,
48
+ updated_at: 1458241272,
49
+ notified_at: 1458241272,
50
+ assigned_to: nil,
51
+ author: IntercomExport::Reference.new('someuser'),
52
+ attachments: []
53
+ },
54
+ {
55
+ id: '83405663',
56
+ part_type: 'note',
57
+ body: '<p>Done</p>',
58
+ created_at: 1458290721,
59
+ updated_at: 1458290721,
60
+ notified_at: 1458290721,
61
+ assigned_to: nil,
62
+ author: IntercomExport::Reference.new('someadmin'),
63
+ attachments: []
64
+ }
65
+ ]
66
+ ),
67
+ nil
68
+ )
69
+ ).to eq([
70
+ {
71
+ name: :import_ticket,
72
+ details: {
73
+ external_id: 'intercom-conversation-4347072250',
74
+ tags: ['foo'],
75
+ status: 'solved',
76
+ requester_id: IntercomExport::Reference.new('someuser'),
77
+ assignee_id: IntercomExport::Reference.new('someadmin'),
78
+ subject: 'Register',
79
+ comments: [
80
+ {
81
+ author_id: IntercomExport::Reference.new('someuser'),
82
+ html_body: '<p>Sorry but Ive got to go</p>',
83
+ created_at: '2016-03-17T13:22:13Z'
84
+ },
85
+ {
86
+ author_id: IntercomExport::Reference.new('someadmin'),
87
+ value: "Hello\nThere\n\nHelp",
88
+ public: true,
89
+ created_at: '2016-03-17T13:37:39Z'
90
+ },
91
+ {
92
+ author_id: IntercomExport::Reference.new('someuser'),
93
+ value: 'Please fix this',
94
+ public: true,
95
+ created_at: '2016-03-17T19:01:12Z'
96
+ },
97
+ {
98
+ author_id: IntercomExport::Reference.new('someadmin'),
99
+ value: 'Done',
100
+ public: false,
101
+ created_at: '2016-03-18T08:45:21Z'
102
+ }
103
+ ],
104
+ created_at: '2016-03-17T13:22:13Z',
105
+ updated_at: '2016-03-18T08:45:38Z',
106
+ }
107
+ }
108
+ ])
109
+ end
110
+ end
111
+
112
+ context 'when the remote object exists' do
113
+ it 'returns no commands' do
114
+ expect(
115
+ subject.diff(
116
+ IntercomExport::Model::IntercomConversation.new,
117
+ IntercomExport::Model::ZendeskTicket.new
118
+ )
119
+ ).to eq([])
120
+ end
121
+ end
122
+ end
123
+
124
+ context 'when comparing users' do
125
+ context 'when the remote object does exist' do
126
+ it 'returns the correct commands' do
127
+ expect(
128
+ subject.diff(
129
+ IntercomExport::Model::IntercomUser.new(
130
+ id: 123, name: 'Theo', email: 'theo@example.com'
131
+ ),
132
+ IntercomExport::Model::ZendeskUser.new(
133
+ id: 999, name: 'Theo', email: 'theo@example.com'
134
+ )
135
+ )
136
+ ).to eq([
137
+ {
138
+ name: :reference,
139
+ details: 999,
140
+ reference: IntercomExport::Reference.new('intercom-user-123')
141
+ }
142
+ ])
143
+ end
144
+ end
145
+
146
+ context 'when the remote object does not exist' do
147
+ it 'returns the correct commands' do
148
+ expect(
149
+ subject.diff(
150
+ IntercomExport::Model::IntercomUser.new(
151
+ id: 123, name: 'Theo', email: 'theo@example.com'
152
+ ),
153
+ nil
154
+ )
155
+ ).to eq([
156
+ {
157
+ name: :import_user,
158
+ details: { external_id: 'intercom-user-123', name: 'Theo', email: 'theo@example.com' },
159
+ reference: IntercomExport::Reference.new('intercom-user-123')
160
+ }
161
+ ])
162
+ end
163
+
164
+ it 'copes with missing name the correct commands' do
165
+ expect(
166
+ subject.diff(
167
+ IntercomExport::Model::IntercomUser.new(
168
+ id: 1, name: nil, email: 't@example.com'
169
+ ),
170
+ nil
171
+ )
172
+ ).to eq([
173
+ {
174
+ name: :import_user,
175
+ details: { external_id: 'intercom-user-1', name: 't@example.com', email: 't@example.com' },
176
+ reference: IntercomExport::Reference.new('intercom-user-1')
177
+ }
178
+ ])
179
+ end
180
+ end
181
+ end
182
+
183
+ context 'when comparing admins' do
184
+ context 'when the remote object does exist' do
185
+ it 'returns the correct commands' do
186
+ expect(
187
+ subject.diff(
188
+ IntercomExport::Model::IntercomAdmin.new(
189
+ id: 123, name: 'Theo', email: 'theo@example.com'
190
+ ),
191
+ IntercomExport::Model::ZendeskUser.new(
192
+ id: 999, name: 'Theo', email: 'theo@example.com'
193
+ )
194
+ )
195
+ ).to eq([
196
+ {
197
+ name: :reference,
198
+ details: 999,
199
+ reference: IntercomExport::Reference.new('intercom-admin-123')
200
+ }
201
+ ])
202
+ end
203
+ end
204
+
205
+ context 'when the remote object does not exist' do
206
+ it 'returns the correct commands' do
207
+ expect(
208
+ subject.diff(
209
+ IntercomExport::Model::IntercomAdmin.new(
210
+ id: 123, name: 'Theo', email: 'theo@example.com'
211
+ ),
212
+ nil
213
+ )
214
+ ).to eq([
215
+ {
216
+ name: :import_user,
217
+ details: { external_id: 'intercom-admin-123', name: 'Theo', email: 'theo@example.com' },
218
+ reference: IntercomExport::Reference.new('intercom-admin-123')
219
+ }
220
+ ])
221
+ end
222
+ end
223
+ end
224
+
225
+ end
226
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+ require 'intercom_export/executor/zendesk'
3
+ require 'intercom_export/reference'
4
+
5
+ require 'zendesk_api'
6
+
7
+ RSpec.describe IntercomExport::Executor::Zendesk do
8
+
9
+ let(:zendesk_client) { double('zendesk client') }
10
+ let(:zendesk_collection_users) { double('ZendeskAPI::Collection') }
11
+ let(:zendesk_collection_tickets) { double('ZendeskAPI::Collection') }
12
+
13
+ subject { IntercomExport::Executor::Zendesk.new(zendesk_client) }
14
+
15
+ before do
16
+ allow(zendesk_client).to receive(:users).and_return(zendesk_collection_users)
17
+ allow(zendesk_client).to receive(:tickets).and_return(zendesk_collection_tickets)
18
+ end
19
+
20
+ describe '#call' do
21
+ context 'for users' do
22
+ it 'creates a new record' do
23
+ expect(zendesk_collection_users).to receive(:create!).with(
24
+ external_id: '123', name: 'Theo', email: 'foo@bar.com'
25
+ ).and_return(ZendeskAPI::User.new(zendesk_client, id: 999))
26
+
27
+ subject.call([{
28
+ name: :import_user,
29
+ details: { external_id: '123', name: 'Theo', email: 'foo@bar.com' },
30
+ reference: IntercomExport::Reference.new('123')
31
+ }])
32
+ end
33
+ end
34
+
35
+ context 'for tickets' do
36
+ it 'creates a new record' do
37
+ expect(zendesk_collection_users).to receive(:create!).with(
38
+ external_id: '123', name: 'Theo', email: 'foo@bar.com'
39
+ ).and_return(ZendeskAPI::User.new(zendesk_client, id: 999))
40
+
41
+ expect(zendesk_collection_tickets).to receive(:import!).with(
42
+ subject: 'This is totally broken',
43
+ requester_id: 999,
44
+ comments: [
45
+ { author_id: 999, value: 'This is a comment' }
46
+ ]
47
+ )
48
+
49
+ subject.call([
50
+ {
51
+ name: :import_user,
52
+ details: { external_id: '123', name: 'Theo', email: 'foo@bar.com' },
53
+ reference: IntercomExport::Reference.new('123')
54
+ },
55
+ {
56
+ name: :import_ticket,
57
+ details: {
58
+ subject: 'This is totally broken',
59
+ requester_id: IntercomExport::Reference.new('123'),
60
+ comments: [
61
+ { author_id: IntercomExport::Reference.new('123'), value: 'This is a comment' }
62
+ ]
63
+ }
64
+ }
65
+ ])
66
+ end
67
+ end
68
+
69
+ context 'for tickets with existing users' do
70
+ it 'creates a new record' do
71
+ expect(zendesk_collection_tickets).to receive(:import!).with(
72
+ subject: 'This is totally broken',
73
+ requester_id: 998,
74
+ comments: [
75
+ { author_id: 998, value: 'This is a comment' }
76
+ ]
77
+ )
78
+
79
+ subject.call([
80
+ {
81
+ name: :reference,
82
+ details: 998,
83
+ reference: IntercomExport::Reference.new('123')
84
+ },
85
+ {
86
+ name: :import_ticket,
87
+ details: {
88
+ subject: 'This is totally broken',
89
+ requester_id: IntercomExport::Reference.new('123'),
90
+ comments: [
91
+ { author_id: IntercomExport::Reference.new('123'), value: 'This is a comment' }
92
+ ]
93
+ }
94
+ }
95
+ ])
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'intercom_export/finder/intercom_zendesk'
3
+ require 'intercom_export/model/intercom_admin'
4
+ require 'intercom_export/model/intercom_user'
5
+ require 'intercom_export/model/intercom_conversation'
6
+
7
+ require 'zendesk_api'
8
+
9
+ RSpec.describe IntercomExport::Finder::IntercomZendesk do
10
+
11
+ let(:zendesk_client) { double(ZendeskAPI::Client) }
12
+
13
+ subject { IntercomExport::Finder::IntercomZendesk.new(zendesk_client) }
14
+
15
+ describe '#find' do
16
+ let(:zendesk_user_collection) { double(ZendeskAPI::Collection) }
17
+ let(:expected_zendesk_user) { ZendeskAPI::User.new(nil, id: 123) }
18
+ let(:expected_zendesk_ticket) { ZendeskAPI::Ticket.new(nil, id: 456) }
19
+
20
+ before do
21
+ allow(zendesk_client).to receive(:users).and_return(zendesk_user_collection)
22
+ end
23
+
24
+ context 'for an intercom admin' do
25
+ context 'when result exists' do
26
+ it 'looks up using their email' do
27
+ allow(zendesk_user_collection).to receive(:search).with(query: 'email:theo@example.com')
28
+ .and_return([expected_zendesk_user])
29
+
30
+ result = subject.find(IntercomExport::Model::IntercomAdmin.new('email' => 'theo@example.com'))
31
+ expect(result).to eq(IntercomExport::Model::ZendeskUser.new(id: 123))
32
+ end
33
+ end
34
+ context 'when result does not exist' do
35
+ it 'returns nil' do
36
+ allow(zendesk_user_collection).to receive(:search).with(query: 'email:theo@example.com')
37
+ .and_return([])
38
+
39
+ result = subject.find(IntercomExport::Model::IntercomAdmin.new('email' => 'theo@example.com'))
40
+ expect(result).to be_nil
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'for an intercom user' do
46
+ context 'when result exists' do
47
+ it 'looks up using their email' do
48
+ allow(zendesk_user_collection).to receive(:search).with(query: 'email:theo@example.com')
49
+ .and_return([expected_zendesk_user])
50
+
51
+ result = subject.find(IntercomExport::Model::IntercomUser.new('email' => 'theo@example.com'))
52
+ expect(result).to eq(IntercomExport::Model::ZendeskUser.new(id: 123))
53
+ end
54
+ end
55
+ context 'when result does not exist' do
56
+ it 'returns nil' do
57
+ allow(zendesk_user_collection).to receive(:search).with(query: 'email:theo@example.com')
58
+ .and_return([])
59
+
60
+ result = subject.find(IntercomExport::Model::IntercomUser.new('email' => 'theo@example.com'))
61
+ expect(result).to be_nil
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'for an intercom conversation' do
67
+ context 'when result exists' do
68
+ it 'looks up using the external id' do
69
+ allow(zendesk_client).to receive(:search).with(
70
+ query: 'type:ticket external_id:intercom-conversation-123'
71
+ ).and_return([expected_zendesk_ticket])
72
+
73
+ result = subject.find(IntercomExport::Model::IntercomConversation.new('id' => '123'))
74
+ expect(result).to eq(IntercomExport::Model::ZendeskTicket.new(id: 456))
75
+ end
76
+ end
77
+ context 'when result does not exist' do
78
+ it 'returns nil' do
79
+ allow(zendesk_client).to receive(:search).with(
80
+ query: 'type:ticket external_id:intercom-conversation-123'
81
+ ).and_return([])
82
+
83
+ result = subject.find(IntercomExport::Model::IntercomConversation.new('id' => '123'))
84
+ expect(result).to be_nil
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+ require 'intercom_export/splitter/intercom'
3
+
4
+ require 'intercom'
5
+
6
+ RSpec.describe IntercomExport::Splitter::Intercom do
7
+
8
+ let(:intercom_client) { instance_double(Intercom::Client) }
9
+ let(:intercom_admin_service) { instance_double(Intercom::Service::Admin) }
10
+ let(:intercom_user_service) { instance_double(Intercom::Service::User) }
11
+
12
+ subject { IntercomExport::Splitter::Intercom.new(intercom_client) }
13
+
14
+ describe '#split' do
15
+ before do
16
+ Intercom::Utils.define_lightweight_class('ConversationMessage')
17
+ Intercom::Utils.define_lightweight_class('ConversationPart')
18
+ Intercom::Utils.define_lightweight_class('NobodyAdmin')
19
+
20
+
21
+ allow(intercom_client).to receive(:admins).and_return(intercom_admin_service)
22
+ allow(intercom_client).to receive(:users).and_return(intercom_user_service)
23
+
24
+ allow(intercom_admin_service).to receive(:all).and_return(intercom_admins_full)
25
+ allow(intercom_user_service).to receive(:find).with(id: '56c186c20655c319400233a4').and_return(
26
+ intercom_user_full
27
+ )
28
+ end
29
+
30
+ let(:intercom_user_partial) do
31
+ Intercom::User.new(id: '56c186c20655c319400233a4')
32
+ end
33
+
34
+ let(:intercom_user_full) do
35
+ Intercom::User.new(id: '56c186c20655c319400233a4', name: 'Bob', email: 'bob@example.com')
36
+ end
37
+
38
+ let(:intercom_admin_partial) do
39
+ Intercom::Admin.new(id: '266817')
40
+ end
41
+
42
+ let(:intercom_admins_full) do
43
+ [
44
+ Intercom::Admin.new(id: 1, name: 'Wrong', email: 'wrong@example.com'),
45
+ Intercom::Admin.new(id: 266817, name: 'Theo', email: 'theo@example.com')
46
+ ]
47
+ end
48
+
49
+ let(:message) do
50
+ Intercom::Message.new(
51
+ author: intercom_user_partial,
52
+ body: 'I love this site',
53
+ id: '22294826',
54
+ subject: ''
55
+ )
56
+ end
57
+
58
+ let(:parts) do
59
+ [
60
+ Intercom::ConversationPart.new(
61
+ assigned_to: intercom_admin_partial,
62
+ attachments: [],
63
+ author: intercom_admin_partial,
64
+ body: 'Yes it is',
65
+ created_at: 1456784671,
66
+ id: '75615723',
67
+ notified_at: 1456784671,
68
+ part_type: 'close',
69
+ updated_at: 1456784671
70
+ ),
71
+ Intercom::ConversationPart.new(
72
+ assigned_to: nil,
73
+ attachments: [],
74
+ author: intercom_user_partial,
75
+ body: 'Thanks',
76
+ created_at: 1456829509,
77
+ id: '75809480',
78
+ notified_at: 1456829509,
79
+ part_type: 'close',
80
+ updated_at: 1456829509
81
+ ),
82
+ Intercom::ConversationPart.new(
83
+ assigned_to: nil,
84
+ attachments: [],
85
+ author: Intercom::User.new(id: '11111'),
86
+ body: nil,
87
+ created_at: 1458751031,
88
+ id: '85606347',
89
+ notified_at: 1458751031,
90
+ part_type: 'close',
91
+ updated_at: 1458751031
92
+ )
93
+ ]
94
+ end
95
+
96
+ let(:conversation) do
97
+ Intercom::Conversation.new(
98
+ id: '2016534877',
99
+ created_at: 1456761281,
100
+ updated_at: 1456829509,
101
+ user: intercom_user_partial,
102
+ assignee: Intercom::NobodyAdmin.new,
103
+ conversation_message: message,
104
+ open: true,
105
+ read: true,
106
+ conversation_parts: parts,
107
+ tags: []
108
+ )
109
+ end
110
+
111
+ it 'returns the parts in order they need to be recreated' do
112
+ expect(subject.split(conversation)).to eq([
113
+ IntercomExport::Model::IntercomAdmin.new(
114
+ id: '266817', name: 'Theo', email: 'theo@example.com'
115
+ ),
116
+ IntercomExport::Model::IntercomUser.new(
117
+ id: '56c186c20655c319400233a4', name: 'Bob', email: 'bob@example.com'
118
+ ),
119
+ IntercomExport::Model::IntercomConversation.new(
120
+ id: '2016534877',
121
+ created_at: 1456761281,
122
+ updated_at: 1456829509,
123
+ user: IntercomExport::Reference.new('intercom-user-56c186c20655c319400233a4'),
124
+ assignee: nil,
125
+ conversation_message: {
126
+ author: IntercomExport::Reference.new('intercom-user-56c186c20655c319400233a4'),
127
+ body: 'I love this site',
128
+ id: '22294826',
129
+ subject: ''
130
+ },
131
+ open: true,
132
+ read: true,
133
+ conversation_parts: [
134
+ {
135
+ assigned_to: IntercomExport::Reference.new('intercom-admin-266817'),
136
+ attachments: [],
137
+ author: IntercomExport::Reference.new('intercom-admin-266817'),
138
+ body: 'Yes it is',
139
+ created_at: 1456784671,
140
+ id: '75615723',
141
+ notified_at: 1456784671,
142
+ part_type: 'close',
143
+ updated_at: 1456784671
144
+ },
145
+ {
146
+ assigned_to: nil,
147
+ attachments: [],
148
+ author: IntercomExport::Reference.new('intercom-user-56c186c20655c319400233a4'),
149
+ body: 'Thanks',
150
+ created_at: 1456829509,
151
+ id: '75809480',
152
+ notified_at: 1456829509,
153
+ part_type: 'close',
154
+ updated_at: 1456829509
155
+ }
156
+ ],
157
+ tags: []
158
+ )
159
+ ])
160
+ end
161
+ end
162
+ end