Improvements to shared library components
This commit is contained in:
parent
2c59c71872
commit
d9e90e9ea8
15 changed files with 485 additions and 348 deletions
|
@ -8,12 +8,14 @@ import { ConversationModel } from '../models/conversations';
|
|||
import { ConversationAttributesType } from '../model-types.d';
|
||||
|
||||
import { routineProfileRefresh } from '../routineProfileRefresh';
|
||||
import * as getProfileStub from '../util/getProfile';
|
||||
|
||||
describe('routineProfileRefresh', () => {
|
||||
let sinonSandbox: sinon.SinonSandbox;
|
||||
|
||||
beforeEach(() => {
|
||||
sinonSandbox = sinon.createSandbox();
|
||||
sinonSandbox.stub(getProfileStub, 'getProfile').resolves(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -24,16 +26,17 @@ describe('routineProfileRefresh', () => {
|
|||
overrideAttributes: Partial<ConversationAttributesType> = {}
|
||||
): ConversationModel {
|
||||
const result = new ConversationModel({
|
||||
profileSharing: true,
|
||||
left: false,
|
||||
accessKey: uuid(),
|
||||
active_at: Date.now(),
|
||||
draftAttachments: [],
|
||||
draftBodyRanges: [],
|
||||
draftTimestamp: null,
|
||||
id: uuid(),
|
||||
inbox_position: 0,
|
||||
isPinned: false,
|
||||
lastMessageDeletedForEveryone: false,
|
||||
lastMessageStatus: 'sent',
|
||||
left: false,
|
||||
markedUnread: false,
|
||||
messageCount: 2,
|
||||
messageCountBeforeMessageRequests: 0,
|
||||
|
@ -42,18 +45,17 @@ describe('routineProfileRefresh', () => {
|
|||
profileAvatar: undefined,
|
||||
profileKeyCredential: uuid(),
|
||||
profileKeyVersion: '',
|
||||
profileSharing: true,
|
||||
quotedMessageId: null,
|
||||
sealedSender: 1,
|
||||
sentMessageCount: 1,
|
||||
sharedGroupNames: [],
|
||||
id: uuid(),
|
||||
type: 'private',
|
||||
timestamp: Date.now(),
|
||||
active_at: Date.now(),
|
||||
type: 'private',
|
||||
uuid: uuid(),
|
||||
version: 2,
|
||||
...overrideAttributes,
|
||||
});
|
||||
sinonSandbox.stub(result, 'getProfile').resolves(undefined);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -87,8 +89,7 @@ describe('routineProfileRefresh', () => {
|
|||
storage,
|
||||
});
|
||||
|
||||
sinon.assert.notCalled(conversation1.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(conversation2.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(getProfileStub.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(storage.put);
|
||||
});
|
||||
|
||||
|
@ -102,8 +103,16 @@ describe('routineProfileRefresh', () => {
|
|||
storage: makeStorage(),
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(conversation1.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledOnce(conversation2.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
conversation1.get('uuid'),
|
||||
conversation1.get('e164')
|
||||
);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
conversation2.get('uuid'),
|
||||
conversation2.get('e164')
|
||||
);
|
||||
});
|
||||
|
||||
it("skips conversations that haven't been active in 30 days", async () => {
|
||||
|
@ -119,9 +128,22 @@ describe('routineProfileRefresh', () => {
|
|||
storage: makeStorage(),
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(recentlyActive.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(inactive.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(neverActive.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledOnce(getProfileStub.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
recentlyActive.get('uuid'),
|
||||
recentlyActive.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
inactive.get('uuid'),
|
||||
inactive.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
neverActive.get('uuid'),
|
||||
neverActive.get('e164')
|
||||
);
|
||||
});
|
||||
|
||||
it('skips your own conversation', async () => {
|
||||
|
@ -134,7 +156,16 @@ describe('routineProfileRefresh', () => {
|
|||
storage: makeStorage(),
|
||||
});
|
||||
|
||||
sinon.assert.notCalled(me.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
notMe.get('uuid'),
|
||||
notMe.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
me.get('uuid'),
|
||||
me.get('e164')
|
||||
);
|
||||
});
|
||||
|
||||
it('skips conversations that were refreshed in the last hour', async () => {
|
||||
|
@ -149,8 +180,17 @@ describe('routineProfileRefresh', () => {
|
|||
storage: makeStorage(),
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(neverRefreshed.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(recentlyFetched.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledOnce(getProfileStub.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
neverRefreshed.get('uuid'),
|
||||
neverRefreshed.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
recentlyFetched.get('uuid'),
|
||||
recentlyFetched.get('e164')
|
||||
);
|
||||
});
|
||||
|
||||
it('"digs into" the members of an active group', async () => {
|
||||
|
@ -182,15 +222,31 @@ describe('routineProfileRefresh', () => {
|
|||
storage: makeStorage(),
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(privateConversation.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledOnce(
|
||||
recentlyActiveGroupMember.getProfile as sinon.SinonStub
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
privateConversation.get('uuid'),
|
||||
privateConversation.get('e164')
|
||||
);
|
||||
sinon.assert.calledOnce(inactiveGroupMember.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(
|
||||
memberWhoHasRecentlyRefreshed.getProfile as sinon.SinonStub
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
recentlyActiveGroupMember.get('uuid'),
|
||||
recentlyActiveGroupMember.get('e164')
|
||||
);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
inactiveGroupMember.get('uuid'),
|
||||
inactiveGroupMember.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
memberWhoHasRecentlyRefreshed.get('uuid'),
|
||||
memberWhoHasRecentlyRefreshed.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
groupConversation.get('uuid'),
|
||||
groupConversation.get('e164')
|
||||
);
|
||||
sinon.assert.notCalled(groupConversation.getProfile as sinon.SinonStub);
|
||||
});
|
||||
|
||||
it('only refreshes profiles for the 50 most recently active direct conversations', async () => {
|
||||
|
@ -235,11 +291,19 @@ describe('routineProfileRefresh', () => {
|
|||
});
|
||||
|
||||
[...activeConversations, ...inactiveGroupMembers].forEach(conversation => {
|
||||
sinon.assert.calledOnce(conversation.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
conversation.get('uuid'),
|
||||
conversation.get('e164')
|
||||
);
|
||||
});
|
||||
|
||||
[me, ...shouldNotBeIncluded].forEach(conversation => {
|
||||
sinon.assert.notCalled(conversation.getProfile as sinon.SinonStub);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
conversation.get('uuid'),
|
||||
conversation.get('e164')
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue