Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski committed Mar 5, 2024
1 parent 57567fc commit 67c0e94
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ object Files {

def updatedCustomMetadata(e: FileCustomMetadataUpdated): Option[FileState] = state.map { s =>
val newAttributes = FileAttributes.setCustomMetadata(s.attributes, e.metadata)
s.copy(rev = e.rev, attributes = newAttributes,tags = s.tags ++ Tags(e.tag, e.rev), updatedAt = e.instant, updatedBy = e.subject)
val newTags = s.tags ++ Tags(e.tag, e.rev)
s.copy(rev = e.rev, attributes = newAttributes, tags = newTags, updatedAt = e.instant, updatedBy = e.subject)
}

def tagAdded(e: FileTagAdded): Option[FileState] = state.map { s =>
Expand Down Expand Up @@ -733,10 +734,11 @@ object Files {
FileState.serializer,
Tagger[FileEvent](
{
case f: FileCreated => f.tag.map(t => t -> f.rev)
case f: FileUpdated => f.tag.map(t => t -> f.rev)
case f: FileTagAdded => Some(f.tag -> f.targetRev)
case _ => None
case f: FileCreated => f.tag.map(t => t -> f.rev)
case f: FileUpdated => f.tag.map(t => t -> f.rev)
case f: FileTagAdded => Some(f.tag -> f.targetRev)
case f: FileCustomMetadataUpdated => f.tag.map(t => t -> f.rev)
case _ => None
},
{
case f: FileTagDeleted => Some(f.tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import akka.http.scaladsl.model.ContentTypes.{`application/json`, `text/plain(UT
import akka.http.scaladsl.model.MediaRanges._
import akka.http.scaladsl.model.MediaTypes.{`multipart/form-data`, `text/html`}
import akka.http.scaladsl.model.headers._
import akka.http.scaladsl.model.{HttpRequest, RequestEntity, StatusCodes, Uri}
import akka.http.scaladsl.model.{HttpRequest, MediaTypes, RequestEntity, StatusCodes, Uri}
import akka.http.scaladsl.server.Route
import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.kernel.http.MediaTypeDetectorConfig
Expand Down Expand Up @@ -434,6 +434,23 @@ class FilesRoutesSpec
}
}

"allow tagging when updating custom metadata" in {
givenAFile { id =>
val metadata = genCustomMetadata()
val userTag = UserTag.unsafe("mytag")

val headers = RawHeader("x-nxs-file-metadata", metadata.asJson.noSpaces)
Put(s"/v1/files/org/proj/$id?rev=1&tag=${userTag.value}").withHeaders(headers) ~> asWriter ~> routes ~> check {
status shouldEqual StatusCodes.OK
Get(s"/v1/files/org/proj/$id?tag=${userTag.value}") ~> Accept(
MediaTypes.`application/json`
) ~> asReader ~> routes ~> check {
status shouldEqual StatusCodes.OK
}
}
}
}

"return an error when attempting to update custom metadata without providing it" in {
givenAFile { id =>
Put(s"/v1/files/org/proj/$id?rev=1") ~> asWriter ~> routes ~> check {
Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/paradox/docs/delta/api/files-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ POST /v1/files/{org_label}/{project_label}?storage={storageId}&tag={tagName}
```

... where

- `{storageId}` selects a specific storage backend where the file will be uploaded. This field is optional.
When not specified, the default storage of the project is used.
- `{tagName}` an optional label given to the file on its first revision.
Expand Down Expand Up @@ -84,6 +85,7 @@ PUT /v1/files/{org_label}/{project_label}/{file_id}?storage={storageId}&tag={tag
```

... where

- `{storageId}` selects a specific storage backend where the file will be uploaded. This field is optional.
When not specified, the default storage of the project is used.
- `{tagName}` an optional label given to the file on its first revision.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,26 @@ class FilesSpec extends BaseIntegrationSpec {

(updateCustomMetadata >> assertMetadataUpdated).accepted
}
}

"update the custom metadata and tag at the same time" in {
givenAFile { id =>
val updatedName = "new name"
val md = Json.obj("name" := updatedName)
val header = RawHeader("x-nxs-file-metadata", md.noSpaces) :: Nil

val updateCustomMetadata = deltaClient
.putEmptyBody[Json](s"/files/$projectRef/$id?rev=1&tag=tag1", Writer, header) { expectOk }

val assertMetadataUpdated = deltaClient.get[Json](s"/files/$projectRef/$id?tag=tag1", Writer) {
(json, response) =>
response.status shouldEqual StatusCodes.OK
json.hcursor.get[Int]("_rev").rightValue shouldEqual 2
json should have(nameField(updatedName))
}

(updateCustomMetadata >> assertMetadataUpdated).accepted
}
}
}

Expand Down

0 comments on commit 67c0e94

Please sign in to comment.