import assert from 'assert';
import { WsClient } from 'tsrpc';
import { encryptUint8Array } from '../../src/encrypt';
import { serviceProto } from '../../src/shared/protocols/serviceProto';

const bindUid = 'zeq1';


describe('ApiSend', function () {
    const client = new WsClient(serviceProto, {
        server: 'ws://localhost:8100',
        logger: undefined,
    });

    // 发送前加密
    client.flows.preSendDataFlow.push(v => {
        if (v.data instanceof Uint8Array) {
            v.data = encryptUint8Array(v.data);
        }
        return v;
    });

    before(async function () {
        const res = await client.connect();
        assert.strictEqual(res.isSucc, true, 'Failed to connect to server, have you executed `npm run dev` already?');
    });

    it('Success', async function () {
        await client.callApi('user/Login', { bindUid: bindUid, serverName: 'localhost', sid: 3 });
        await client.callApi('SyncBtn', []);
    });

    after(async function () {

    });
});