Skip to content

Commit

Permalink
feat : 디바이스 토큰 1개의 값만 저장하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
thalals committed Sep 18, 2024
1 parent 8123920 commit dc95f10
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public ResponseEntity<Object> patchUserAgreement(@AuthenticationPrincipal final
@PatchMapping("/user/device-key")
public ResponseEntity<Object> saveDeviceKey(@AuthenticationPrincipal final User user, @RequestBody @Valid final UserDeviceKeyRequest request) {
userFacade.updateDeviceKey(user.getUserUuid(), request.deviceKey());
return ResponseEntity.status(HttpStatus.CREATED).build();
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,6 @@ void docsDeviceKey() throws Exception {
)
)
)
.andExpect(MockMvcResultMatchers.status().isCreated());
.andExpect(MockMvcResultMatchers.status().isOk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

public interface UserDeviceKeyRepository extends JpaRepository<UserDeviceKey, Long> {

Optional<UserDeviceKey> findByUserUuidAndDeviceKey(final String userUuid, final String deviceKey);
Optional<UserDeviceKey> findByUserUuid(final String userUuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UserDeviceKeyService {

public void update(final String userUuid, final String deviceKey) {

Optional<UserDeviceKey> userDeviceKey = userDeviceKeyRepository.findByUserUuidAndDeviceKey(userUuid, deviceKey);
Optional<UserDeviceKey> userDeviceKey = userDeviceKeyRepository.findByUserUuid(userUuid);
if (userDeviceKey.isEmpty()) {
userDeviceKeyRepository.save(UserDeviceKey.create(userUuid, deviceKey));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@ class UserDeviceKeyServiceTest {
@Test
@DisplayName("유저 uuid 와 매핑되는 deviceKey 가 존재하지 않음 (생성)")
void updateByUserUuidAndDeviceKey() {
when(userDeviceKeyRepository.findByUserUuidAndDeviceKey(anyString(),
anyString())).thenReturn(Optional.empty());
when(userDeviceKeyRepository.findByUserUuid(anyString())).thenReturn(Optional.empty());

deviceKeyService.update(anyString(), anyString());
deviceKeyService.update(anyString(), "device key");

verify(userDeviceKeyRepository).save(any());
}

@Test
@DisplayName("유저 uuid 와 매핑되는 deviceKey 가 존재 (미생성)")
void nonUpdateByUserUuidAndDeviceKey() {
when(userDeviceKeyRepository.findByUserUuidAndDeviceKey(anyString(),
anyString())).thenReturn(Optional.of(mock(UserDeviceKey.class)));
when(userDeviceKeyRepository.findByUserUuid(anyString())).thenReturn(Optional.of(mock(UserDeviceKey.class)));

deviceKeyService.update(anyString(), anyString());
deviceKeyService.update(anyString(), "device key");

verify(userDeviceKeyRepository, times(0)).save(any());
}
Expand Down

0 comments on commit dc95f10

Please sign in to comment.