Skip to content

Commit

Permalink
integration-tests: Fix tests after fixing explicit auth to NdlaClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Aug 29, 2023
1 parent 762ea17 commit 9a244b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

package no.ndla.integrationtests.articleapi.draftapi

import no.ndla.articleapi.model.api
import no.ndla.common.model.NDLADate
import no.ndla.draftapi.DraftApiProperties
import no.ndla.integrationtests.UnitSuite
import no.ndla.network.AuthUser
import no.ndla.scalatestsuite.IntegrationSuite
import no.ndla.{articleapi, draftapi}
import org.eclipse.jetty.server.Server
Expand Down Expand Up @@ -49,39 +47,4 @@ class DraftApiClientTest
draftApiServer.stop()
}

private def setupAgreements() =
(1L to 10)
.map(id => {
draftApi.componentRegistry.agreementRepository.insert(
draftapi.TestData.sampleBySaDomainAgreement.copy(id = Some(id))
)
})

test("should be able to fetch agreements' copyright") {
setupAgreements()

val expectedCopyright = api.Copyright(
api.License(
"CC-BY-SA-4.0",
Some("Creative Commons Attribution-ShareAlike 4.0 International"),
Some("https://creativecommons.org/licenses/by-sa/4.0/")
),
"Origin",
Seq.empty,
Seq.empty,
Seq.empty,
None,
None,
None
)

val exampleToken =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlF6bEVPVFE1TTBOR01EazROakV4T0VKR01qYzJNalZGT0RoRVFrRTFOVUkyTmtFMFJUUXlSZyJ9.eyJodHRwczovL25kbGEubm8vbmRsYV9pZCI6IjQyWDkxUmEyY0M0d0xQSDZhUHloajVWQSIsImh0dHBzOi8vbmRsYS5uby91c2VyX25hbWUiOiJIdXJkaUR1cmR5IiwiaHR0cHM6Ly9uZGxhLm5vL2NsaWVudF9pZCI6IktFMjZMTTJSS05heFBsS1c5M0xMTGtPc0Vnb01Ma3BXIiwiaXNzIjoiaHR0cHM6Ly9uZGxhLXRlc3QuZXUuYXV0aDAuY29tLyIsInN1YiI6Imdvb2dsZS1vYXV0aDIiLCJhdWQiOiJuZGxhX3N5c3RlbSIsImlhdCI6MTU0NzQ1ODExNiwiZXhwIjoxNTQ3NDY1MzE2LCJhenAiOiJGSzM1RkQzWUhPZWFZY1hHODBFVkNiQm1BZmlGR3ppViIsInNjb3BlIjoibGlzdGluZzp3cml0ZSBkcmFmdHM6YWRtaW4gbGVhcm5pbmdwYXRoOmFkbWluIGRyYWZ0czpzZXRfdG9fcHVibGlzaCBhdWRpbzp3cml0ZSBpbWFnZXM6d3JpdGUgY29uY2VwdDp3cml0ZSBkcmFmdHM6d3JpdGUgdGF4b25vbXk6d3JpdGUgYXJ0aWNsZXM6d3JpdGUgIn0K.hgk3TpqXpCerofnVaE17ZH7r4Cr3ehaiOl95hsipQrL9OuJvzDx1Y7-DrGfk6Y3-cE4qwScEahpYVf_aOIuXPNNKfbtRYPV3H84T1B02j1olhlLzEbJ-BGyvN2J6CpVy2PHfSUpTVjOMB7q4IDti2NUlhYSXCY4_ZAZhN20wXqID71ZjWqwNRJh1xUXfBQFOkFkCRxgYgEUA_oBrVBgx66iXhIrTDVcGPNyLRui40LMDnQFTU7lel-c1BdK393MHq9lQq5Yg3x5tFJ3k3HA682_UCiN8HzNvLaE5bUyskXPT-Qy57uWNuO0bpUkiRxB2rYwUR5OGYSCWz9fSbIKptQ"

AuthUser.setHeader(s"Bearer $exampleToken")
val draftApiClient = new DraftApiClient(draftApiBaseUrl)
val copyright = draftApiClient.getAgreementCopyright(1)
copyright.get should be(expectedCopyright)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import no.ndla.common.model.{NDLADate, domain => common}
import no.ndla.draftapi.model.api.ContentId
import no.ndla.integrationtests.UnitSuite
import no.ndla.network.AuthUser
import no.ndla.network.tapir.auth.TokenUser
import no.ndla.scalatestsuite.IntegrationSuite
import org.json4s.Formats
import org.testcontainers.containers.PostgreSQLContainer
Expand Down Expand Up @@ -67,7 +68,6 @@ class ArticleApiClientTest
Seq.empty,
Seq.empty,
None,
None,
None
)

Expand Down Expand Up @@ -114,6 +114,7 @@ class ArticleApiClientTest
val exampleToken =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6Ik9FSTFNVVU0T0RrNU56TTVNekkyTXpaRE9EazFOMFl3UXpkRE1EUXlPRFZDUXpRM1FUSTBNQSJ9.eyJodHRwczovL25kbGEubm8vbmRsYV9pZCI6Inh4eHl5eSIsImlzcyI6Imh0dHBzOi8vbmRsYS5ldS5hdXRoMC5jb20vIiwic3ViIjoieHh4eXl5QGNsaWVudHMiLCJhdWQiOiJuZGxhX3N5c3RlbSIsImlhdCI6MTUxMDMwNTc3MywiZXhwIjoxNTEwMzkyMTczLCJwZXJtaXNzaW9ucyI6WyJhcnRpY2xlczpwdWJsaXNoIiwiZHJhZnRzOndyaXRlIiwiZHJhZnRzOnNldF90b19wdWJsaXNoIiwiYXJ0aWNsZXM6d3JpdGUiXSwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.v6q6y6owx9VXri1h4FJJHDAnMllmNYFAAT2b9CJLm88"
val authHeaderMap: Map[String, String] = Map("Authorization" -> s"Bearer $exampleToken")
val authUser = TokenUser.SystemUser.copy(originalToken = Some(exampleToken))

class LocalArticleApiTestData extends articleapi.Props with articleapi.TestData {
override val props: ArticleApiProperties = articleApiProperties
Expand Down Expand Up @@ -150,7 +151,8 @@ class ArticleApiClientTest
testArticle,
List("1234"),
useImportValidation = false,
useSoftValidation = false
useSoftValidation = false,
authUser
)
response.isSuccess should be(true)
}
Expand All @@ -160,22 +162,22 @@ class ArticleApiClientTest
val contentId = ContentId(1)
AuthUser.setHeader(s"Bearer $exampleToken")
val articleApiClient = new ArticleApiClient(articleApiBaseUrl)
articleApiClient.deleteArticle(1).get should be(contentId)
articleApiClient.deleteArticle(1, authUser).get should be(contentId)
}

test("that unpublishing an article returns 200") {
dataFixer.setupArticles()
AuthUser.setHeader(s"Bearer $exampleToken")
val articleApiCient = new ArticleApiClient(articleApiBaseUrl)
articleApiCient.unpublishArticle(testArticle).get
articleApiCient.unpublishArticle(testArticle, authUser).get
}

test("that verifying an article returns 200 if valid") {
AuthUser.setHeader(s"Bearer $exampleToken")
val articleApiCient = new ArticleApiClient(articleApiBaseUrl)
val result = converterService
.toArticleApiArticle(testArticle)
.flatMap(article => articleApiCient.validateArticle(article, importValidate = false))
.flatMap(article => articleApiCient.validateArticle(article, importValidate = false, None))
println(result)
result.isSuccess should be(true)
}
Expand All @@ -185,7 +187,7 @@ class ArticleApiClientTest
val articleApiCient = new ArticleApiClient(articleApiBaseUrl)
val result = converterService
.toArticleApiArticle(testArticle.copy(title = Seq(common.Title("", "nb"))))
.flatMap(article => articleApiCient.validateArticle(article, importValidate = false))
.flatMap(article => articleApiCient.validateArticle(article, importValidate = false, None))
result.isSuccess should be(false)
}
}

0 comments on commit 9a244b3

Please sign in to comment.