chore: complete Shangwutong connector integration

This commit is contained in:
Rogee
2026-08-04 18:00:10 +08:00
parent 4611c0201f
commit 3d7ff5a6b1
8 changed files with 215 additions and 26 deletions
@@ -0,0 +1,104 @@
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import Shangwutong from '../Shangwutong.vue';
vi.mock('../../../../../index', () => ({
default: {
replace: vi.fn(),
},
}));
vi.mock('dashboard/composables', () => ({
useAlert: vi.fn(),
}));
const t = key => key;
const mountComponent = ({
dispatch = vi.fn().mockResolvedValue({ id: 42 }),
} = {}) =>
shallowMount(Shangwutong, {
global: {
mocks: {
$t: t,
$store: {
dispatch,
getters: {
'inboxes/getUIFlags': { isCreating: false },
},
},
},
stubs: {
PageHeader: true,
NextButton: true,
},
},
});
describe('Shangwutong channel setup', () => {
it('submits the exact shangwutong channel payload', async () => {
const dispatch = vi.fn().mockResolvedValue({ id: 42 });
const wrapper = mountComponent({ dispatch });
await wrapper.setData({
channelName: ' 商务通站点 ',
sessionId: 'LZA69557093',
username: ' operator ',
password: 'secret-password',
desiredPresence: 'busy',
webhookUrl: 'http://shangwutong-connector:9100/webhooks/gochat/v1',
});
await wrapper.vm.createChannel();
expect(dispatch).toHaveBeenCalledWith('inboxes/createChannel', {
name: '商务通站点',
channel: {
type: 'shangwutong',
session_id: 'LZA69557093',
username: 'operator',
password: 'secret-password',
desired_presence: 'busy',
webhook_url: 'http://shangwutong-connector:9100/webhooks/gochat/v1',
},
});
});
it('rejects invalid session IDs before dispatching', async () => {
const dispatch = vi.fn();
const wrapper = mountComponent({ dispatch });
await wrapper.setData({
channelName: '商务通站点',
sessionId: 'short',
username: 'operator',
password: 'secret-password',
webhookUrl: 'http://shangwutong-connector:9100/webhooks/gochat/v1',
});
await wrapper.vm.createChannel();
await nextTick();
expect(dispatch).not.toHaveBeenCalled();
expect(wrapper.vm.v$.sessionId.$error).toBe(true);
});
it('rejects webhook URLs with userinfo or fragments', async () => {
const dispatch = vi.fn();
const wrapper = mountComponent({ dispatch });
await wrapper.setData({
channelName: '商务通站点',
sessionId: 'LZA69557093',
username: 'operator',
password: 'secret-password',
webhookUrl: 'http://user:pass@connector:9100/webhooks/gochat/v1#frag',
});
await wrapper.vm.createChannel();
await nextTick();
expect(dispatch).not.toHaveBeenCalled();
expect(wrapper.vm.v$.webhookUrl.$error).toBe(true);
});
});