feat(onebot): expose qidian enterprise name on stranger info
When a stranger is a qidian account, attach the enterprise name from the corp data card. Non-qidian accounts keep an empty name. Refs #404
This commit is contained in:
1 parent
e1bb9b4722
commit
c1a0091143
15 files changed
+238
-10
No files matched your search
@@ -614,6 +614,55 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes through the qidian enterprise (企业) data-card when available', async () => {
|
||||
const fetchQidianCorpInfo = vi.fn(async () => ({
|
||||
name: '测试企业', intro: '测试简介', website: 'https://example.com',
|
||||
slogan: '测试签名', address: '测试地址', phone: '400-0000-0000', email: '[email protected]',
|
||||
}));
|
||||
const bridge = fakeBridge({
|
||||
apis: {
|
||||
contacts: {
|
||||
fetchUserProfile: vi.fn(async () => ({
|
||||
...makeProfile(55555, 'QidianWorker', 'male'),
|
||||
qidianMasterFlag: 0,
|
||||
qidianCrewFlag: 1,
|
||||
qidianCrewFlag2: 0,
|
||||
})),
|
||||
fetchQidianCorpInfo,
|
||||
},
|
||||
},
|
||||
});
|
||||
const out = await getStrangerInfo(bridge, 55555);
|
||||
expect(out).toMatchObject({
|
||||
user_id: 55555,
|
||||
qidian_master_flag: 0,
|
||||
qidian_crew_flag: 1,
|
||||
qidian_crew_flag_2: 0,
|
||||
qidian_enterprise_name: '测试企业',
|
||||
});
|
||||
expect(fetchQidianCorpInfo).toHaveBeenCalledWith(55555);
|
||||
});
|
||||
|
||||
it('leaves enterprise fields empty for non-qidian accounts and never calls the corp lookup', async () => {
|
||||
const fetchQidianCorpInfo = vi.fn(async () => ({
|
||||
name: 'x', intro: '', website: '', slogan: '', address: '', phone: '', email: '',
|
||||
}));
|
||||
const bridge = fakeBridge({
|
||||
apis: {
|
||||
contacts: {
|
||||
fetchUserProfile: vi.fn(async () => makeProfile(88888, 'Normal', 'male')),
|
||||
fetchQidianCorpInfo,
|
||||
},
|
||||
},
|
||||
});
|
||||
const out = await getStrangerInfo(bridge, 88888);
|
||||
expect(out).toMatchObject({
|
||||
user_id: 88888,
|
||||
qidian_enterprise_name: '',
|
||||
});
|
||||
expect(fetchQidianCorpInfo).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('falls back to identity.findUserProfile when fetch fails but the profile is cached', async () => {
|
||||
const bridge = fakeBridge({
|
||||
fetchUserProfile: vi.fn(async () => { throw new Error('net'); }),
|
||||
|
||||
@@ -34,6 +34,7 @@ describe('get_stranger_info action', () => {
|
||||
qidian_master_flag: { type: 'integer' },
|
||||
qidian_crew_flag: { type: 'integer' },
|
||||
qidian_crew_flag_2: { type: 'integer' },
|
||||
qidian_enterprise_name: { type: 'string' },
|
||||
},
|
||||
});
|
||||
expect(schema?.required).toContain('remark');
|
||||
|
||||
@@ -823,6 +823,7 @@ describe('buildApiContext contact reads', () => {
|
||||
qidian_master_flag: 0,
|
||||
qidian_crew_flag: 0,
|
||||
qidian_crew_flag_2: 0,
|
||||
qidian_enterprise_name: '',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user