testing stubs
							parent
							
								
									734debe841
								
							
						
					
					
						commit
						fb4c6fb387
					
				@ -1,60 +1,60 @@
 | 
			
		||||
import { expect } from 'chai';
 | 
			
		||||
 | 
			
		||||
import { ChatMessage, SessionResetMessage } from '../../../session/messages/outgoing';
 | 
			
		||||
import { TextEncoder } from 'util';
 | 
			
		||||
import { MessageUtils } from '../../../session/utils';
 | 
			
		||||
import { PendingMessageCache } from '../../../session/sending/PendingMessageCache';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Used for ExampleMessage
 | 
			
		||||
import { v4 as uuid } from 'uuid';
 | 
			
		||||
import { SignalService } from '../../../protobuf';
 | 
			
		||||
 | 
			
		||||
export class ExampleMessage extends ContentMessage {
 | 
			
		||||
  constructor() {
 | 
			
		||||
    super({
 | 
			
		||||
      timestamp: Math.floor(Math.random() * 10000000000000),
 | 
			
		||||
      identifier: uuid(),
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public ttl(): number {
 | 
			
		||||
    // throw new Error("Method not implemented.");
 | 
			
		||||
    return 5;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected contentProto(): SignalService.Content {
 | 
			
		||||
    // throw new Error("Method not implemented.");
 | 
			
		||||
 | 
			
		||||
    // TODO - get actual content
 | 
			
		||||
    const content = SignalService.Content.create();
 | 
			
		||||
 | 
			
		||||
    return content;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
describe('PendingMessageCache', () => {
 | 
			
		||||
    const pendingMessageCache = new PendingMessageCache();
 | 
			
		||||
 | 
			
		||||
    let sessionResetMessage: SessionResetMessage;
 | 
			
		||||
    const preKeyBundle = {
 | 
			
		||||
        deviceId: 123456,
 | 
			
		||||
        preKeyId: 654321,
 | 
			
		||||
        signedKeyId: 111111,
 | 
			
		||||
        preKey: new TextEncoder().encode('preKey'),
 | 
			
		||||
        signature: new TextEncoder().encode('signature'),
 | 
			
		||||
        signedKey: new TextEncoder().encode('signedKey'),
 | 
			
		||||
        identityKey: new TextEncoder().encode('identityKey'),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // queue with session reset message.
 | 
			
		||||
    // should return undefined
 | 
			
		||||
    // TOOD: Send me to MESSAGE QUEUE TEST
 | 
			
		||||
    it('queue session reset message', () => {
 | 
			
		||||
      const timestamp = Date.now();
 | 
			
		||||
      sessionResetMessage = new SessionResetMessage({timestamp, preKeyBundle});
 | 
			
		||||
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
// import { expect } from 'chai';
 | 
			
		||||
 | 
			
		||||
// import { ChatMessage, SessionResetMessage } from '../../../session/messages/outgoing';
 | 
			
		||||
// import { TextEncoder } from 'util';
 | 
			
		||||
// import { MessageUtils } from '../../../session/utils';
 | 
			
		||||
// import { PendingMessageCache } from '../../../session/sending/PendingMessageCache';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// // Used for ExampleMessage
 | 
			
		||||
// import { v4 as uuid } from 'uuid';
 | 
			
		||||
// import { SignalService } from '../../../protobuf';
 | 
			
		||||
 | 
			
		||||
// export class ExampleMessage extends ContentMessage {
 | 
			
		||||
//   constructor() {
 | 
			
		||||
//     super({
 | 
			
		||||
//       timestamp: Math.floor(Math.random() * 10000000000000),
 | 
			
		||||
//       identifier: uuid(),
 | 
			
		||||
//     });
 | 
			
		||||
//   }
 | 
			
		||||
 | 
			
		||||
//   public ttl(): number {
 | 
			
		||||
//     // throw new Error("Method not implemented.");
 | 
			
		||||
//     return 5;
 | 
			
		||||
//   }
 | 
			
		||||
 | 
			
		||||
//   protected contentProto(): SignalService.Content {
 | 
			
		||||
//     // throw new Error("Method not implemented.");
 | 
			
		||||
 | 
			
		||||
//     // TODO - get actual content
 | 
			
		||||
//     const content = SignalService.Content.create();
 | 
			
		||||
 | 
			
		||||
//     return content;
 | 
			
		||||
//   }
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// describe('PendingMessageCache', () => {
 | 
			
		||||
//     const pendingMessageCache = new PendingMessageCache();
 | 
			
		||||
 | 
			
		||||
//     let sessionResetMessage: SessionResetMessage;
 | 
			
		||||
//     const preKeyBundle = {
 | 
			
		||||
//         deviceId: 123456,
 | 
			
		||||
//         preKeyId: 654321,
 | 
			
		||||
//         signedKeyId: 111111,
 | 
			
		||||
//         preKey: new TextEncoder().encode('preKey'),
 | 
			
		||||
//         signature: new TextEncoder().encode('signature'),
 | 
			
		||||
//         signedKey: new TextEncoder().encode('signedKey'),
 | 
			
		||||
//         identityKey: new TextEncoder().encode('identityKey'),
 | 
			
		||||
//     };
 | 
			
		||||
 | 
			
		||||
//     // queue with session reset message.
 | 
			
		||||
//     // should return undefined
 | 
			
		||||
//     // TOOD: Send me to MESSAGE QUEUE TEST
 | 
			
		||||
//     it('queue session reset message', () => {
 | 
			
		||||
//       const timestamp = Date.now();
 | 
			
		||||
//       sessionResetMessage = new SessionResetMessage({timestamp, preKeyBundle});
 | 
			
		||||
 | 
			
		||||
//     });
 | 
			
		||||
 | 
			
		||||
// });
 | 
			
		||||
 | 
			
		||||
@ -1,74 +0,0 @@
 | 
			
		||||
import { expect, should } from 'chai';
 | 
			
		||||
import { SignalService } from '../../../protobuf';
 | 
			
		||||
import { ChatMessage } from '../../../session/messages/outgoing';
 | 
			
		||||
import { RawMessage } from '../../../session/types/RawMessage';
 | 
			
		||||
import { MessageUtils, PubKey, PubKeyType } from '../../../session/utils';
 | 
			
		||||
 | 
			
		||||
describe('MessageUtils', () => {
 | 
			
		||||
  it('can convert to RawMessage', () => {
 | 
			
		||||
    // TOOD: MOVE ME TO MESSAGE UTILS TEST
 | 
			
		||||
    const pubkey =
 | 
			
		||||
      '0582fe8822c684999663cc6636148328fbd47c0836814c118af4e326bb4f0e1000';
 | 
			
		||||
    const messageText = 'This is some message content';
 | 
			
		||||
 | 
			
		||||
    const isRawMessage = (object: any): object is RawMessage => {
 | 
			
		||||
      return (
 | 
			
		||||
        'identifier' in object &&
 | 
			
		||||
        'plainTextBuffer' in object &&
 | 
			
		||||
        'timestamp' in object &&
 | 
			
		||||
        'device' in object &&
 | 
			
		||||
        'ttl' in object &&
 | 
			
		||||
        'encryption' in object
 | 
			
		||||
      );
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const message = new ChatMessage({
 | 
			
		||||
      body: messageText,
 | 
			
		||||
      identifier: '1234567890',
 | 
			
		||||
      timestamp: Date.now(),
 | 
			
		||||
      attachments: undefined,
 | 
			
		||||
      quote: undefined,
 | 
			
		||||
      expireTimer: undefined,
 | 
			
		||||
      lokiProfile: undefined,
 | 
			
		||||
      preview: undefined,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // Explicitly check that it's a RawMessage
 | 
			
		||||
    const rawMessage = MessageUtils.toRawMessage(pubkey, message);
 | 
			
		||||
    expect(isRawMessage(rawMessage)).to.be.equal(true);
 | 
			
		||||
 | 
			
		||||
    // console.log('[vince] isRawMessage(rawMessage):', isRawMessage(rawMessage));
 | 
			
		||||
 | 
			
		||||
    // Check plaintext
 | 
			
		||||
    const plainText = message.plainTextBuffer();
 | 
			
		||||
    const decoded = SignalService.Content.decode(plainText);
 | 
			
		||||
    expect(decoded.dataMessage?.body).to.be.equal(messageText);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  // Pubkeys
 | 
			
		||||
  it('can create new valid pubkey', () => {
 | 
			
		||||
    const validPubkey =
 | 
			
		||||
      '0582fe8822c684999663cc6636148328fbd47c0836814c118af4e326bb4f0e1000';
 | 
			
		||||
    should().not.Throw(() => new PubKey(validPubkey), Error);
 | 
			
		||||
 | 
			
		||||
    const pubkey = new PubKey(validPubkey);
 | 
			
		||||
    expect(pubkey instanceof PubKey).to.be.equal(true);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('invalid pubkey should throw error', () => {
 | 
			
		||||
    const invalidPubkey = 'Lorem Ipsum';
 | 
			
		||||
 | 
			
		||||
    should().Throw(() => new PubKey(invalidPubkey), Error);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('can set pubkey type', () => {
 | 
			
		||||
    const validPubkey =
 | 
			
		||||
      '0582fe8822c684999663cc6636148328fbd47c0836814c118af4e326bb4f0e1000';
 | 
			
		||||
    const pubkeyType = PubKeyType.Primary;
 | 
			
		||||
 | 
			
		||||
    should().not.Throw(() => new PubKey(validPubkey, pubkeyType), Error);
 | 
			
		||||
 | 
			
		||||
    const pubkey = new PubKey(validPubkey, pubkeyType);
 | 
			
		||||
    expect(pubkey.type).to.be.equal(PubKeyType.Primary);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue