@@ -157,3 +157,63 @@ func TestPutGithubUser_emptyName(t *testing.T) {
157
157
t .Errorf ("PutGithubUser with empty name -> user.Name=%q, expected %q" , got , want )
158
158
}
159
159
}
160
+ func TestPutLinkedinbUser (t * testing.T ) {
161
+ s := setup (t )
162
+ defer teardown (t , s )
163
+
164
+ // We Put the LinkedIn user for the first time. The user does not exist so we
165
+ // expect Put to create the user.
166
+ llu := & petfind.LinkedinUser {
167
+ ID : "JANEDOE" ,
168
+ FirstName : "Jane" ,
169
+ LastName : "Doe" ,
170
+ }
171
+ got , err := s .PutLinkedinUser (llu )
172
+ if err != nil {
173
+ t .Fatal ("PutLinkedinUser for non existent user returned err:" , err )
174
+ }
175
+
176
+ // Save created time to check it was the same when we Put for a second time
177
+ // below.
178
+ created := got .Created
179
+ // Ignore time values.
180
+ got .Created = time.Time {}
181
+ got .Updated = time.Time {}
182
+
183
+ want := & petfind.User {
184
+ ID : 1 , // A newly created user should get ID 1 from Postgres.
185
+ LinkedinID : "JANEDOE" ,
186
+ Name : "Jane Doe" ,
187
+ }
188
+ if ! reflect .DeepEqual (got , want ) {
189
+ t .Fatalf ("PutLinkedinUser first run \n have: %#v\n want: %#v" , got , want )
190
+ }
191
+
192
+ // Attempt to Put again the github User. The LinkedIn user should have been
193
+ // already been created from the previous run and we now expect the values
194
+ // to be updated.
195
+ llu = & petfind.LinkedinUser {
196
+ ID : "JANEDOE" ,
197
+ FirstName : "Michaella" , // changed
198
+ LastName : "Neirou" , // changed
199
+ }
200
+ got , err = s .PutLinkedinUser (llu )
201
+ if err != nil {
202
+ t .Fatal ("PutLinkedinUser for existing user returned err:" , err )
203
+ }
204
+
205
+ // Ignore updated.
206
+ got .Updated = time.Time {}
207
+
208
+ want = & petfind.User {
209
+ ID : 1 , // ID stays the same as we are doing an update.
210
+ LinkedinID : "JANEDOE" ,
211
+ Name : "Michaella Neirou" ,
212
+ Created : created ,
213
+ }
214
+ // This time we expect the values to be updated but the created time should
215
+ // be the same as the first run.
216
+ if ! reflect .DeepEqual (got , want ) {
217
+ t .Fatalf ("PutLinkedinUser second run \n have: %#v\n want: %#v" , got , want )
218
+ }
219
+ }
0 commit comments