Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from navikt/pdl_call_id
Browse files Browse the repository at this point in the history
Legger til callId og consumerId
  • Loading branch information
maccyber authored Jun 29, 2023
2 parents c2bc61f + 32efc94 commit 2403c89
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion paw-pdl-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "no.nav.paw"
version = "0.1.4"
version = "0.2.0"

plugins {
kotlin("jvm")
Expand Down
2 changes: 1 addition & 1 deletion paw-pdl-client/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ graphQLKotlinVersion=6.4.0
# Dependency versions
coroutinesVersion=1.6.4
kotlinSerializationVersion=1.4.0
ktorVersion=2.1.1
ktorVersion=2.3.1
mockkVersion=1.12.7
12 changes: 6 additions & 6 deletions paw-pdl-client/src/main/kotlin/no/nav/paw/pdl/HentAktorId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import no.nav.paw.pdl.graphql.generated.HentIdenter
import no.nav.paw.pdl.graphql.generated.enums.IdentGruppe
import no.nav.paw.pdl.graphql.generated.hentidenter.IdentInformasjon

suspend fun PdlClient.hentAktorId(ident: String): String? = hentIdenter(ident)
suspend fun PdlClient.hentAktorId(ident: String, callId: String): String? = hentIdenter(ident, callId)
?.firstOrNull { it.gruppe == IdentGruppe.AKTORID }
?.ident

suspend fun PdlClient.hentIdenter(ident: String): List<IdentInformasjon>? {
suspend fun PdlClient.hentIdenter(ident: String, callId: String): List<IdentInformasjon>? {
val query = HentIdenter(HentIdenter.Variables(ident))

logger.info("Henter 'aktorId' fra PDL")
logger.info("Henter 'hentIdenter' fra PDL")

val respons = execute(query)
val respons = execute(query, callId)

respons.errors?.let {
logger.error("Henter 'aktorId' fra PDL feilet med: ${respons.errors}")
logger.error("Henter 'hentIdenter' fra PDL feilet med: ${respons.errors}")
throw PdlException(it)
}

logger.info("Hentet 'aktorId' fra PDL")
logger.info("Hentet 'hentIdenter' fra PDL")

return respons
.data
Expand Down
5 changes: 4 additions & 1 deletion paw-pdl-client/src/main/kotlin/no/nav/paw/pdl/PdlClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PdlClient(
url: String,
// Tema: https://confluence.adeo.no/pages/viewpage.action?pageId=309311397
private val tema: String,
private val navConsumerId: String,
httpClient: HttpClient,
private val getAccessToken: () -> String
) {
Expand All @@ -25,10 +26,12 @@ class PdlClient(
httpClient = httpClient
)

internal suspend fun <T : Any> execute(query: GraphQLClientRequest<T>): GraphQLClientResponse<T> =
internal suspend fun <T : Any> execute(query: GraphQLClientRequest<T>, callId: String): GraphQLClientResponse<T> =
graphQLClient.execute(query) {
bearerAuth(getAccessToken())
header("Tema", tema)
header("Nav-Call-Id", callId)
header("Nav-Consumer-Id", navConsumerId)
}
}

Expand Down
2 changes: 1 addition & 1 deletion paw-pdl-client/src/test/kotlin/no/nav/paw/MockPdlClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ fun mockPdlClient(content: String): PdlClient {
headers = headersOf(HttpHeaders.ContentType, ContentType.Application.Json.toString())
)
}
return PdlClient("https://url", "tema", HttpClient(mockEngine)) { "fake token" }
return PdlClient("https://url", "tema", "consumerId", HttpClient(mockEngine)) { "fake token" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package no.nav.paw.pdl

import kotlinx.coroutines.runBlocking
import no.nav.paw.mockPdlClient
import java.util.UUID
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

class PdlClientTest {
val callId = UUID.randomUUID().toString()
@Test
fun `Forventer gyldig respons fra hentAktorId`() {
val respons = readResource("hentIdenter-response.json")
val pdlClient = mockPdlClient(respons)

val resultat = runBlocking { pdlClient.hentAktorId("2649500819544") }
val resultat = runBlocking { pdlClient.hentAktorId("2649500819544", callId) }
val forventet = "2649500819544"
assertEquals(forventet, resultat)
}
Expand All @@ -24,7 +26,7 @@ class PdlClientTest {
assertFailsWith<PdlException>(
block = {
runBlocking {
pdlClient.hentIdenter("2649500819544")
pdlClient.hentIdenter("2649500819544", callId)
}
}
)
Expand All @@ -35,7 +37,7 @@ class PdlClientTest {
val respons = readResource("hentIdenter-response.json")
val pdlClient = mockPdlClient(respons)

val resultat = runBlocking { pdlClient.hentIdenter("2649500819544") }
val resultat = runBlocking { pdlClient.hentIdenter("2649500819544", callId) }
val forventet = "09127821914"
assertEquals(forventet, resultat!!.first().ident)
}
Expand Down

0 comments on commit 2403c89

Please sign in to comment.