Added tests

This commit is contained in:
Filip Izydorczyk
2020-12-23 12:12:50 +01:00
parent 61c5a43192
commit 6eac8e6266
2 changed files with 55 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package com.plannaplan.controllers;
import java.util.Optional;
import java.util.UUID;
import com.plannaplan.entities.User;
@ -67,9 +68,13 @@ public class TokenController {
@GetMapping("/token/refresh")
@ApiOperation(value = "Endpoint to access new token based on refresh token. It's needed when request with provided token fail with code 403")
public ResponseEntity<TokenResponse> getRefreshToken(
@RequestParam("refreshToken") @ApiParam(value = "Refresh token obtained in /token request") final String refreshToken) {
User user = this.userService.getUserByRefreshToken(refreshToken)
.orElseThrow(() -> new NullPointerException("User not found"));
@RequestParam("refreshToken") @ApiParam(value = "Refresh token obtained in /token request") final String refreshToken)
throws NullPointerException {
Optional<User> userResult = this.userService.getUserByRefreshToken(refreshToken);
if (userResult.isEmpty()) {
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
}
User user = userResult.get();
user.setToken(UUID.randomUUID().toString());
user = this.userService.save(user);
return new ResponseEntity<>(new TokenResponse(user), HttpStatus.OK);