private void setNotificationsReadDate(DbSession dbSession, UserDto user) { dbClient.userPropertiesDao().insertOrUpdate(dbSession, new UserPropertyDto() .setUserUuid(user.getUuid()) .setKey(NOTIFICATIONS_READ_DATE) .setValue(Long.toString(system2.now()))); } }
private void setUserSetting(String key, String value) { try (DbSession dbSession = dbClient.openSession(false)) { dbClient.userPropertiesDao().insertOrUpdate(dbSession, new UserPropertyDto() .setUserUuid(requireNonNull(userSession.getUuid(), "Authenticated user uuid cannot be null")) .setKey(key) .setValue(value)); dbSession.commit(); } }
public static UserPropertyDto newUserSettingDto(UserDto user) { return new UserPropertyDto() .setUuid(Uuids.createFast()) .setUserUuid(user.getUuid()) .setKey(randomAlphanumeric(20)) .setValue(randomAlphanumeric(100)); } }
@Test public void return_user_settings() { UserDto user = db.users().insertUser(); db.users().insertUserSetting(user, userSetting -> userSetting .setKey("notifications.readDate") .setValue("1234")); db.users().insertUserSetting(user, userSetting -> userSetting .setKey("notifications.optOut") .setValue("true")); db.commit(); userSession.logIn(user); CurrentWsResponse response = call(); assertThat(response.getSettingsList()) .extracting(CurrentWsResponse.Setting::getKey, CurrentWsResponse.Setting::getValue) .containsExactlyInAnyOrder( tuple("notifications.optOut", "true"), tuple("notifications.readDate", "1234")); }
@Test public void update_existing_setting() { UserDto user = db.users().insertUser(); db.users().insertUserSetting(user, userSetting -> userSetting .setKey("notifications.optOut") .setValue("false")); userSession.logIn(user); ws.newRequest() .setParam("key", "notifications.optOut") .setParam("value", "true") .execute(); assertThat(db.getDbClient().userPropertiesDao().selectByUser(db.getSession(), user)) .extracting(UserPropertyDto::getKey, UserPropertyDto::getValue) .containsExactlyInAnyOrder(tuple("notifications.optOut", "true")); }
@Test public void keep_existing_setting_when_setting_new_one() { UserDto user = db.users().insertUser(); db.users().insertUserSetting(user, userSetting -> userSetting .setKey("notifications.readDate") .setValue("1234")); userSession.logIn(user); ws.newRequest() .setParam("key", "notifications.optOut") .setParam("value", "true") .execute(); assertThat(db.getDbClient().userPropertiesDao().selectByUser(db.getSession(), user)) .extracting(UserPropertyDto::getKey, UserPropertyDto::getValue) .containsExactlyInAnyOrder( tuple("notifications.readDate", "1234"), tuple("notifications.optOut", "true")); }
@Test public void insert() { UserDto user = db.users().insertUser(); UserPropertyDto userSetting = underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() .setUserUuid(user.getUuid()) .setKey("a_key") .setValue("a_value")); Map<String, Object> map = db.selectFirst(db.getSession(), "select uuid as \"uuid\",\n" + " user_uuid as \"userUuid\",\n" + " kee as \"key\",\n" + " text_value as \"value\"," + " created_at as \"createdAt\",\n" + " updated_at as \"updatedAt\"" + " from user_properties"); assertThat(map).contains( entry("uuid", userSetting.getUuid()), entry("userUuid", user.getUuid()), entry("key", "a_key"), entry("value", "a_value"), entry("createdAt", NOW), entry("updatedAt", NOW)); }