84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
const assert = require('assert');
|
|
const ProfilePages = require('../public/js/profile-pages.js');
|
|
|
|
function run() {
|
|
assert.strictEqual(ProfilePages.pick({
|
|
nickName: '汤小明',
|
|
userName: '备用'
|
|
}, ['nickName', 'userName'], '未设置'), '汤小明');
|
|
|
|
assert.strictEqual(ProfilePages.getAvatarText({
|
|
nickName: '汤小明'
|
|
}), '汤');
|
|
|
|
assert.deepStrictEqual(ProfilePages.buildProfileView({
|
|
nickName: '汤小明',
|
|
phone: '13800000000',
|
|
sex: '1',
|
|
birthday: '2026-07-09',
|
|
provinceCode: '510000',
|
|
cityCode: '510100',
|
|
districtCode: '510104'
|
|
}), {
|
|
displayName: '汤小明',
|
|
avatarText: '汤',
|
|
phone: '13800000000',
|
|
sex: '1',
|
|
birthday: '2026-07-09',
|
|
regionText: '510000 / 510100 / 510104'
|
|
});
|
|
|
|
assert.deepStrictEqual(ProfilePages.buildProfileUpdateBody({
|
|
nickName: ' 汤小明 ',
|
|
avatarOssId: '2060001',
|
|
sex: '1',
|
|
birthday: '2026-07-09',
|
|
provinceCode: '510000',
|
|
cityCode: '510100',
|
|
districtCode: '510104'
|
|
}), {
|
|
nickName: '汤小明',
|
|
avatarOssId: 2060001,
|
|
sex: '1',
|
|
birthday: '2026-07-09',
|
|
provinceCode: '510000',
|
|
cityCode: '510100',
|
|
districtCode: '510104'
|
|
});
|
|
|
|
assert.deepStrictEqual(ProfilePages.buildProfileUpdateBody({
|
|
nickName: ' ',
|
|
avatarOssId: '',
|
|
sex: '',
|
|
birthday: ''
|
|
}), {
|
|
nickName: undefined,
|
|
avatarOssId: undefined,
|
|
sex: undefined,
|
|
birthday: undefined,
|
|
provinceCode: undefined,
|
|
cityCode: undefined,
|
|
districtCode: undefined
|
|
});
|
|
|
|
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
|
getToken: () => ''
|
|
}), true);
|
|
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
|
getToken: () => 'token-x'
|
|
}), false);
|
|
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
|
getToken: () => 'token-x'
|
|
}, { status: 401 }), true);
|
|
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
|
getToken: () => 'token-x'
|
|
}, { code: 401 }), true);
|
|
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
|
getToken: () => 'token-x'
|
|
}, { status: 500 }), false);
|
|
|
|
console.log('profile-pages tests passed');
|
|
}
|
|
|
|
run();
|