You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			64 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			64 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
| 
											6 years ago
										 | import { expect } from 'chai'; | ||
| 
											6 years ago
										 | import { beforeEach } from 'mocha'; | ||
| 
											6 years ago
										 | 
 | ||
| 
											6 years ago
										 | import { | ||
|  |   DeliveryReceiptMessage, | ||
|  |   ReadReceiptMessage, | ||
| 
											5 years ago
										 | } from '../../../../session/messages/outgoing'; | ||
|  | import { SignalService } from '../../../../protobuf'; | ||
| 
											5 years ago
										 | import { toNumber } from 'lodash'; | ||
| 
											5 years ago
										 | import { Constants } from '../../../../session'; | ||
| 
											6 years ago
										 | 
 | ||
|  | describe('ReceiptMessage', () => { | ||
| 
											6 years ago
										 |   let readMessage: ReadReceiptMessage; | ||
|  |   let deliveryMessage: ReadReceiptMessage; | ||
|  |   let timestamps: Array<number>; | ||
|  | 
 | ||
|  |   beforeEach(() => { | ||
|  |     timestamps = [987654321, 123456789]; | ||
|  |     const timestamp = Date.now(); | ||
|  |     readMessage = new ReadReceiptMessage({ timestamp, timestamps }); | ||
|  |     deliveryMessage = new DeliveryReceiptMessage({ timestamp, timestamps }); | ||
|  |   }); | ||
|  | 
 | ||
|  |   it('content of a read receipt is correct', () => { | ||
|  |     const plainText = readMessage.plainTextBuffer(); | ||
|  |     const decoded = SignalService.Content.decode(plainText); | ||
|  | 
 | ||
|  |     expect(decoded.receiptMessage).to.have.property('type', 1); | ||
| 
											5 years ago
										 |     const decodedTimestamps = (decoded.receiptMessage?.timestamp ?? []).map( | ||
|  |       toNumber | ||
| 
											6 years ago
										 |     ); | ||
| 
											5 years ago
										 |     expect(decodedTimestamps).to.deep.equal(timestamps); | ||
| 
											6 years ago
										 |   }); | ||
|  | 
 | ||
|  |   it('content of a delivery receipt is correct', () => { | ||
|  |     const plainText = deliveryMessage.plainTextBuffer(); | ||
|  |     const decoded = SignalService.Content.decode(plainText); | ||
|  | 
 | ||
|  |     expect(decoded.receiptMessage).to.have.property('type', 0); | ||
| 
											5 years ago
										 |     const decodedTimestamps = (decoded.receiptMessage?.timestamp ?? []).map( | ||
|  |       toNumber | ||
| 
											6 years ago
										 |     ); | ||
| 
											5 years ago
										 |     expect(decodedTimestamps).to.deep.equal(timestamps); | ||
| 
											6 years ago
										 |   }); | ||
|  | 
 | ||
| 
											5 years ago
										 |   it('correct ttl', () => { | ||
|  |     expect(readMessage.ttl()).to.equal(Constants.TTL_DEFAULT.REGULAR_MESSAGE); | ||
| 
											5 years ago
										 |     expect(deliveryMessage.ttl()).to.equal( | ||
|  |       Constants.TTL_DEFAULT.REGULAR_MESSAGE | ||
|  |     ); | ||
| 
											6 years ago
										 |   }); | ||
|  | 
 | ||
|  |   it('has an identifier', () => { | ||
|  |     expect(readMessage.identifier).to.not.equal( | ||
|  |       null, | ||
|  |       'identifier cannot be null' | ||
|  |     ); | ||
|  |     expect(readMessage.identifier).to.not.equal( | ||
|  |       undefined, | ||
|  |       'identifier cannot be undefined' | ||
|  |     ); | ||
|  |   }); | ||
| 
											6 years ago
										 | }); |