Skip to content

Commit

Permalink
Add test for ResourcesImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
dantb committed Oct 6, 2023
1 parent d4e531d commit 50de1ad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class ResourcesRoutesSpec extends BaseRouteSpec with IOFromMap {
response.asJson shouldEqual
resourceMetadata(projectRef, id, schema, (nxv + "Custom").toString, createdBy = alice, updatedBy = alice)
}

}
}

Expand All @@ -199,7 +198,6 @@ class ResourcesRoutesSpec extends BaseRouteSpec with IOFromMap {
response.asJson shouldEqual
resourceMetadata(projectRef, id, schema, (nxv + "Custom").toString, createdBy = alice, updatedBy = alice)
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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),
Expand Down

0 comments on commit 50de1ad

Please sign in to comment.