-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from navikt/ikke-bruke-fnr-i-path-og-query-pa…
…rams Ikke bruke fnr i path og query params
- Loading branch information
Showing
13 changed files
with
201 additions
and
7 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...oppgave/controller/EnheterController.java → ...gave/controller/v1/EnheterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ppgave/controller/InternalController.java → ...ave/controller/v1/InternalController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...oppgave/controller/OppgaveController.java → ...gave/controller/v1/OppgaveController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ontroller/OppgavehistorikkController.java → ...roller/v1/OppgavehistorikkController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/no/nav/veilarboppgave/controller/v2/EnheterControllerV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package no.nav.veilarboppgave.controller.v2; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import no.nav.common.types.identer.AktorId; | ||
import no.nav.common.types.identer.Fnr; | ||
import no.nav.veilarboppgave.domain.EnheterRequest; | ||
import no.nav.veilarboppgave.domain.OppfolgingEnhet; | ||
import no.nav.veilarboppgave.service.AuthService; | ||
import no.nav.veilarboppgave.service.EnheterService; | ||
import no.nav.veilarboppgave.util.Valider; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
import static no.nav.veilarboppgave.util.OppgaveUtils.tilTemaDto; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v2/enheter") | ||
public class EnheterControllerV2 { | ||
|
||
private final EnheterService enheterService; | ||
private final AuthService authService; | ||
|
||
@PostMapping | ||
public List<OppfolgingEnhet> hentEnheter(@RequestBody EnheterRequest enheterRequest, @RequestParam("tema") String tema) { | ||
Fnr fnr = enheterRequest.fnr(); | ||
AktorId aktorid = authService.getAktorIdOrThrow(fnr); | ||
|
||
authService.sjekkLesetilgangMedAktorId(aktorid); | ||
|
||
Valider.validerTema(tema); | ||
|
||
return enheterService.hentEnheter(fnr, tilTemaDto(tema)); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/no/nav/veilarboppgave/controller/v2/OppgavehistorikkControllerV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package no.nav.veilarboppgave.controller.v2; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import no.nav.common.types.identer.AktorId; | ||
import no.nav.veilarboppgave.domain.Oppgavehistorikk; | ||
import no.nav.veilarboppgave.domain.OppgavehistorikkRequest; | ||
import no.nav.veilarboppgave.service.AuthService; | ||
import no.nav.veilarboppgave.service.OppgavehistorikkService; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v2/oppgavehistorikk") | ||
public class OppgavehistorikkControllerV2 { | ||
|
||
private final AuthService authService; | ||
private final OppgavehistorikkService oppgavehistorikkService; | ||
|
||
@PostMapping | ||
public List<Oppgavehistorikk> getOppgavehistorikk(@RequestBody OppgavehistorikkRequest oppgavehistorikkRequest) { | ||
AktorId aktorId = authService.getAktorIdOrThrow(oppgavehistorikkRequest.fnr()); | ||
|
||
authService.sjekkLesetilgangMedAktorId(aktorId); | ||
|
||
return oppgavehistorikkService.hentOppgavehistorikk(aktorId); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/no/nav/veilarboppgave/domain/EnheterRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package no.nav.veilarboppgave.domain; | ||
|
||
import no.nav.common.types.identer.Fnr; | ||
|
||
public record EnheterRequest( | ||
Fnr fnr | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/no/nav/veilarboppgave/domain/OppgavehistorikkRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package no.nav.veilarboppgave.domain; | ||
|
||
import no.nav.common.types.identer.Fnr; | ||
|
||
public record OppgavehistorikkRequest( | ||
Fnr fnr | ||
) { | ||
} |
3 changes: 2 additions & 1 deletion
3
...pgave/controller/EnhetControllerTest.java → ...ve/controller/v1/EnhetControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ave/controller/OppgaveControllerTest.java → .../controller/v1/OppgaveControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...oller/OppgavehistorikkControllerTest.java → ...er/v1/OppgavehistorikkControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/no/nav/veilarboppgave/controller/v2/EnhetControllerV2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package no.nav.veilarboppgave.controller.v2; | ||
|
||
import no.nav.veilarboppgave.domain.EnheterRequest; | ||
import no.nav.veilarboppgave.domain.TemaDTO; | ||
import no.nav.veilarboppgave.service.AuthService; | ||
import no.nav.veilarboppgave.service.EnheterService; | ||
import no.nav.veilarboppgave.utils.TestData; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class EnhetControllerV2Test { | ||
|
||
private EnheterControllerV2 enheterControllerV2; | ||
private AuthService authServiceMock; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
authServiceMock = mock(AuthService.class); | ||
enheterControllerV2 = new EnheterControllerV2(mock(EnheterService.class), authServiceMock); | ||
} | ||
|
||
@Test | ||
public void skal_sjekke_tilgang() { | ||
EnheterRequest enheterRequest = new EnheterRequest(TestData.genererTilfeldigFnrUtenTilgang()); | ||
|
||
enheterControllerV2.hentEnheter(enheterRequest, TemaDTO.OPPFOLGING.name()); | ||
|
||
verify(authServiceMock, atLeastOnce()).sjekkLesetilgangMedAktorId(any()); | ||
} | ||
|
||
@Test | ||
public void skal_kaste_exception_ved_validering_av_ugyldig_tema() { | ||
assertThrows(ResponseStatusException.class, () -> { | ||
EnheterRequest enheterRequest = new EnheterRequest(TestData.genererTilfeldigFnrMedTilgang()); | ||
enheterControllerV2.hentEnheter(enheterRequest, "UGYLDIG_TEMA"); | ||
}); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/test/java/no/nav/veilarboppgave/controller/v2/OppgavehistorikkControllerV2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package no.nav.veilarboppgave.controller.v2; | ||
|
||
|
||
import no.nav.common.types.identer.AktorId; | ||
import no.nav.common.types.identer.Fnr; | ||
import no.nav.veilarboppgave.domain.Oppgavehistorikk; | ||
import no.nav.veilarboppgave.domain.OppgavehistorikkDTO; | ||
import no.nav.veilarboppgave.domain.OppgavehistorikkRequest; | ||
import no.nav.veilarboppgave.repositoyry.OppgavehistorikkRepository; | ||
import no.nav.veilarboppgave.service.AuthService; | ||
import no.nav.veilarboppgave.service.OppgavehistorikkService; | ||
import no.nav.veilarboppgave.utils.SingletonPostgresContainer; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class OppgavehistorikkControllerV2Test { | ||
|
||
private AuthService authService = mock(AuthService.class); | ||
|
||
private OppgavehistorikkRepository oppgavehistorikkRepository; | ||
|
||
private OppgavehistorikkControllerV2 oppgavehistorikkControllerV2; | ||
|
||
@Before | ||
public void resetMocks() { | ||
JdbcTemplate db = SingletonPostgresContainer.init().createJdbcTemplate(); | ||
oppgavehistorikkRepository = new OppgavehistorikkRepository(db); | ||
OppgavehistorikkService oppgavehistorikkService = new OppgavehistorikkService(oppgavehistorikkRepository); | ||
oppgavehistorikkControllerV2 = new OppgavehistorikkControllerV2(authService, oppgavehistorikkService); | ||
|
||
reset(authService); | ||
} | ||
|
||
@Test | ||
public void skalHenteOppgavehistorikk() { | ||
AktorId aktoerid = AktorId.of("4444"); | ||
OppgavehistorikkRequest oppgavehistorikkRequest = new OppgavehistorikkRequest(Fnr.of("3333")); | ||
|
||
when(authService.getAktorIdOrThrow(any())).thenReturn(aktoerid); | ||
|
||
oppgavehistorikkRepository.insertOppgaveHistorikk(getOppgaveHitorikk(aktoerid)); | ||
oppgavehistorikkRepository.insertOppgaveHistorikk(getOppgaveHitorikk(aktoerid)); | ||
|
||
List<Oppgavehistorikk> oppgavehistorikkDTOS = oppgavehistorikkControllerV2.getOppgavehistorikk(oppgavehistorikkRequest); | ||
assertEquals(2, oppgavehistorikkDTOS.size()); | ||
} | ||
|
||
private OppgavehistorikkDTO getOppgaveHitorikk(AktorId aktorId) { | ||
return new OppgavehistorikkDTO("tema", | ||
"type", | ||
new Timestamp(0), | ||
"X000000", | ||
"GSAKID", | ||
aktorId.get()); | ||
} | ||
|
||
} |