-
Notifications
You must be signed in to change notification settings - Fork 403
Expand file tree
/
Copy pathsearch_spec.rb
More file actions
255 lines (202 loc) · 8.12 KB
/
search_spec.rb
File metadata and controls
255 lines (202 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
require 'helper'
describe LinkedIn::Search do
# if you remove the related cassettes you will need to inform valid
# tokens and secrets to regenerate them
#
let(:client) do
consumer_token = ENV['LINKED_IN_CONSUMER_KEY'] || 'key'
consumer_secret = ENV['LINKED_IN_CONSUMER_SECRET'] || 'secret'
client = LinkedIn::Client.new(consumer_token, consumer_secret)
auth_token = ENV['LINKED_IN_AUTH_KEY'] || 'key'
auth_secret = ENV['LINKED_IN_AUTH_SECRET'] || 'secret'
client.authorize_from_access(auth_token, auth_secret)
client
end
describe "#search_company" do
describe "by keywords string parameter" do
use_vcr_cassette :record => :new_episodes
let(:results) do
client.search('apple', :company)
end
it "should perform a company search" do
results.companies.all.size.should == 10
results.companies.all.first.name.should == 'Apple'
results.companies.all.first.id.should == 162479
end
end
describe "by single keywords option" do
use_vcr_cassette :record => :new_episodes
let(:results) do
options = {:keywords => 'apple'}
client.search(options, :company)
end
it "should perform a company search" do
results.companies.all.size.should == 10
results.companies.all.first.name.should == 'Apple'
results.companies.all.first.id.should == 162479
end
end
describe "by single keywords option with facets to return" do
use_vcr_cassette :record => :new_episodes
let(:results) do
options = {:keywords => 'apple', :facets => [:industry]}
client.search(options, :company)
end
it "should return a facet" do
results.facets.all.first.buckets.all.first.name.should == 'Information Technology and Services'
end
end
describe "by single keywords option with pagination" do
use_vcr_cassette :record => :new_episodes
let(:results) do
options = {:keywords => 'apple', :start => 5, :count => 5}
client.search(options, :company)
end
it "should perform a search" do
results.companies.all.size.should == 5
results.companies.all.first.name.should == 'iSquare - Apple Authorized Distributor in Greece & Cyprus'
results.companies.all.first.id.should == 2135525
results.companies.all.last.name.should == 'Apple Crumble'
results.companies.all.last.id.should == 1049054
end
end
describe "by keywords options with fields" do
use_vcr_cassette :record => :new_episodes
let(:fields) { [{:companies => [:id, :name, :industries, :description, :specialties]}, :num_results] }
let(:options) { {:keywords => 'apple', :fields => fields} }
let(:results) do
client.search(options, 'company')
end
it "doesn't change the original options" do
original_options = options.dup
client.search(options, 'company')
options.should == original_options
end
it "should perform a search" do
results.companies.all.first.name.should == 'Apple'
results.companies.all.first.description.should == 'Apple designs Macs, the best personal computers in the world, along with OS X, iLife, iWork and professional software. Apple leads the digital music revolution with its iPods and iTunes online store. Apple has reinvented the mobile phone with its revolutionary iPhone and App Store, and is defining the future of mobile media and computing devices with iPad.'
results.companies.all.first.id.should == 162479
end
end
end
describe "#search" do
describe "by keywords string parameter" do
use_vcr_cassette :record => :new_episodes
let(:results) do
client.search('github')
end
it "should perform a search" do
results.people.all.size.should == 6
results.people.all.first.first_name.should == 'Shay'
results.people.all.first.last_name.should == 'Frendt'
results.people.all.first.id.should == 'ucXjUw4M9J'
end
end
describe "by single keywords option" do
use_vcr_cassette :record => :new_episodes
let(:results) do
client.search(:keywords => 'github')
end
it "should perform a search" do
results.people.all.size.should == 6
results.people.all.first.first_name.should == 'Shay'
results.people.all.first.last_name.should == 'Frendt'
results.people.all.first.id.should == 'ucXjUw4M9J'
end
end
describe "by single keywords option with pagination" do
use_vcr_cassette :record => :new_episodes
let(:results) do
client.search(:keywords => 'github', :start => 5, :count => 5)
end
it "should perform a search" do
results.people.all.size.should == 1
results.people.all.first.first_name.should == 'Satish'
results.people.all.first.last_name.should == 'Talim'
results.people.all.first.id.should == 'V1FPuGot-I'
end
end
describe "by first_name and last_name options" do
use_vcr_cassette :record => :new_episodes
let(:results) do
client.search(:first_name => 'Charles', :last_name => 'Garcia')
end
it "should perform a search" do
results.people.all.size.should == 10
results.people.all.first.first_name.should == 'Charles'
results.people.all.first.last_name.should == 'Garcia, CFA'
results.people.all.first.id.should == '2zk34r8TvA'
end
end
describe "by email address" do
use_vcr_cassette :record => :new_episodes
let(:results) do
fields = ['id']
client.profile(:email => 'email=yy@zz.com', :fields => fields)
end
it "should perform a people search" do
results._total.should == 1
output = results["values"]
output.each do |record|
record.id.should == '96GVfLeWjU'
record._key.should == 'email=yy@zz.com'
end
end
end
describe "by multiple email address" do
use_vcr_cassette :record => :new_episodes
let(:results) do
fields = ['id']
client.profile(:email => 'email=yy@zz.com,email=xx@yy.com', :fields => fields)
end
it "should perform a multi-email search" do
results._total.should == 2
output = results["values"]
output.count.should == 2
end
end
describe "email search returns unauthorized" do
use_vcr_cassette :record => :new_episodes
it "should raise an unauthorized error" do
fields = ['id']
expect {client.profile(:email => 'email=aa@bb.com', :fields => fields)}.to raise_error(LinkedIn::Errors::UnauthorizedError)
end
end
describe "by first_name and last_name options with fields" do
use_vcr_cassette :record => :new_episodes
let(:results) do
fields = [{:people => [:id, :first_name, :last_name, :public_profile_url, :picture_url]}, :num_results]
client.search(:first_name => 'Charles', :last_name => 'Garcia', :fields => fields)
end
it "should perform a search" do
first_person = results.people.all.first
results.people.all.size.should == 10
first_person.first_name.should == 'Charles'
first_person.last_name.should == 'Garcia, CFA'
first_person.id.should == '2zk34r8TvA'
first_person.picture_url.should be_nil
first_person.public_profile_url.should == 'http://www.linkedin.com/in/charlesgarcia'
end
end
describe "by company_name option" do
use_vcr_cassette :record => :new_episodes
let(:results) do
client.search(:company_name => 'IBM')
end
it "should perform a search" do
results.people.all.size.should == 6
results.people.all.first.first_name.should == 'Ryan'
results.people.all.first.last_name.should == 'Sue'
results.people.all.first.id.should == 'KHkgwBMaa-'
end
end
describe "#field_selector" do
it "should not modify the parameter object" do
fields = [{:people => [:id, :first_name]}]
fields_dup = fields.dup
client.send(:field_selector, fields)
fields.should eq fields_dup
end
end
end
end