feat(signin): 手机号已在其他应用注册时并入原账号并补成员关系
This commit is contained in:
@@ -575,4 +575,63 @@ describe('微信登录', () => {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('手机号已在其他应用注册、本应用无成员关系时直接并入', async () => {
|
||||
const mobile = nextMobile();
|
||||
const openid = `wx-merge-${mobile}`;
|
||||
openidByCode.set('code-merge', openid);
|
||||
|
||||
// 老账号只有就诊人端成员关系,陪诊师端还没有
|
||||
const existing = await createUser(mobile, '梁娟');
|
||||
await addMembership(existing.user._id, CONSUMER_APP, ['user']);
|
||||
|
||||
const res = await agent.post('/user/wxsignin').send({
|
||||
code: 'code-merge',
|
||||
appId: ADMIN_APP,
|
||||
phoneNumber: mobile,
|
||||
name: '张三',
|
||||
});
|
||||
|
||||
assert.equal(res.body.code, 0, res.body.msg);
|
||||
assert.equal(String(res.body.data.user._id), String(existing.user._id));
|
||||
assert.equal(await DBModel.User.countDocuments({ 'profile.mobile': mobile }), 1);
|
||||
|
||||
// 只补当前应用的成员关系与 openid 身份,账号资料不被覆盖
|
||||
const membership = await DBModel.UserApp.findOne({
|
||||
userId: existing.user._id,
|
||||
appId: ADMIN_APP,
|
||||
}).lean();
|
||||
assert.ok(membership);
|
||||
assert.deepEqual(membership.roles, ['user']);
|
||||
|
||||
assert.ok(
|
||||
await DBModel.UserIdentity.exists({
|
||||
userId: existing.user._id,
|
||||
appId: ADMIN_APP,
|
||||
provider: 'weixin-mini',
|
||||
openid,
|
||||
})
|
||||
);
|
||||
|
||||
const user = await DBModel.User.findById(existing.user._id).lean();
|
||||
assert.equal(user.profile.name, '梁娟');
|
||||
});
|
||||
|
||||
it('手机号已在本应用注册时,换微信登录被拒绝', async () => {
|
||||
const mobile = nextMobile();
|
||||
const existing = await createUser(mobile, '梁娟');
|
||||
await addMembership(existing.user._id, ADMIN_APP, ['user']);
|
||||
|
||||
openidByCode.set('code-merge-bound', `wx-merge-bound-${mobile}`);
|
||||
|
||||
const res = await agent.post('/user/wxsignin').send({
|
||||
code: 'code-merge-bound',
|
||||
appId: ADMIN_APP,
|
||||
phoneNumber: mobile,
|
||||
name: '梁娟',
|
||||
});
|
||||
|
||||
assert.equal(res.body.code, 409);
|
||||
assert.match(res.body.msg, /已在本应用注册/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user