36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const { getAuthToken, TOKEN_FILE } = require('../../support/system_method_client');
|
|
|
|
describe('test/app/controller/system.user.login.test.js', () => {
|
|
it('should get token from cache or login method', async () => {
|
|
const { token, fromCache } = await getAuthToken();
|
|
|
|
assert.equal(typeof token, 'string');
|
|
assert.ok(token.length > 20);
|
|
assert.equal(typeof fromCache, 'boolean');
|
|
});
|
|
|
|
it('should persist token cache file', async () => {
|
|
assert.equal(fs.existsSync(TOKEN_FILE), true);
|
|
});
|
|
|
|
it('user.login should return token only', async () => {
|
|
const { invokeSystemMethod, USERNAME } = require('../../support/system_method_client');
|
|
const password = process.env.SYSTEM_TEST_PASSWORD || '111111';
|
|
|
|
const loginRes = await invokeSystemMethod('user.login', {
|
|
username: USERNAME,
|
|
password,
|
|
});
|
|
|
|
assert.equal(loginRes.status, 200);
|
|
assert.equal(loginRes.body.flag, 'success');
|
|
assert.equal(loginRes.body.code, 200);
|
|
assert.equal(typeof loginRes.body.data?.token, 'string');
|
|
assert.equal(loginRes.body.data?.user, undefined);
|
|
});
|
|
});
|