~nikwen/account-polld/directly-poll-with-new-account-data-fix

« back to all changes in this revision

Viewing changes to plugins/facebook/facebook_test.go

  • Committer: CI bot
  • Author(s): Guillermo Gonzalez
  • Date: 2014-08-28 23:40:45 UTC
  • mfrom: (66.1.15 account-polld)
  • Revision ID: ps-jenkins@lists.canonical.com-20140828234045-0uozk934yy4psuey
Initial version of inbox/messages polling. 
Approved by: Sergio Schvezov, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import (
20
20
        "bytes"
 
21
        "encoding/json"
21
22
        "io"
 
23
        "io/ioutil"
22
24
        "net/http"
 
25
        "os"
 
26
        "path"
 
27
        "path/filepath"
23
28
        "testing"
24
29
 
25
30
        . "launchpad.net/gocheck"
26
31
 
27
32
        "launchpad.net/account-polld/plugins"
 
33
        "launchpad.net/go-xdg/v0"
28
34
)
29
35
 
30
 
type S struct{}
31
 
 
32
 
func init() {
33
 
        Suite(S{})
34
 
}
35
 
 
36
 
func TestAll(t *testing.T) {
37
 
        TestingT(t)
38
 
}
 
36
type S struct {
 
37
        tempDir string
 
38
}
 
39
 
 
40
var _ = Suite(&S{})
 
41
 
 
42
func Test(t *testing.T) { TestingT(t) }
39
43
 
40
44
// closeWraper adds a dummy Close() method to a reader
41
45
type closeWrapper struct {
122
126
  ]
123
127
}
124
128
`
 
129
        largeNotificationsBody = `
 
130
{
 
131
  "data": [
 
132
    {
 
133
      "id": "notif_id",
 
134
      "from": {
 
135
        "id": "sender_id",
 
136
        "name": "Sender"
 
137
      },
 
138
      "to": {
 
139
        "id": "recipient_id",
 
140
        "name": "Recipient"
 
141
      },
 
142
      "created_time": "2014-07-12T09:51:57+0000",
 
143
      "updated_time": "2014-07-12T09:51:57+0000",
 
144
      "title": "Sender posted on your timeline: \"The message...\"",
 
145
      "link": "http://www.facebook.com/recipient/posts/id",
 
146
      "application": {
 
147
        "name": "Wall",
 
148
        "namespace": "wall",
 
149
        "id": "2719290516"
 
150
      },
 
151
      "unread": 1
 
152
    },
 
153
    {
 
154
      "id": "notif_1105650586_80600069",
 
155
      "from": {
 
156
        "id": "sender2_id",
 
157
        "name": "Sender2"
 
158
      },
 
159
      "to": {
 
160
        "id": "recipient_id",
 
161
        "name": "Recipient"
 
162
      },
 
163
      "created_time": "2014-07-08T06:17:52+0000",
 
164
      "updated_time": "2014-07-08T06:17:52+0000",
 
165
      "title": "Sender2's birthday was on July 7.",
 
166
      "link": "http://www.facebook.com/profile.php?id=xxx&ref=brem",
 
167
      "application": {
 
168
        "name": "Gifts",
 
169
        "namespace": "superkarma",
 
170
        "id": "329122197162272"
 
171
      },
 
172
      "unread": 1,
 
173
      "object": {
 
174
        "id": "sender2_id",
 
175
        "name": "Sender2"
 
176
      }
 
177
    },
 
178
    {
 
179
      "id": "notif_id_3",
 
180
      "from": {
 
181
        "id": "sender3_id",
 
182
        "name": "Sender3"
 
183
      },
 
184
      "to": {
 
185
        "id": "recipient_id",
 
186
        "name": "Recipient"
 
187
      },
 
188
      "created_time": "2014-07-12T09:51:57+0000",
 
189
      "updated_time": "2014-07-12T09:51:57+0000",
 
190
      "title": "Sender posted on your timeline: \"The message...\"",
 
191
      "link": "http://www.facebook.com/recipient/posts/id",
 
192
      "application": {
 
193
        "name": "Wall",
 
194
        "namespace": "wall",
 
195
        "id": "2719290516"
 
196
      },
 
197
      "unread": 1
 
198
    },
 
199
    {
 
200
      "id": "notif_id_4",
 
201
      "from": {
 
202
        "id": "sender4_id",
 
203
        "name": "Sender2"
 
204
      },
 
205
      "to": {
 
206
        "id": "recipient_id",
 
207
        "name": "Recipient"
 
208
      },
 
209
      "created_time": "2014-07-08T06:17:52+0000",
 
210
      "updated_time": "2014-07-08T06:17:52+0000",
 
211
      "title": "Sender2's birthday was on July 7.",
 
212
      "link": "http://www.facebook.com/profile.php?id=xxx&ref=brem",
 
213
      "application": {
 
214
        "name": "Gifts",
 
215
        "namespace": "superkarma",
 
216
        "id": "329122197162272"
 
217
      },
 
218
      "unread": 1
 
219
    }
 
220
  ],
 
221
  "paging": {
 
222
    "previous": "https://graph.facebook.com/v2.0/recipient/notifications?limit=5000&since=1405158717&__paging_token=enc_AewDzwIQmWOwPNO-36GaZsaJAog8l93HQ7uLEO-gp1Tb6KCiolXfzMCcGY2KjrJJsDJXdDmNJObICr5dewfMZgGs",
 
223
    "next": "https://graph.facebook.com/v2.0/recipient/notifications?limit=5000&until=1404705077&__paging_token=enc_Aewlhut5DQyhqtLNr7pLCMlYU012t4XY7FOt7cooz4wsWIWi-Jqz0a0IDnciJoeLu2vNNQkbtOpCmEmsVsN4hkM4"
 
224
  },
 
225
  "summary": [
 
226
  ]
 
227
}
 
228
`
 
229
 
 
230
        inboxBody = `
 
231
{
 
232
  "data": [
 
233
    {
 
234
      "unread": 1, 
 
235
      "unseen": 1, 
 
236
      "id": "445809168892281", 
 
237
      "updated_time": "2014-08-25T18:39:32+0000", 
 
238
      "comments": {
 
239
        "data": [
 
240
          {
 
241
            "id": "445809168892281_1408991972", 
 
242
            "from": {
 
243
              "id": "346217352202239", 
 
244
              "name": "Pollod Magnifico"
 
245
            }, 
 
246
            "message": "Hola mundo!", 
 
247
            "created_time": "2014-08-25T18:39:32+0000"
 
248
          }
 
249
        ], 
 
250
        "paging": {
 
251
          "previous": "https://graph.facebook.com/v2.0/445809168892281/comments?limit=1&since=1408991972&__paging_token=enc_Aew2kKJXEXzdm9k89DvLYz_y8nYxUbvElWcn6h_pKMRsoAPTPpkU7-AsGhkcYF6M1qbomOnFJf9ckL5J3hTltLFq", 
 
252
          "next": "https://graph.facebook.com/v2.0/445809168892281/comments?limit=1&until=1408991972&__paging_token=enc_Aewlixpk4h4Vq79-W1ixrTM6ONbsMUDrcj0vLABs34tbhWarfpQLf818uoASWNDEpQO4XEXh5HbgHpcCqnuNVEOR"
 
253
        }
 
254
      }
 
255
    },
 
256
    {
 
257
      "unread": 2, 
 
258
      "unseen": 1, 
 
259
      "id": "445809168892282", 
 
260
      "updated_time": "2014-08-25T18:39:32+0000", 
 
261
      "comments": {
 
262
        "data": [
 
263
          {
 
264
            "id": "445809168892282_1408991973", 
 
265
            "from": {
 
266
              "id": "346217352202239", 
 
267
              "name": "Pollitod Magnifico"
 
268
            }, 
 
269
            "message": "Hola!", 
 
270
            "created_time": "2014-08-25T18:39:32+0000"
 
271
          }
 
272
        ], 
 
273
        "paging": {
 
274
          "previous": "https://graph.facebook.com/v2.0/445809168892281/comments?limit=1&since=1408991972&__paging_token=enc_Aew2kKJXEXzdm9k89DvLYz_y8nYxUbvElWcn6h_pKMRsoAPTPpkU7-AsGhkcYF6M1qbomOnFJf9ckL5J3hTltLFq", 
 
275
          "next": "https://graph.facebook.com/v2.0/445809168892281/comments?limit=1&until=1408991972&__paging_token=enc_Aewlixpk4h4Vq79-W1ixrTM6ONbsMUDrcj0vLABs34tbhWarfpQLf818uoASWNDEpQO4XEXh5HbgHpcCqnuNVEOR"
 
276
        }
 
277
      }
 
278
    },
 
279
    {
 
280
      "unread": 2, 
 
281
      "unseen": 1, 
 
282
      "id": "445809168892283", 
 
283
      "updated_time": "2014-08-25T18:39:32+0000", 
 
284
      "comments": {
 
285
        "data": [
 
286
          {
 
287
            "id": "445809168892282_1408991973", 
 
288
            "from": {
 
289
              "id": "346217352202240", 
 
290
              "name": "A Friend"
 
291
            }, 
 
292
            "message": "mellon", 
 
293
            "created_time": "2014-08-25T18:39:32+0000"
 
294
          }
 
295
        ], 
 
296
        "paging": {
 
297
          "previous": "https://graph.facebook.com/v2.0/445809168892281/comments?limit=1&since=1408991972&__paging_token=enc_Aew2kKJXEXzdm9k89DvLYz_y8nYxUbvElWcn6h_pKMRsoAPTPpkU7-AsGhkcYF6M1qbomOnFJf9ckL5J3hTltLFq", 
 
298
          "next": "https://graph.facebook.com/v2.0/445809168892281/comments?limit=1&until=1408991972&__paging_token=enc_Aewlixpk4h4Vq79-W1ixrTM6ONbsMUDrcj0vLABs34tbhWarfpQLf818uoASWNDEpQO4XEXh5HbgHpcCqnuNVEOR"
 
299
        }
 
300
      }
 
301
    }
 
302
 
 
303
 
 
304
  ], 
 
305
  "paging": {
 
306
    "previous": "https://graph.facebook.com/v2.0/270128826512416/inbox?fields=unread,unseen,comments.limit(1)&limit=25&since=1408991972&__paging_token=enc_Aey99ACSOyZqN_7I-yWLnY8K3dqu4wVsx-Th3kMHMTMQ5VPbQRPgCQiJps0II1QAXDAVzHplqPS8yNgq8Zs_G2aK", 
 
307
    "next": "https://graph.facebook.com/v2.0/270128826512416/inbox?fields=unread,unseen,comments.limit(1)&limit=25&until=1408991972&__paging_token=enc_AewjHkk10NNjRCXJCoaP5hyf22kw-htwxsDaVOiLY-IiXxB99sKNGlfFFmkcG-VeMGUETI2agZGR_1IWP5W4vyPL"
 
308
  }, 
 
309
  "summary": {
 
310
    "unseen_count": 0, 
 
311
    "unread_count": 1, 
 
312
    "updated_time": "2014-08-25T19:05:49+0000"
 
313
  }
 
314
}
 
315
`
125
316
)
126
317
 
127
 
func (s S) TestParseNotifications(c *C) {
 
318
func (s *S) SetUpTest(c *C) {
 
319
        s.tempDir = c.MkDir()
 
320
        plugins.XdgDataFind = func(a string) (string, error) {
 
321
                return filepath.Join(s.tempDir, a), nil
 
322
        }
 
323
        plugins.XdgDataEnsure = func(a string) (string, error) {
 
324
                p := filepath.Join(s.tempDir, a)
 
325
                base := path.Dir(p)
 
326
                if _, err := os.Stat(base); err != nil {
 
327
                        os.MkdirAll(base, 0700)
 
328
                }
 
329
                return p, nil
 
330
        }
 
331
}
 
332
 
 
333
func (s *S) TearDownTest(c *C) {
 
334
        plugins.XdgDataFind = xdg.Data.Find
 
335
        plugins.XdgDataEnsure = xdg.Data.Find
 
336
}
 
337
 
 
338
func (s *S) TestParseNotifications(c *C) {
128
339
        resp := &http.Response{
129
340
                StatusCode: http.StatusOK,
130
341
                Body:       closeWrapper{bytes.NewReader([]byte(notificationsBody))},
137
348
        c.Check(messages[0].Notification.Card.Body, Equals, "Sender posted on your timeline: \"The message...\"")
138
349
        c.Check(messages[1].Notification.Card.Summary, Equals, "Sender2")
139
350
        c.Check(messages[1].Notification.Card.Body, Equals, "Sender2's birthday was on July 7.")
140
 
        c.Check(p.lastUpdate, Equals, timeStamp("2014-07-12T09:51:57+0000"))
141
 
}
142
 
 
143
 
func (s S) TestIgnoreOldNotifications(c *C) {
 
351
        c.Check(p.state.LastUpdate, Equals, timeStamp("2014-07-12T09:51:57+0000"))
 
352
}
 
353
 
 
354
func (s *S) TestParseLotsOfNotifications(c *C) {
 
355
        resp := &http.Response{
 
356
                StatusCode: http.StatusOK,
 
357
                Body:       closeWrapper{bytes.NewReader([]byte(largeNotificationsBody))},
 
358
        }
 
359
        p := &fbPlugin{}
 
360
        messages, err := p.parseResponse(resp)
 
361
        c.Assert(err, IsNil)
 
362
        c.Assert(len(messages), Equals, 3)
 
363
        c.Check(messages[0].Notification.Card.Summary, Equals, "Sender")
 
364
        c.Check(messages[0].Notification.Card.Body, Equals, "Sender posted on your timeline: \"The message...\"")
 
365
        c.Check(messages[1].Notification.Card.Summary, Equals, "Sender2")
 
366
        c.Check(messages[1].Notification.Card.Body, Equals, "Sender2's birthday was on July 7.")
 
367
        c.Check(messages[2].Notification.Card.Summary, Equals, "Multiple more notifications")
 
368
        c.Check(messages[2].Notification.Card.Body, Equals, "From Sender3, Sender2")
 
369
        c.Check(p.state.LastUpdate, Equals, timeStamp("2014-07-12T09:51:57+0000"))
 
370
}
 
371
 
 
372
func (s *S) TestIgnoreOldNotifications(c *C) {
144
373
        resp := &http.Response{
145
374
                StatusCode: http.StatusOK,
146
375
                Body:       closeWrapper{bytes.NewReader([]byte(notificationsBody))},
147
376
        }
148
 
        p := &fbPlugin{lastUpdate: "2014-07-08T06:17:52+0000"}
 
377
        p := &fbPlugin{state: fbState{LastUpdate: "2014-07-08T06:17:52+0000"}}
149
378
        messages, err := p.parseResponse(resp)
150
379
        c.Assert(err, IsNil)
151
380
        c.Assert(len(messages), Equals, 1)
152
381
        c.Check(messages[0].Notification.Card.Summary, Equals, "Sender")
153
382
        c.Check(messages[0].Notification.Card.Body, Equals, "Sender posted on your timeline: \"The message...\"")
154
 
        c.Check(p.lastUpdate, Equals, timeStamp("2014-07-12T09:51:57+0000"))
 
383
        c.Check(p.state.LastUpdate, Equals, timeStamp("2014-07-12T09:51:57+0000"))
155
384
}
156
385
 
157
 
func (s S) TestErrorResponse(c *C) {
 
386
func (s *S) TestParseResponseErrorResponse(c *C) {
158
387
        resp := &http.Response{
159
388
                StatusCode: http.StatusBadRequest,
160
389
                Body:       closeWrapper{bytes.NewReader([]byte(errorBody))},
168
397
        c.Check(graphErr.Code, Equals, 2500)
169
398
}
170
399
 
171
 
func (s S) TestTokenExpiredErrorResponse(c *C) {
 
400
func (s *S) TestDecodeResponseErrorResponse(c *C) {
 
401
        resp := &http.Response{
 
402
                StatusCode: http.StatusBadRequest,
 
403
                Body:       closeWrapper{bytes.NewReader([]byte(errorBody))},
 
404
        }
 
405
        p := &fbPlugin{}
 
406
        var result notificationDoc
 
407
        err := p.decodeResponse(resp, &result)
 
408
        c.Check(result, DeepEquals, notificationDoc{})
 
409
        c.Assert(err, Not(IsNil))
 
410
        graphErr := err.(*GraphError)
 
411
        c.Check(graphErr.Message, Equals, "Unknown path components: /xyz")
 
412
        c.Check(graphErr.Code, Equals, 2500)
 
413
}
 
414
 
 
415
func (s *S) TestDecodeResponseErrorResponseFails(c *C) {
 
416
        resp := &http.Response{
 
417
                StatusCode: http.StatusBadRequest,
 
418
                Body:       closeWrapper{bytes.NewReader([]byte("hola" + errorBody))},
 
419
        }
 
420
        p := &fbPlugin{}
 
421
        var result notificationDoc
 
422
        err := p.decodeResponse(resp, &result)
 
423
        c.Check(result, DeepEquals, notificationDoc{})
 
424
        c.Assert(err, NotNil)
 
425
        jsonErr := err.(*json.SyntaxError)
 
426
        c.Check(jsonErr.Offset, Equals, int64(1))
 
427
}
 
428
 
 
429
func (s *S) TestTokenExpiredErrorResponse(c *C) {
172
430
        resp := &http.Response{
173
431
                StatusCode: http.StatusBadRequest,
174
432
                Body:       closeWrapper{bytes.NewReader([]byte(tokenExpiredErrorBody))},
178
436
        c.Check(notifications, IsNil)
179
437
        c.Assert(err, Equals, plugins.ErrTokenExpired)
180
438
}
 
439
 
 
440
func (s *S) TestParseInbox(c *C) {
 
441
        resp := &http.Response{
 
442
                StatusCode: http.StatusOK,
 
443
                Body:       closeWrapper{bytes.NewReader([]byte(inboxBody))},
 
444
        }
 
445
        p := &fbPlugin{}
 
446
        messages, err := p.parseInboxResponse(resp)
 
447
        c.Assert(err, IsNil)
 
448
        c.Assert(len(messages), Equals, 3)
 
449
        c.Check(messages[0].Notification.Card.Summary, Equals, "Pollod Magnifico")
 
450
        c.Check(messages[0].Notification.Card.Body, Equals, "Hola mundo!")
 
451
        c.Check(messages[1].Notification.Card.Summary, Equals, "Pollitod Magnifico")
 
452
        c.Check(messages[1].Notification.Card.Body, Equals, "Hola!")
 
453
        c.Check(messages[2].Notification.Card.Summary, Equals, "Multiple more messages")
 
454
        c.Check(messages[2].Notification.Card.Body, Equals, "From Pollitod Magnifico, A Friend")
 
455
        c.Check(p.state.LastInboxUpdate, Equals, timeStamp("2014-08-25T18:39:32+0000"))
 
456
}
 
457
 
 
458
func (s *S) TestDecodeResponse(c *C) {
 
459
        resp := &http.Response{
 
460
                StatusCode: http.StatusOK,
 
461
                Body:       closeWrapper{bytes.NewReader([]byte(inboxBody))},
 
462
        }
 
463
        p := &fbPlugin{}
 
464
        var doc inboxDoc
 
465
        err := p.decodeResponse(resp, &doc)
 
466
        c.Check(err, IsNil)
 
467
        c.Check(len(doc.Data), Equals, 3)
 
468
}
 
469
 
 
470
func (s *S) TestDecodeResponseFails(c *C) {
 
471
        resp := &http.Response{
 
472
                StatusCode: http.StatusOK,
 
473
                Body:       closeWrapper{bytes.NewReader([]byte("hola" + inboxBody))},
 
474
        }
 
475
        p := &fbPlugin{}
 
476
        var doc inboxDoc
 
477
        err := p.decodeResponse(resp, &doc)
 
478
        c.Assert(err, NotNil)
 
479
        jsonErr := err.(*json.SyntaxError)
 
480
        c.Check(jsonErr.Offset, Equals, int64(1))
 
481
}
 
482
 
 
483
func (s *S) TestFilterNotifications(c *C) {
 
484
        resp := &http.Response{
 
485
                StatusCode: http.StatusOK,
 
486
                Body:       closeWrapper{bytes.NewReader([]byte(inboxBody))},
 
487
        }
 
488
        p := &fbPlugin{}
 
489
        var doc inboxDoc
 
490
        p.decodeResponse(resp, &doc)
 
491
        var state fbState
 
492
        notifications := p.filterNotifications(&doc, &state.LastInboxUpdate)
 
493
        c.Check(notifications, HasLen, 3)
 
494
        // check if the lastInboxUpdate is updated
 
495
        c.Check(state.LastInboxUpdate, Equals, timeStamp("2014-08-25T18:39:32+0000"))
 
496
}
 
497
 
 
498
func (s *S) TestBuildPushMessages(c *C) {
 
499
        resp := &http.Response{
 
500
                StatusCode: http.StatusOK,
 
501
                Body:       closeWrapper{bytes.NewReader([]byte(inboxBody))},
 
502
        }
 
503
        var state fbState
 
504
        p := &fbPlugin{state: state, accountId: 32}
 
505
        var doc inboxDoc
 
506
        p.decodeResponse(resp, &doc)
 
507
        notifications := p.filterNotifications(&doc, &p.state.LastInboxUpdate)
 
508
        pushMsgs := p.buildPushMessages(notifications, &doc, doc.size(), doc.size())
 
509
        c.Check(pushMsgs, HasLen, doc.size())
 
510
}
 
511
 
 
512
func (s *S) TestBuildPushMessagesConsolidate(c *C) {
 
513
        resp := &http.Response{
 
514
                StatusCode: http.StatusOK,
 
515
                Body:       closeWrapper{bytes.NewReader([]byte(inboxBody))},
 
516
        }
 
517
        var state fbState
 
518
        p := &fbPlugin{state: state, accountId: 32}
 
519
        var doc inboxDoc
 
520
        p.decodeResponse(resp, &doc)
 
521
        notifications := p.filterNotifications(&doc, &p.state.LastInboxUpdate)
 
522
        max := doc.size() - 2
 
523
        pushMsgs := p.buildPushMessages(notifications, &doc, max, max)
 
524
        // we should get max + 1 messages
 
525
        c.Check(pushMsgs, HasLen, max+1)
 
526
}
 
527
 
 
528
func (s *S) TestStateFromStorageInitialState(c *C) {
 
529
        state, err := stateFromStorage(32)
 
530
        c.Check(err, NotNil)
 
531
        c.Check(state.LastUpdate, Equals, timeStamp(""))
 
532
        c.Check(state.LastInboxUpdate, Equals, timeStamp(""))
 
533
}
 
534
 
 
535
func (s *S) TestStateFromStoragePersist(c *C) {
 
536
        filePath := filepath.Join(s.tempDir, "facebook.test/facebook-32.json")
 
537
        state, err := stateFromStorage(32)
 
538
        c.Check(err, NotNil)
 
539
        state.LastInboxUpdate = timeStamp("2014-08-25T18:39:32+0000")
 
540
        state.LastUpdate = timeStamp("2014-08-25T18:39:33+0000")
 
541
        err = state.persist(32)
 
542
        c.Check(err, IsNil)
 
543
        jsonData, err := ioutil.ReadFile(filePath)
 
544
        c.Check(err, IsNil)
 
545
        var data map[string]string
 
546
        json.Unmarshal(jsonData, &data)
 
547
        c.Check(data["last_inbox_update"], Equals, "2014-08-25T18:39:32+0000")
 
548
        c.Check(data["last_notification_update"], Equals, "2014-08-25T18:39:33+0000")
 
549
}
 
550
 
 
551
func (s *S) TestStateFromStoragePersistFails(c *C) {
 
552
        state := fbState{LastInboxUpdate: "2014-08-25T18:39:32+0000", LastUpdate: "2014-08-25T18:39:33+0000"}
 
553
        plugins.XdgDataEnsure = plugins.XdgDataFind
 
554
        err := state.persist(32)
 
555
        c.Check(err, NotNil)
 
556
}
 
557
 
 
558
func (s *S) TestStateFromStorage(c *C) {
 
559
        state := fbState{LastInboxUpdate: "2014-08-25T18:39:32+0000", LastUpdate: "2014-08-25T18:39:33+0000"}
 
560
        err := state.persist(32)
 
561
        c.Check(err, IsNil)
 
562
        newState, err := stateFromStorage(32)
 
563
        c.Check(err, IsNil)
 
564
        c.Check(newState.LastUpdate, Equals, timeStamp("2014-08-25T18:39:33+0000"))
 
565
        c.Check(newState.LastInboxUpdate, Equals, timeStamp("2014-08-25T18:39:32+0000"))
 
566
        // bad format
 
567
        state = fbState{LastInboxUpdate: "yesterday", LastUpdate: "2014-08-25T18:39:33+0000"}
 
568
        state.persist(32)
 
569
        _, err = stateFromStorage(32)
 
570
        c.Check(err, NotNil)
 
571
        state = fbState{LastInboxUpdate: "2014-08-25T18:39:33+0000", LastUpdate: "today"}
 
572
        state.persist(32)
 
573
        _, err = stateFromStorage(32)
 
574
        c.Check(err, NotNil)
 
575
}
 
576
 
 
577
func (s *S) TestNew(c *C) {
 
578
        state := fbState{LastInboxUpdate: "2014-08-25T18:39:32+0000", LastUpdate: "2014-08-25T18:39:33+0000"}
 
579
        state.persist(32)
 
580
        p := New(32)
 
581
        fb := p.(*fbPlugin)
 
582
        c.Check(fb.state, DeepEquals, state)
 
583
        // with bad format
 
584
        state = fbState{LastInboxUpdate: "hola", LastUpdate: "mundo"}
 
585
        state.persist(32)
 
586
        p = New(32)
 
587
        fb = p.(*fbPlugin)
 
588
        c.Check(fb.state, DeepEquals, state)
 
589
}
 
590
 
 
591
func (s *S) TestApplicationId(c *C) {
 
592
        expected := plugins.ApplicationId("com.ubuntu.developer.webapps.webapp-facebook_webapp-facebook")
 
593
        p := New(32)
 
594
        c.Check(p.ApplicationId(), Equals, expected)
 
595
}