mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: jest test
This commit is contained in:
95
test/MessageUnique.ts
Normal file
95
test/MessageUnique.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
describe('MessageUniqueWrapper', () => {
|
||||
let messageUniqueWrapper: MessageUniqueWrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
messageUniqueWrapper = new MessageUniqueWrapper();
|
||||
});
|
||||
|
||||
test('createMsg should return a unique shortId for a new message', () => {
|
||||
const peer = new Peer();
|
||||
peer.chatType = 1;
|
||||
peer.peerUid = '123';
|
||||
const msgId = 'msgId123';
|
||||
|
||||
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`;
|
||||
const hash = crypto.createHash('sha1').update(key);
|
||||
const expectedShortId = parseInt(hash.digest('hex').slice(0, 8), 16);
|
||||
|
||||
const shortId = messageUniqueWrapper.createMsg(peer, msgId);
|
||||
|
||||
expect(shortId).toBeDefined();
|
||||
expect(shortId).toBe(expectedShortId);
|
||||
});
|
||||
|
||||
test('createMsg should return undefined if the same message is added again', () => {
|
||||
const peer = new Peer();
|
||||
peer.chatType = 1;
|
||||
peer.peerUid = '123';
|
||||
const msgId = 'msgId123';
|
||||
|
||||
const shortId = messageUniqueWrapper.createMsg(peer, msgId);
|
||||
const secondShortId = messageUniqueWrapper.createMsg(peer, msgId);
|
||||
|
||||
expect(shortId).toBeDefined();
|
||||
expect(secondShortId).toBeUndefined();
|
||||
});
|
||||
|
||||
test('getMsgIdAndPeerByShortId should return the message and peer for a given shortId', () => {
|
||||
const peer = new Peer();
|
||||
peer.chatType = 1;
|
||||
peer.peerUid = '123';
|
||||
const msgId = 'msgId123';
|
||||
|
||||
messageUniqueWrapper.createMsg(peer, msgId);
|
||||
|
||||
const shortId = messageUniqueWrapper.getShortIdByMsgId(msgId);
|
||||
const result = messageUniqueWrapper.getMsgIdAndPeerByShortId(shortId);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.MsgId).toBe(msgId);
|
||||
expect(result.Peer.chatType).toBe(peer.chatType);
|
||||
expect(result.Peer.peerUid).toBe(peer.peerUid);
|
||||
});
|
||||
|
||||
test('getMsgIdAndPeerByShortId should return undefined if the shortId does not exist', () => {
|
||||
const peer = new Peer();
|
||||
peer.chatType = 1;
|
||||
peer.peerUid = '123';
|
||||
const msgId = 'msgId123';
|
||||
|
||||
messageUniqueWrapper.createMsg(peer, msgId);
|
||||
|
||||
const invalidShortId = 12345678;
|
||||
const result = messageUniqueWrapper.getMsgIdAndPeerByShortId(invalidShortId);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
test('getShortIdByMsgId should return the shortId for a given message Id', () => {
|
||||
const peer = new Peer();
|
||||
peer.chatType = 1;
|
||||
peer.peerUid = '123';
|
||||
const msgId = 'msgId123';
|
||||
|
||||
messageUniqueWrapper.createMsg(peer, msgId);
|
||||
|
||||
const shortId = messageUniqueWrapper.getShortIdByMsgId(msgId);
|
||||
|
||||
expect(shortId).toBeDefined();
|
||||
expect(typeof shortId).toBe('number');
|
||||
});
|
||||
|
||||
test('getShortIdByMsgId should return undefined if the message Id does not exist', () => {
|
||||
const peer = new Peer();
|
||||
peer.chatType = 1;
|
||||
peer.peerUid = '123';
|
||||
const msgId = 'msgId123';
|
||||
|
||||
messageUniqueWrapper.createMsg(peer, msgId);
|
||||
|
||||
const invalidMsgId = 'invalidMsgId';
|
||||
const shortId = messageUniqueWrapper.getShortIdByMsgId(invalidMsgId);
|
||||
|
||||
expect(shortId).toBeUndefined();
|
||||
});
|
||||
});
|
@@ -1,4 +0,0 @@
|
||||
let t = require('./NapCatNative.node');
|
||||
console.log(t);
|
||||
let r = t.ClearElectronAsNode();
|
||||
console.log(r);
|
Binary file not shown.
@@ -1,6 +0,0 @@
|
||||
# Test For NapCatQQ
|
||||
This is a test for NapCatQQ.
|
||||
|
||||
# 计划
|
||||
1. 根据配置文件启动不同的测试 Event与Api
|
||||
2. 标记特殊注意的测试
|
@@ -1,4 +0,0 @@
|
||||
def send_pic_local_msg(user, file):
|
||||
pass
|
||||
def send_pic_http_msg(user, pic_url):
|
||||
pass
|
@@ -1,6 +0,0 @@
|
||||
import requests
|
||||
import pyyaml
|
||||
def __main__():
|
||||
print("TEST")
|
||||
|
||||
__main__()
|
@@ -1 +0,0 @@
|
||||
# todo
|
@@ -1 +0,0 @@
|
||||
#发送消息
|
@@ -1 +0,0 @@
|
||||
pyyaml==5.4.1
|
Reference in New Issue
Block a user