'use strict'; const assert = require('node:assert/strict'); const { invokeSystemMethod } = require('../../support/system_method_client'); const VALID_LOGIN_CODE = process.env.SYSTEM_TEST_LOGIN_CODE || 'eyJ1dWlkIjoiMDg2MTk4MzQtY2FhYS00OTIyLWJmNjctODc5M2U2Y2MwYzJkIn0='; describe('test/app/controller/system.user.loginByCode.test.js', () => { it('should login successfully when code is valid', async () => { const res = await invokeSystemMethod('user.loginByCode', { code: VALID_LOGIN_CODE, }); assert.equal(res.status, 200); assert.equal(res.body.flag, 'success'); assert.equal(res.body.code, 200); assert.equal(res.body.success, true); assert.equal(typeof res.body.data?.token, 'string'); assert.ok(res.body.data.token.length > 20); assert.equal(typeof res.body.data?.user?.id, 'number'); }); it('should fail when code is missing', async () => { const res = await invokeSystemMethod('user.loginByCode', {}); assert.equal(res.status, 200); assert.equal(res.body.flag, 'failure'); assert.equal(res.body.code, 0); assert.match(String(res.body.message || ''), /code/); }); it('should fail when code is not valid base64 json', async () => { const code = `INVALID_CODE_${Date.now()}`; const res = await invokeSystemMethod('user.loginByCode', { code }); assert.equal(res.status, 200); assert.equal(res.body.flag, 'failure'); assert.equal(res.body.code, 0); assert.match(String(res.body.message || ''), /无效的登录码格式/); }); it('should fail when decoded payload does not contain uuid', async () => { const code = Buffer.from(JSON.stringify({ foo: 'bar' }), 'utf8').toString('base64'); const res = await invokeSystemMethod('user.loginByCode', { code }); assert.equal(res.status, 200); assert.equal(res.body.flag, 'failure'); assert.equal(res.body.code, 0); assert.match(String(res.body.message || ''), /uuid/); }); });