chore: cleanedup the stubbing logic

pull/2620/head
Audric Ackermann 2 years ago
parent 68852a9e63
commit 2da2c95272

@ -2033,7 +2033,7 @@ function removeV2OpenGroupRoom(conversationId: string) {
const configDumpData: ConfigDumpDataNode = { const configDumpData: ConfigDumpDataNode = {
getConfigDumpByVariantAndPubkey: (variant: SharedConfigSupportedVariant, pubkey: string) => { getConfigDumpByVariantAndPubkey: (variant: SharedConfigSupportedVariant, pubkey: string) => {
const rows = assertGlobalInstance() const rows = assertGlobalInstance()
.prepare(`SELECT * from configDump WHERE variant = $variant AND pubkey = $pubkey;`) .prepare('SELECT * from configDump WHERE variant = $variant AND pubkey = $pubkey;')
.get({ .get({
pubkey, pubkey,
variant, variant,
@ -2049,7 +2049,7 @@ const configDumpData: ConfigDumpDataNode = {
getConfigDumpsByPubkey: (pubkey: string) => { getConfigDumpsByPubkey: (pubkey: string) => {
const rows = assertGlobalInstance() const rows = assertGlobalInstance()
.prepare(`SELECT * from configDump WHERE pubkey = $pubkey;`) .prepare('SELECT * from configDump WHERE pubkey = $pubkey;')
.get({ .get({
pubkey, pubkey,
}); });

@ -139,11 +139,7 @@ export class SwarmPolling {
// we always poll as often as possible for our pubkey // we always poll as often as possible for our pubkey
const ourPubkey = UserUtils.getOurPubKeyFromCache(); const ourPubkey = UserUtils.getOurPubKeyFromCache();
const directPromise = Promise.all([ const directPromise = Promise.all([
this.pollOnceForKey(ourPubkey, false, [ this.pollOnceForKey(ourPubkey, false, this.getUserNamespacesPolled()),
SnodeNamespaces.UserMessages,
SnodeNamespaces.UserProfile,
SnodeNamespaces.UserContacts,
]),
]).then(() => undefined); ]).then(() => undefined);
const now = Date.now(); const now = Date.now();
@ -410,6 +406,12 @@ export class SwarmPolling {
return newMessages; return newMessages;
} }
private getUserNamespacesPolled() {
return window.sessionFeatureFlags.useSharedUtilForUserConfig
? [SnodeNamespaces.UserMessages, SnodeNamespaces.UserProfile, SnodeNamespaces.UserContacts]
: [SnodeNamespaces.UserMessages];
}
private async updateLastHash({ private async updateLastHash({
edkey, edkey,
expiration, expiration,

@ -1,7 +1,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { from_hex, from_string } from 'libsodium-wrappers-sumo'; import { from_hex, from_string } from 'libsodium-wrappers-sumo';
import * as SessionUtilWrapper from 'session_util_wrapper';
// tslint:disable: chai-vague-errors no-unused-expression no-http-string no-octal-literal whitespace // tslint:disable: chai-vague-errors no-unused-expression no-http-string no-octal-literal whitespace
@ -17,6 +16,7 @@ describe('libsession_wrapper_contacts ', () => {
const edSecretKey = from_hex( const edSecretKey = from_hex(
'0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7' '0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7'
); );
const SessionUtilWrapper = require('session_util_wrapper');
// Initialize a brand new, empty config because we have no dump data to deal with. // Initialize a brand new, empty config because we have no dump data to deal with.
const contacts = new SessionUtilWrapper.ContactsConfigWrapper(edSecretKey, null); const contacts = new SessionUtilWrapper.ContactsConfigWrapper(edSecretKey, null);
@ -121,8 +121,8 @@ describe('libsession_wrapper_contacts ', () => {
// Iterate through and make sure we got everything we expected // Iterate through and make sure we got everything we expected
const allContacts = contacts.getAll(); const allContacts = contacts.getAll();
const session_ids = allContacts.map(m => m.id); const session_ids = allContacts.map((m: any) => m.id);
const nicknames = allContacts.map(m => m.nickname || '(N/A)'); const nicknames = allContacts.map((m: any) => m.nickname || '(N/A)');
expect(session_ids.length).to.be.eq(2); expect(session_ids.length).to.be.eq(2);
expect(session_ids).to.be.deep.eq([real_id, another_id]); expect(session_ids).to.be.deep.eq([real_id, another_id]);
@ -173,8 +173,8 @@ describe('libsession_wrapper_contacts ', () => {
expect(contacts2.needsPush()).to.be.false; expect(contacts2.needsPush()).to.be.false;
const allContacts2 = contacts.getAll(); const allContacts2 = contacts.getAll();
const session_ids2 = allContacts2.map(m => m.id); const session_ids2 = allContacts2.map((m: any) => m.id);
const nicknames2 = allContacts2.map(m => m.nickname || '(N/A)'); const nicknames2 = allContacts2.map((m: any) => m.nickname || '(N/A)');
expect(session_ids2.length).to.be.eq(2); expect(session_ids2.length).to.be.eq(2);
expect(nicknames2.length).to.be.eq(2); expect(nicknames2.length).to.be.eq(2);
@ -186,6 +186,7 @@ describe('libsession_wrapper_contacts ', () => {
const edSecretKey = from_hex( const edSecretKey = from_hex(
'0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7' '0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7'
); );
const SessionUtilWrapper = require('session_util_wrapper');
// Initialize a brand new, empty config because we have no dump data to deal with. // Initialize a brand new, empty config because we have no dump data to deal with.
const contacts = new SessionUtilWrapper.ContactsConfigWrapper(edSecretKey, null); const contacts = new SessionUtilWrapper.ContactsConfigWrapper(edSecretKey, null);
@ -262,8 +263,8 @@ describe('libsession_wrapper_contacts ', () => {
expect(accepted).to.be.equal(1); expect(accepted).to.be.equal(1);
const allContacts2 = contacts.getAll(); const allContacts2 = contacts.getAll();
const session_ids2 = allContacts2.map(m => m.id); const session_ids2 = allContacts2.map((m: any) => m.id);
const nicknames2 = allContacts2.map(m => m.nickname || '(N/A)'); const nicknames2 = allContacts2.map((m: any) => m.nickname || '(N/A)');
expect(session_ids2.length).to.be.eq(2); expect(session_ids2.length).to.be.eq(2);
expect(nicknames2.length).to.be.eq(2); expect(nicknames2.length).to.be.eq(2);
@ -276,7 +277,7 @@ describe('libsession_wrapper_contacts ', () => {
const allContacts3 = contacts.getAll(); const allContacts3 = contacts.getAll();
let deletions = 0; let deletions = 0;
let non_deletions = 0; let non_deletions = 0;
allContacts3.forEach(c => { allContacts3.forEach((c: any) => {
if (c.id !== real_id) { if (c.id !== real_id) {
contacts.erase(c.id); contacts.erase(c.id);
deletions++; deletions++;

@ -3,7 +3,6 @@ import { expect } from 'chai';
import { stringToUint8Array } from '../../../../session/utils/String'; import { stringToUint8Array } from '../../../../session/utils/String';
import { from_hex, to_hex } from 'libsodium-wrappers-sumo'; import { from_hex, to_hex } from 'libsodium-wrappers-sumo';
import { concatUInt8Array } from '../../../../session/crypto'; import { concatUInt8Array } from '../../../../session/crypto';
import * as SessionUtilWrapper from 'session_util_wrapper';
// tslint:disable: chai-vague-errors no-unused-expression no-http-string no-octal-literal whitespace // tslint:disable: chai-vague-errors no-unused-expression no-http-string no-octal-literal whitespace
@ -19,6 +18,7 @@ describe('libsession_wrapper', () => {
const edSecretKey = from_hex( const edSecretKey = from_hex(
'0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7' '0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7'
); );
const SessionUtilWrapper = require('session_util_wrapper');
// Initialize a brand new, empty config because we have no dump data to deal with. // Initialize a brand new, empty config because we have no dump data to deal with.
const conf = new SessionUtilWrapper.UserConfigWrapper(edSecretKey, null); const conf = new SessionUtilWrapper.UserConfigWrapper(edSecretKey, null);

@ -2,6 +2,7 @@ import { expect } from 'chai';
import Sinon from 'sinon'; import Sinon from 'sinon';
import { Data } from '../../../../ts/data/data'; import { Data } from '../../../../ts/data/data';
import { OpenGroupData } from '../../../data/opengroups'; import { OpenGroupData } from '../../../data/opengroups';
import { ConfigDumpData } from '../../../data/configDump/configDump';
import * as utilWorker from '../../../webworker/workers/browser/util_worker_interface'; import * as utilWorker from '../../../webworker/workers/browser/util_worker_interface';
@ -12,6 +13,7 @@ const globalAny: any = global;
// tslint:disable: no-require-imports no-var-requires // tslint:disable: no-require-imports no-var-requires
type DataFunction = typeof Data; type DataFunction = typeof Data;
type OpenGroupDataFunction = typeof OpenGroupData; type OpenGroupDataFunction = typeof OpenGroupData;
type ConfigDumpDataFunction = typeof ConfigDumpData;
/** /**
* Stub a function inside Data. * Stub a function inside Data.
@ -27,6 +29,10 @@ export function stubOpenGroupData<K extends keyof OpenGroupDataFunction>(fn: K):
return Sinon.stub(OpenGroupData, fn); return Sinon.stub(OpenGroupData, fn);
} }
export function stubConfigDumpData<K extends keyof ConfigDumpDataFunction>(fn: K): sinon.SinonStub {
return Sinon.stub(ConfigDumpData, fn);
}
export function stubUtilWorker(fnName: string, returnedValue: any): sinon.SinonStub { export function stubUtilWorker(fnName: string, returnedValue: any): sinon.SinonStub {
return Sinon.stub(utilWorker, 'callUtilsWorker') return Sinon.stub(utilWorker, 'callUtilsWorker')
.withArgs(fnName as any) .withArgs(fnName as any)

Loading…
Cancel
Save