From 50de1ade952d1dcea295e8c7dacd3e289db87c37 Mon Sep 17 00:00:00 2001 From: dantb Date: Fri, 6 Oct 2023 12:30:48 +0200 Subject: [PATCH] Add test for ResourcesImpl --- .../delta/routes/ResourcesRoutesSpec.scala | 2 - .../sdk/resources/ResourcesImplSpec.scala | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutesSpec.scala b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutesSpec.scala index 2efa498d2c..98efdc14ad 100644 --- a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutesSpec.scala +++ b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutesSpec.scala @@ -183,7 +183,6 @@ class ResourcesRoutesSpec extends BaseRouteSpec with IOFromMap { response.asJson shouldEqual resourceMetadata(projectRef, id, schema, (nxv + "Custom").toString, createdBy = alice, updatedBy = alice) } - } } @@ -199,7 +198,6 @@ class ResourcesRoutesSpec extends BaseRouteSpec with IOFromMap { response.asJson shouldEqual resourceMetadata(projectRef, id, schema, (nxv + "Custom").toString, createdBy = alice, updatedBy = alice) } - } } diff --git a/delta/sdk/src/test/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ResourcesImplSpec.scala b/delta/sdk/src/test/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ResourcesImplSpec.scala index 85991bb195..3d21724684 100644 --- a/delta/sdk/src/test/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ResourcesImplSpec.scala +++ b/delta/sdk/src/test/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/ResourcesImplSpec.scala @@ -111,6 +111,10 @@ class ResourcesImplSpec val myId7 = nxv + "myid7" // Resource created against the resource schema with id passed explicitly and with payload without @context val myId8 = nxv + "myid8" // Resource created against the resource schema with id present on the payload and having its context pointing on metadata and myId1 and myId2 val myId9 = nxv + "myid9" // Resource created against the resource schema with id present on the payload and having its context pointing on metadata and myId8 so therefore myId1 and myId2 + val myId10 = nxv + "myid10" + val myId11 = nxv + "myid11" + val myId12 = nxv + "myid12" + val myId13 = nxv + "myid13" // format: on val resourceSchema = Latest(schemas.resources) @@ -134,6 +138,20 @@ class ResourcesImplSpec } } + "succeed and tag with the id present on the payload" in { + forAll(List(myId10 -> resourceSchema, myId11 -> Latest(schema1.id))) { case (id, schemaRef) => + val sourceWithId = source deepMerge json"""{"@id": "$id"}""" + val expectedData = + ResourceGen.resource(id, projectRef, sourceWithId, Revision(schemaRef.iri, 1), Tags(tag -> 1)) + val resource = resources.create(projectRef, schemaRef, sourceWithId, Some(tag)).accepted + resource shouldEqual ResourceGen.resourceFor( + expectedData, + types = types, + subject = subject + ) + } + } + "succeed with the id present on the payload and passed" in { val list = List( @@ -152,6 +170,25 @@ class ResourcesImplSpec } } + "succeed and tag with the id present on the payload and passed" in { + val list = + List( + (myId12, "_", resourceSchema), + (myId13, "myschema", Latest(schema1.id)) + ) + forAll(list) { case (id, schemaSegment, schemaRef) => + val sourceWithId = source deepMerge json"""{"@id": "$id"}""" + val expectedData = + ResourceGen.resource(id, projectRef, sourceWithId, Revision(schemaRef.iri, 1), Tags(tag -> 1)) + val resource = resources.create(id, projectRef, schemaSegment, sourceWithId, Some(tag)).accepted + resource shouldEqual ResourceGen.resourceFor( + expectedData, + types = types, + subject = subject + ) + } + } + "succeed with the passed id" in { val list = List( ("nxv:myid5", myId5, resourceSchema),