100% edit-to-changes code coverage
This commit is contained in:
		
							parent
							
								
									8c4e16e255
								
							
						
					
					
						commit
						7780ee806a
					
				
					 5 changed files with 74 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -23,7 +23,7 @@ async function editToChanges(message, guild, api) {
 | 
			
		|||
 | 
			
		||||
	const roomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").pluck().get(message.channel_id)
 | 
			
		||||
	/** @type {string?} */
 | 
			
		||||
	let senderMxid = db.prepare("SELECT mxid FROM sim WHERE discord_id = ?").pluck().get(message.author.id) ?? null
 | 
			
		||||
	let senderMxid = db.prepare("SELECT mxid FROM sim WHERE discord_id = ?").pluck().get(message.author.id) || null
 | 
			
		||||
	if (senderMxid) {
 | 
			
		||||
		const senderIsInRoom = db.prepare("SELECT * FROM sim_member WHERE room_id = ? and mxid = ?").get(roomID, senderMxid)
 | 
			
		||||
		if (!senderIsInRoom) {
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ async function editToChanges(message, guild, api) {
 | 
			
		|||
		// Find a new event to pair it with...
 | 
			
		||||
		for (let i = 0; i < oldEventRows.length; i++) {
 | 
			
		||||
			const olde = oldEventRows[i]
 | 
			
		||||
			if (olde.event_type === newe.$type && olde.event_subtype === (newe.msgtype ?? null)) { // The spec does allow subtypes to change, so I can change this condition later if I want to
 | 
			
		||||
			if (olde.event_type === newe.$type && olde.event_subtype === (newe.msgtype || null)) { // The spec does allow subtypes to change, so I can change this condition later if I want to
 | 
			
		||||
				// Found one!
 | 
			
		||||
				// Set up the pairing
 | 
			
		||||
				eventsToReplace.push({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -103,6 +103,32 @@ test("edit2changes: add caption back to that image", async t => {
 | 
			
		|||
	t.deepEqual(eventsToReplace, [])
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test("edit2changes: stickers and attachments are not changed, only the content can be edited", async t => {
 | 
			
		||||
	const {eventsToRedact, eventsToReplace, eventsToSend} = await editToChanges(data.message_update.edited_content_with_sticker_and_attachments, data.guild.general, {})
 | 
			
		||||
	t.deepEqual(eventsToRedact, [])
 | 
			
		||||
	t.deepEqual(eventsToSend, [])
 | 
			
		||||
	t.deepEqual(eventsToReplace, [{
 | 
			
		||||
		oldID: "$lnAF9IosAECTnlv9p2e18FG8rHn-JgYKHEHIh5qdFv4",
 | 
			
		||||
		newContent: {
 | 
			
		||||
			$type: "m.room.message",
 | 
			
		||||
			msgtype: "m.text",
 | 
			
		||||
			body: "* only the content can be edited",
 | 
			
		||||
			"m.mentions": {},
 | 
			
		||||
			// *** Replaced With: ***
 | 
			
		||||
			"m.new_content": {
 | 
			
		||||
				msgtype: "m.text",
 | 
			
		||||
				body: "only the content can be edited",
 | 
			
		||||
				"m.mentions": {}
 | 
			
		||||
			},
 | 
			
		||||
			"m.relates_to": {
 | 
			
		||||
				rel_type: "m.replace",
 | 
			
		||||
				event_id: "$lnAF9IosAECTnlv9p2e18FG8rHn-JgYKHEHIh5qdFv4"
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}])
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
test("edit2changes: edit of reply to skull webp attachment with content", async t => {
 | 
			
		||||
	const {eventsToRedact, eventsToReplace, eventsToSend} = await editToChanges(data.message_update.edit_of_reply_to_skull_webp_attachment_with_content, data.guild.general, {})
 | 
			
		||||
	t.deepEqual(eventsToRedact, [])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue