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

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

@ -1,7 +1,6 @@
import { expect } from 'chai';
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
@ -17,6 +16,7 @@ describe('libsession_wrapper_contacts ', () => {
const edSecretKey = from_hex(
'0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7'
);
const SessionUtilWrapper = require('session_util_wrapper');
// Initialize a brand new, empty config because we have no dump data to deal with.
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
const allContacts = contacts.getAll();
const session_ids = allContacts.map(m => m.id);
const nicknames = allContacts.map(m => m.nickname || '(N/A)');
const session_ids = allContacts.map((m: any) => m.id);
const nicknames = allContacts.map((m: any) => m.nickname || '(N/A)');
expect(session_ids.length).to.be.eq(2);
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;
const allContacts2 = contacts.getAll();
const session_ids2 = allContacts2.map(m => m.id);
const nicknames2 = allContacts2.map(m => m.nickname || '(N/A)');
const session_ids2 = allContacts2.map((m: any) => m.id);
const nicknames2 = allContacts2.map((m: any) => m.nickname || '(N/A)');
expect(session_ids2.length).to.be.eq(2);
expect(nicknames2.length).to.be.eq(2);
@ -186,6 +186,7 @@ describe('libsession_wrapper_contacts ', () => {
const edSecretKey = from_hex(
'0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7'
);
const SessionUtilWrapper = require('session_util_wrapper');
// Initialize a brand new, empty config because we have no dump data to deal with.
const contacts = new SessionUtilWrapper.ContactsConfigWrapper(edSecretKey, null);
@ -262,8 +263,8 @@ describe('libsession_wrapper_contacts ', () => {
expect(accepted).to.be.equal(1);
const allContacts2 = contacts.getAll();
const session_ids2 = allContacts2.map(m => m.id);
const nicknames2 = allContacts2.map(m => m.nickname || '(N/A)');
const session_ids2 = allContacts2.map((m: any) => m.id);
const nicknames2 = allContacts2.map((m: any) => m.nickname || '(N/A)');
expect(session_ids2.length).to.be.eq(2);
expect(nicknames2.length).to.be.eq(2);
@ -276,7 +277,7 @@ describe('libsession_wrapper_contacts ', () => {
const allContacts3 = contacts.getAll();
let deletions = 0;
let non_deletions = 0;
allContacts3.forEach(c => {
allContacts3.forEach((c: any) => {
if (c.id !== real_id) {
contacts.erase(c.id);
deletions++;

@ -3,7 +3,6 @@ import { expect } from 'chai';
import { stringToUint8Array } from '../../../../session/utils/String';
import { from_hex, to_hex } from 'libsodium-wrappers-sumo';
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
@ -19,6 +18,7 @@ describe('libsession_wrapper', () => {
const edSecretKey = from_hex(
'0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7'
);
const SessionUtilWrapper = require('session_util_wrapper');
// Initialize a brand new, empty config because we have no dump data to deal with.
const conf = new SessionUtilWrapper.UserConfigWrapper(edSecretKey, null);

@ -2,6 +2,7 @@ import { expect } from 'chai';
import Sinon from 'sinon';
import { Data } from '../../../../ts/data/data';
import { OpenGroupData } from '../../../data/opengroups';
import { ConfigDumpData } from '../../../data/configDump/configDump';
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
type DataFunction = typeof Data;
type OpenGroupDataFunction = typeof OpenGroupData;
type ConfigDumpDataFunction = typeof ConfigDumpData;
/**
* Stub a function inside Data.
@ -27,6 +29,10 @@ export function stubOpenGroupData<K extends keyof OpenGroupDataFunction>(fn: K):
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 {
return Sinon.stub(utilWorker, 'callUtilsWorker')
.withArgs(fnName as any)

Loading…
Cancel
Save