use of com.stardata.starshop2.authcontext.domain.loginlog.LoginLog in project starshop by beautautumn.
the class StarshopAuthLoginTests method should_create_and_save_login_log_correctly_given_login_log.
// 5.1. 记录用户登录日志;(组合任务,领域服务)
@Test
@Transactional
@Rollback(true)
void should_create_and_save_login_log_correctly_given_login_log() {
// given:
WxOpenId openId = WxOpenId.of("testOpenId");
User user = User.of("testUser", 2).avatarUrl("testUrl").country("testCountry").province("testProvince").city("testCity").language("testLanguage");
user.setOpenid(openId);
userRepository.add(user);
// when: 调用 loginLogService.recordLogin
LoginLog loginLog = loginLogService.recordLogin(user, "testIp");
entityManager.flush();
LoginLog loadedLog = loginLogRepository.instanceOf(loginLog.getId());
// then: 创建了有效的登录日志
assertNotNull(loadedLog);
assertNotNull(loadedLog.getLastLoginTime());
LocalDateTime now = LocalDateTime.now();
assertTrue(loadedLog.getLastLoginTime().isBefore(now.plusSeconds(1)));
}
use of com.stardata.starshop2.authcontext.domain.loginlog.LoginLog in project starshop by beautautumn.
the class LoginLogService method recordLogin.
public LoginLog recordLogin(User user, String loginIp) {
LoginLog log = LoginLog.createFor(user, loginIp);
logRepository.add(log);
return log;
}
Aggregations