Add view counters per album, recipient and browser, per-browser sign-out in admin, and photo hearts
This commit is contained in:
@@ -207,3 +207,47 @@ describe('public shares', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('activity and hearts', () => {
|
||||
it('counts views per share, recipient and browser, and lists browsers newest first', () => {
|
||||
store.upsertShare({ key: 'k1', slug: null, title: 'A', password: null }, T0)
|
||||
const ann = recipient()
|
||||
const older = store.createSession(ann.id, T0, 'Firefox')
|
||||
const newer = store.createSession(ann.id, T0, 'Chrome')
|
||||
store.recordView('k1', {}, T1)
|
||||
store.recordView('k1', { recipientId: ann.id, sessionToken: older, userAgent: 'Firefox 2' }, T1)
|
||||
store.recordView('k1', { recipientId: ann.id, sessionToken: newer }, T2)
|
||||
|
||||
expect(store.shareActivity().get('k1')).toEqual({ views: 3, anonymousViews: 1, lastViewedAt: T2, hearts: 0 })
|
||||
expect(store.recipientActivity(ann.id)).toEqual({ views: 2, lastViewedAt: T2 })
|
||||
const [first, second] = store.listSessions(ann.id)
|
||||
expect(first).toMatchObject({ views: 1, lastViewedAt: T2, userAgent: 'Chrome' })
|
||||
expect(second).toMatchObject({ views: 1, lastViewedAt: T1, userAgent: 'Firefox 2' })
|
||||
})
|
||||
|
||||
it('signs out one browser, only for its own recipient', () => {
|
||||
const ann = recipient()
|
||||
const bob = recipient('bob@example.com')
|
||||
store.createSession(ann.id, T0)
|
||||
const [session] = store.listSessions(ann.id)
|
||||
expect(store.deleteSessionById(bob.id, session.id)).toBe(false)
|
||||
expect(store.deleteSessionById(ann.id, session.id)).toBe(true)
|
||||
expect(store.listSessions(ann.id)).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('hearts once per recipient per photo, and counts them', () => {
|
||||
store.upsertShare({ key: 'k1', slug: null, title: 'A', password: null }, T0)
|
||||
const ann = recipient()
|
||||
const bob = recipient('bob@example.com')
|
||||
expect(store.setHeart('k1', 'p1', ann.id, true, T0)).toBe(1)
|
||||
expect(store.setHeart('k1', 'p1', ann.id, true, T0)).toBe(1)
|
||||
expect(store.setHeart('k1', 'p1', bob.id, true, T0)).toBe(2)
|
||||
expect(store.countHearts('k1')).toEqual({ p1: 2 })
|
||||
expect(store.heartedBy('k1', ann.id)).toEqual(['p1'])
|
||||
expect(store.shareActivity().get('k1')?.hearts).toBe(2)
|
||||
expect(store.setHeart('k1', 'p1', ann.id, false, T0)).toBe(1)
|
||||
// Deleting the share takes its hearts with it
|
||||
store.deleteShare('k1')
|
||||
expect(store.countHearts('k1')).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user