68 lines
2.7 KiB
JavaScript
68 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
getAuthToken,
|
|
invokeSystemMethod,
|
|
invokeGatewayMethod,
|
|
} = require('../../support/system_method_client');
|
|
|
|
const YE4S_TEST_USER_ID = Number(process.env.SYSTEM_TEST_YE4S_USER_ID || 28);
|
|
|
|
describe('test/app/controller/gateway.user.bindAccountByTempCode.test.js', () => {
|
|
it('should bind, unbind, and bind again for ye4s user', async () => {
|
|
const { token } = await getAuthToken();
|
|
|
|
const infoRes = await invokeSystemMethod('user.info', {}, token);
|
|
assert.equal(infoRes.status, 200);
|
|
assert.equal(infoRes.body.flag, 'success');
|
|
const accountId = Number(infoRes.body?.data?.id);
|
|
assert.ok(Number.isFinite(accountId) && accountId > 0);
|
|
|
|
const bindCodeRes = await invokeSystemMethod('user.getBindWechatCode', {
|
|
forceRefresh: true,
|
|
init: true,
|
|
}, token);
|
|
assert.equal(bindCodeRes.status, 200);
|
|
assert.equal(bindCodeRes.body.flag, 'success');
|
|
const code = String(bindCodeRes.body?.data?.code || '');
|
|
assert.ok(code.length > 10);
|
|
|
|
const bindRes1 = await invokeGatewayMethod('user.bindAccountByTempCode', {
|
|
code,
|
|
ye4s_user_id: YE4S_TEST_USER_ID,
|
|
});
|
|
assert.equal(bindRes1.status, 200);
|
|
assert.equal(bindRes1.body.flag, 'success');
|
|
assert.equal(bindRes1.body.code, 200);
|
|
assert.equal(Number(bindRes1.body?.data?.account_id), accountId);
|
|
assert.equal(Number(bindRes1.body?.data?.ye4s_user_id), YE4S_TEST_USER_ID);
|
|
assert.equal(bindRes1.body?.data?.status, 'bound');
|
|
|
|
const unbindRes = await invokeSystemMethod('user.unbindWechat', {}, token);
|
|
assert.equal(unbindRes.status, 200);
|
|
assert.equal(unbindRes.body.flag, 'success');
|
|
assert.equal(unbindRes.body.code, 200);
|
|
assert.equal(unbindRes.body?.data?.status, 'unbound');
|
|
assert.equal(Number(unbindRes.body?.data?.account_id), accountId);
|
|
|
|
const bindRes2 = await invokeGatewayMethod('user.bindAccountByTempCode', {
|
|
code,
|
|
ye4s_user_id: YE4S_TEST_USER_ID,
|
|
});
|
|
assert.equal(bindRes2.status, 200);
|
|
assert.equal(bindRes2.body.flag, 'success');
|
|
assert.equal(bindRes2.body.code, 200);
|
|
assert.equal(Number(bindRes2.body?.data?.account_id), accountId);
|
|
assert.equal(Number(bindRes2.body?.data?.ye4s_user_id), YE4S_TEST_USER_ID);
|
|
assert.equal(bindRes2.body?.data?.status, 'bound');
|
|
|
|
const verifyRes = await invokeGatewayMethod('user.getUserByTempCode', { code });
|
|
assert.equal(verifyRes.status, 200);
|
|
assert.equal(verifyRes.body.flag, 'success');
|
|
assert.equal(verifyRes.body.code, 200);
|
|
assert.equal(Number(verifyRes.body?.data?.account_id), accountId);
|
|
assert.equal(verifyRes.body?.data?.status, 'bound');
|
|
});
|
|
});
|