test: fixed a few unit tests

pull/3052/head
Audric Ackermann 7 months ago
parent 3cd7d3272b
commit 487e418f73
No known key found for this signature in database

@ -98,6 +98,25 @@ export const ConversationMessageRequestButtons = () => {
return (
<MessageRequestContainer>
<InvitedToGroupControlMessage />
<ConversationBannerRow>
<SessionButton
onClick={() => {
void handleAcceptConversationRequest({ convoId: selectedConvoId });
}}
text={window.i18n('accept')}
dataTestId="accept-message-request"
/>
<SessionButton
buttonColor={SessionButtonColor.Danger}
text={window.i18n('delete')}
onClick={() => {
handleDeclineConversationRequest(selectedConvoId, selectedConvoId, convoOrigin);
}}
dataTestId="decline-message-request"
/>
</ConversationBannerRow>
<ConversationIncomingRequestExplanation />
{isOutgoingRequest ? (
<ConversationOutgoingRequestExplanation />
) : (
@ -116,24 +135,6 @@ export const ConversationMessageRequestButtons = () => {
{window.i18n('block')}
</StyledBlockUserText>
) : null}
<ConversationIncomingRequestExplanation />
<ConversationBannerRow>
<SessionButton
onClick={() => {
void handleAcceptConversationRequest({ convoId: selectedConvoId });
}}
text={window.i18n('accept')}
dataTestId="accept-message-request"
/>
<SessionButton
buttonColor={SessionButtonColor.Danger}
text={window.i18n('delete')}
onClick={() => {
handleDeclineConversationRequest(selectedConvoId, selectedConvoId, convoOrigin);
}}
dataTestId="decline-message-request"
/>
</ConversationBannerRow>
</>
)}
</MessageRequestContainer>

@ -27,7 +27,6 @@ import {
import { getSelectedConversationKey } from '../../state/selectors/selectedConversation';
import { SessionMessagesList } from './SessionMessagesList';
import { TypingBubble } from './TypingBubble';
import { ConversationMessageRequestButtons } from './MessageRequestButtons';
export type SessionMessageListProps = {
messageContainerRef: RefObject<HTMLDivElement>;
@ -126,7 +125,6 @@ class SessionMessagesListContainerInner extends Component<Props> {
key="typing-bubble"
/>
</StyledTypingBubbleContainer>
<ConversationMessageRequestButtons />
<ScrollToLoadedMessageContext.Provider value={this.scrollToLoadedMessage}>
<SessionMessagesList

@ -112,6 +112,12 @@ export const ConversationIncomingRequestExplanation = () => {
const showMsgRequestUI = selectedConversation && isIncomingMessageRequest;
const hasOutgoingMessages = useSelector(hasSelectedConversationOutgoingMessages);
const isGroupV2 = useSelectedIsGroupV2()
if (isGroupV2) {
return <GroupRequestExplanation />
}
if (!showMsgRequestUI || hasOutgoingMessages) {
return null;
}

@ -197,6 +197,7 @@ async function fetchLogFile(logFile: string) {
}
function logAtLevel(level: string, ...args: any) {
if (logger) {
// To avoid [Object object] in our log since console.log handles non-strings smoothly
const str = args.map((item: any) => {

@ -49,7 +49,6 @@ async function dropSnodeFromSnodePool(snodeEd25519: string) {
async function getRandomSnode(excludingEd25519Snode?: Array<string>): Promise<Snode> {
// make sure we have a few snodes in the pool excluding the one passed as args
const requiredCount = SnodePoolConstants.minSnodePoolCount + (excludingEd25519Snode?.length || 0);
debugger;
if (randomSnodePool.length < requiredCount) {
await SnodePool.getSnodePoolFromDBOrFetchFromSeed(excludingEd25519Snode?.length);
@ -67,7 +66,6 @@ async function getRandomSnode(excludingEd25519Snode?: Array<string>): Promise<Sn
if (!excludingEd25519Snode) {
const snodePicked = sample(randomSnodePool);
if (!snodePicked) {
console.warn('randomSnodePool', randomSnodePool);
throw new Error('getRandomSnode failed as sample returned none ');
}
return snodePicked;

@ -647,6 +647,10 @@ export class SwarmPolling {
})
);
if (!window.inboxStore?.getState().onionPaths.isOnline) {
window.inboxStore?.dispatch(updateIsOnline(true));
}
return results;
} catch (e) {
if (e.message === ERROR_CODE_NO_CONNECT) {

@ -117,10 +117,11 @@ const getDecryptedMediaUrl = async (
// window.log.debug('about to read and decrypt file :', url, path.isAbsolute(url));
try {
const absUrl = path.isAbsolute(url) ? url : getAbsoluteAttachmentPath(url);
const encryptedFileContent = await readFileContent(absUrl);
const encryptedFileContent = await DecryptedAttachmentsManager.readFileContent(absUrl);
const decryptedContent = await decryptAttachmentBufferRenderer(
encryptedFileContent.buffer
);
if (decryptedContent?.length) {
const arrayBuffer = decryptedContent.buffer;
const obj = makeObjectUrl(arrayBuffer, contentType);

@ -64,17 +64,12 @@ describe('DecryptedAttachmentsManager', () => {
TestUtils.stubCreateObjectUrl();
});
it('url starts with attachment path but is not already decrypted', () => {
expect(
DecryptedAttachmentsManager.getAlreadyDecryptedMediaUrl('/local/attachment/attachment1')
).to.be.eq(null);
});
it('url starts with attachment path but is not already decrypted', async () => {
expect(
DecryptedAttachmentsManager.getAlreadyDecryptedMediaUrl('/local/attachment/attachment1')
).to.be.eq(null);
expect(readFileContent.callCount).to.be.eq(0);
expect(decryptAttachmentBufferNode.callCount).to.be.eq(0);
expect(getItemById.callCount).to.be.eq(0);

@ -169,6 +169,7 @@ describe('libsession_metagroup', () => {
});
it('can add member by setting its promoted state, both ok and nok', () => {
metaGroupWrapper.memberConstructAndSet(member);
metaGroupWrapper.memberSetPromotionSent(member);
expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1);
expect(metaGroupWrapper.memberGetAll()[0]).to.be.deep.eq({

@ -15,7 +15,7 @@ import { UserSync } from '../../../../session/utils/job_runners/jobs/UserSyncJob
import { sleepFor } from '../../../../session/utils/Promise';
import { UserGroupsWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface';
import { TestUtils } from '../../../test-utils';
import { generateFakeSnodes, stubData } from '../../../test-utils/utils';
import { generateFakeSnodes, stubData, stubLibSessionWorker } from '../../../test-utils/utils';
import { ConversationTypeEnum } from '../../../../models/types';
import { ConvoHub } from '../../../../session/conversations';
import { SnodePool } from '../../../../session/apis/snode_api/snodePool';
@ -135,7 +135,7 @@ describe('SwarmPolling', () => {
});
});
describe('groupv3', () => {
describe('groupv2', () => {
it('returns ACTIVE for convo with less than two days old activeAt', () => {
const convo = ConvoHub.use().getOrCreate(
TestUtils.generateFakeClosedGroupV2PkStr(),
@ -189,36 +189,47 @@ describe('SwarmPolling', () => {
describe('pollForAllKeys', () => {
beforeEach(() => {
stubData('createOrUpdateItem').resolves();
});
afterEach(() => {
Sinon.restore();
});
it('does run for our pubkey even if activeAt is really old ', async () => {
stubLibSessionWorker([]);
const convo = ConvoHub.use().getOrCreate(ourNumber, ConversationTypeEnum.PRIVATE);
convo.set('active_at', Date.now() - 1000 * 3600 * 25);
await swarmPolling.start(true);
expect(pollOnceForKeySpy.callCount).to.eq(1);
expect(pollOnceForKeySpy.firstCall.args).to.deep.eq([ourPubkey, false, [0, 2, 3, 5, 4]]);
expect(pollOnceForKeySpy.firstCall.args[0]).to.deep.eq([ourPubkey.key, 'private']);
});
it('does run for our pubkey even if activeAt is recent ', async () => {
stubLibSessionWorker([]);
const convo = ConvoHub.use().getOrCreate(ourNumber, ConversationTypeEnum.PRIVATE);
convo.set('active_at', Date.now());
await swarmPolling.start(true);
expect(pollOnceForKeySpy.callCount).to.eq(1);
expect(pollOnceForKeySpy.firstCall.args).to.deep.eq([ourPubkey, false, [0, 2, 3, 5, 4]]);
expect(pollOnceForKeySpy.firstCall.args[0]).to.deep.eq([ourPubkey.key, 'private']);
});
describe('legacy group', () => {
it('does run for group pubkey on start no matter the recent timestamp', async () => {
const convo = ConvoHub.use().getOrCreate(
TestUtils.generateFakePubKeyStr(),
ConversationTypeEnum.GROUP
);
TestUtils.stubLibSessionWorker(undefined);
TestUtils.stubLibSessionWorker([]);
stubData('removeAllMessagesInConversation').resolves()
stubData('getLatestClosedGroupEncryptionKeyPair').resolves()
stubData('removeAllClosedGroupEncryptionKeyPairs').resolves()
stubData('removeConversation').resolves()
stubData('fetchConvoMemoryDetails').resolves()
convo.set('active_at', Date.now());
const groupConvoPubkey = PubKey.cast(convo.id as string);
swarmPolling.addGroupId(groupConvoPubkey);
@ -226,8 +237,8 @@ describe('SwarmPolling', () => {
// our pubkey will be polled for, hence the 2
expect(pollOnceForKeySpy.callCount).to.eq(2);
expect(pollOnceForKeySpy.firstCall.args).to.deep.eq([ourPubkey, false, [0, 2, 3, 5, 4]]);
expect(pollOnceForKeySpy.secondCall.args).to.deep.eq([groupConvoPubkey, true, [-10]]);
expect(pollOnceForKeySpy.firstCall.args[0]).to.deep.eq([ourPubkey.key, 'private']);
expect(pollOnceForKeySpy.secondCall.args[0]).to.deep.eq([groupConvoPubkey.key, 'private']);
});
it('does only poll from -10 for closed groups if HF >= 19.1 ', async () => {

@ -96,7 +96,7 @@ describe('OpenGroupUtils', () => {
serverPublicKey: '',
serverUrl: 'https://example.org',
})
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set');
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set');
});
it('throws if serverUrl is empty', () => {
@ -106,7 +106,7 @@ describe('OpenGroupUtils', () => {
serverPublicKey: '05123456789',
serverUrl: '',
})
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set');
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set');
});
it('throws if roomId is empty', () => {
@ -116,7 +116,7 @@ describe('OpenGroupUtils', () => {
serverPublicKey: '05123456789',
serverUrl: 'https://example.org',
})
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set');
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set');
});
it('throws if pubkey is null', () => {
expect(() =>
@ -125,7 +125,7 @@ describe('OpenGroupUtils', () => {
serverPublicKey: null as any,
serverUrl: 'https://example.org',
})
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set');
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set');
});
it('throws if serverUrl is null', () => {
@ -135,7 +135,7 @@ describe('OpenGroupUtils', () => {
serverPublicKey: '05123456789',
serverUrl: null as any,
})
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set');
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set');
});
it('throws if roomId is null', () => {
@ -145,7 +145,7 @@ describe('OpenGroupUtils', () => {
serverPublicKey: '05123456789',
serverUrl: 'https://example.org',
})
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set');
).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set');
});
});
});

@ -110,6 +110,12 @@ const development = window && window?.getEnvironment && window?.getEnvironment()
// The Bunyan API: https://github.com/trentm/node-bunyan#log-method-api
function logAtLevel(level: string, prefix: string, ...args: any) {
// when unit testing with mocha, we just log whatever we get to the console.log
if (typeof (global as any).it === 'function') {
(console as any)._log(prefix, now(), ...args);
return
}
if (prefix === 'DEBUG' && !window.sessionFeatureFlags.debug.debugLogging) {
return;
}

Loading…
Cancel
Save