Commit 342f6f83 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Add `isShared` property, use `notify` when sending annotation activity

parent e7b406e9
import { isShared } from '../helpers/permissions';
import * as postMessageJsonRpc from '../util/postmessage-json-rpc'; import * as postMessageJsonRpc from '../util/postmessage-json-rpc';
/** /**
...@@ -45,16 +46,16 @@ export class AnnotationActivityService { ...@@ -45,16 +46,16 @@ export class AnnotationActivityService {
date: activityDate, date: activityDate,
annotation: { annotation: {
id: annotation.id, id: annotation.id,
isShared: isShared(annotation.permissions),
}, },
}; };
if (this._reportConfig.events.includes(eventType)) { if (this._reportConfig.events.includes(eventType)) {
postMessageJsonRpc.call( postMessageJsonRpc.notify(
this._rpc.targetFrame, this._rpc.targetFrame,
this._rpc.origin, this._rpc.origin,
this._reportConfig.method, this._reportConfig.method,
[eventType, data], [eventType, data]
3000
); );
} }
} }
......
...@@ -3,6 +3,7 @@ import * as fixtures from '../../test/annotation-fixtures'; ...@@ -3,6 +3,7 @@ import * as fixtures from '../../test/annotation-fixtures';
import { AnnotationActivityService, $imports } from '../annotation-activity'; import { AnnotationActivityService, $imports } from '../annotation-activity';
describe('AnnotationActivityService', () => { describe('AnnotationActivityService', () => {
let fakePermissions;
let fakePostMessageJsonRpc; let fakePostMessageJsonRpc;
let fakeRpcSettings; let fakeRpcSettings;
...@@ -10,8 +11,12 @@ describe('AnnotationActivityService', () => { ...@@ -10,8 +11,12 @@ describe('AnnotationActivityService', () => {
let fakeSettings; let fakeSettings;
beforeEach(() => { beforeEach(() => {
fakePermissions = {
isShared: sinon.stub().returns(true),
};
fakePostMessageJsonRpc = { fakePostMessageJsonRpc = {
call: sinon.stub(), notify: sinon.stub(),
}; };
fakeRpcSettings = { fakeRpcSettings = {
...@@ -30,6 +35,7 @@ describe('AnnotationActivityService', () => { ...@@ -30,6 +35,7 @@ describe('AnnotationActivityService', () => {
}; };
$imports.$mock({ $imports.$mock({
'../helpers/permissions': fakePermissions,
'../util/postmessage-json-rpc': fakePostMessageJsonRpc, '../util/postmessage-json-rpc': fakePostMessageJsonRpc,
}); });
}); });
...@@ -45,9 +51,9 @@ describe('AnnotationActivityService', () => { ...@@ -45,9 +51,9 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('update', annotation); svc.reportActivity('update', annotation);
assert.calledOnce(fakePostMessageJsonRpc.call); assert.calledOnce(fakePostMessageJsonRpc.notify);
assert.calledWith( assert.calledWith(
fakePostMessageJsonRpc.call, fakePostMessageJsonRpc.notify,
window, window,
'https://www.example.com', 'https://www.example.com',
'remoteMethod' 'remoteMethod'
...@@ -60,8 +66,8 @@ describe('AnnotationActivityService', () => { ...@@ -60,8 +66,8 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('update', annotation); svc.reportActivity('update', annotation);
const eventType = fakePostMessageJsonRpc.call.getCall(0).args[3][0]; const eventType = fakePostMessageJsonRpc.notify.getCall(0).args[3][0];
const data = fakePostMessageJsonRpc.call.getCall(0).args[3][1]; const data = fakePostMessageJsonRpc.notify.getCall(0).args[3][1];
assert.equal(eventType, 'update'); assert.equal(eventType, 'update');
assert.deepEqual(data, { assert.deepEqual(data, {
...@@ -70,6 +76,7 @@ describe('AnnotationActivityService', () => { ...@@ -70,6 +76,7 @@ describe('AnnotationActivityService', () => {
date: new Date(annotation.updated).toISOString(), date: new Date(annotation.updated).toISOString(),
annotation: { annotation: {
id: annotation.id, id: annotation.id,
isShared: true,
}, },
}); });
}); });
...@@ -82,7 +89,7 @@ describe('AnnotationActivityService', () => { ...@@ -82,7 +89,7 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('update', annotation); svc.reportActivity('update', annotation);
assert.notCalled(fakePostMessageJsonRpc.call); assert.notCalled(fakePostMessageJsonRpc.notify);
}); });
it('does not invoke remote activity method if reportActivity not configured', () => { it('does not invoke remote activity method if reportActivity not configured', () => {
...@@ -91,7 +98,7 @@ describe('AnnotationActivityService', () => { ...@@ -91,7 +98,7 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('update', annotation); svc.reportActivity('update', annotation);
assert.notCalled(fakePostMessageJsonRpc.call); assert.notCalled(fakePostMessageJsonRpc.notify);
}); });
it('does not invoke remote activity method if annotation event type is not one of configured events', () => { it('does not invoke remote activity method if annotation event type is not one of configured events', () => {
...@@ -100,7 +107,7 @@ describe('AnnotationActivityService', () => { ...@@ -100,7 +107,7 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('delete', annotation); svc.reportActivity('delete', annotation);
assert.notCalled(fakePostMessageJsonRpc.call); assert.notCalled(fakePostMessageJsonRpc.notify);
}); });
it('uses annotation created date as `date` for `create` events', () => { it('uses annotation created date as `date` for `create` events', () => {
...@@ -109,7 +116,7 @@ describe('AnnotationActivityService', () => { ...@@ -109,7 +116,7 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('create', annotation); svc.reportActivity('create', annotation);
const data = fakePostMessageJsonRpc.call.getCall(0).args[3][1]; const data = fakePostMessageJsonRpc.notify.getCall(0).args[3][1];
assert.equal(data.date, new Date(annotation.created).toISOString()); assert.equal(data.date, new Date(annotation.created).toISOString());
}); });
...@@ -120,7 +127,7 @@ describe('AnnotationActivityService', () => { ...@@ -120,7 +127,7 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('update', annotation); svc.reportActivity('update', annotation);
const data = fakePostMessageJsonRpc.call.getCall(0).args[3][1]; const data = fakePostMessageJsonRpc.notify.getCall(0).args[3][1];
assert.equal(data.date, new Date(annotation.updated).toISOString()); assert.equal(data.date, new Date(annotation.updated).toISOString());
}); });
...@@ -145,7 +152,7 @@ describe('AnnotationActivityService', () => { ...@@ -145,7 +152,7 @@ describe('AnnotationActivityService', () => {
svc.reportActivity('delete', annotation); svc.reportActivity('delete', annotation);
const data = fakePostMessageJsonRpc.call.getCall(0).args[3][1]; const data = fakePostMessageJsonRpc.notify.getCall(0).args[3][1];
assert.equal(data.date, now.toISOString()); assert.equal(data.date, now.toISOString());
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment