Skip to content

Commit 4442fe3

Browse files
committed
tests
1 parent 064739c commit 4442fe3

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

db-controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ function _contextid(contextInput) {
3535
if(Array.isArray(contextInput)) {
3636
for(const c of contextInput) {
3737
contextURI = c
38+
console.log("For context 2 "+contextURI)
3839
bool = knownContexts.some(contextCheck)
3940
if(bool) break
4041
}
4142
}
4243
else {
44+
console.log("For context 1 "+contextURI)
4345
bool = knownContexts.some(contextCheck)
4446
}
4547
return bool
@@ -278,6 +280,7 @@ const putUpdate = async function (req, res, next) {
278280
}
279281
else {
280282
id = ObjectID()
283+
let context = objectReceived["@context"] ? { "@context": objectReceived["@context"] } : {}
281284
let rerumProp = { "__rerum": utils.configureRerumOptions(generatorAgent, originalObject, true, false)["__rerum"] }
282285
delete objectReceived["_rerum"]
283286
delete objectReceived["_id"]
@@ -1021,7 +1024,7 @@ const bulkCreate = async function (req, res, next) {
10211024
const id = isValidID(providedID) ? providedID : ObjectID()
10221025
let generatorAgent = getAgentClaim(req, next)
10231026
d = utils.configureRerumOptions(generatorAgent, d)
1024-
if(_contextid(provided["@context"])) {
1027+
if(_contextid(d["@context"])) {
10251028
// id is also protected in this case, so it can't be set.
10261029
delete d.id
10271030
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { jest } from "@jest/globals"
2+
import controller from '../../db-controller.js'
3+
4+
it("Functional '@id-id' negotiation on objects returned.", async () => {
5+
let negotiate = {
6+
"@context": "http://iiif.io/api/presentation/3/context.json",
7+
"_id": "example",
8+
"@id": "https://store.rerum.io/v1/id/example",
9+
"test": "item"
10+
}
11+
negotiate = controller.idNegotiation(negotiate)
12+
expect(negotiate._id).toBeUndefined()
13+
expect(negotiate["@id"]).toBeUndefined()
14+
expect(negotiate.id).toBe("https://store.rerum.io/v1/id/example")
15+
expect(negotiate.test).toBe("item")
16+
17+
let nonegotiate = {
18+
"@context":"http://example.org/context.json",
19+
"_id": "example",
20+
"@id": "https://store.rerum.io/v1/id/example",
21+
"id": "test_example",
22+
"test":"item"
23+
}
24+
nonegotiate = controller.idNegotiation(nonegotiate)
25+
expect(nonegotiate._id).toBeUndefined()
26+
expect(nonegotiate["@id"]).toBe("https://store.rerum.io/v1/id/example")
27+
expect(nonegotiate.id).toBe("test_example")
28+
expect(nonegotiate.test).toBe("item")
29+
})

0 commit comments

Comments
 (0)