Skip to content

Commit 4fa7521

Browse files
committed
Update update.test.js
1 parent 532a9ff commit 4fa7521

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

test/routes/update.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,55 @@ describe("Update network failure behavior. __rest __core", () => {
116116
.send({ "@id": rerumUriOrig, testing: "item" })
117117
assert.equal(response.statusCode, 502)
118118
})
119+
120+
it("Preserves upstream text error message when update returns non-ok.", async () => {
121+
global.fetch = async () => ({
122+
ok: false,
123+
status: 503,
124+
text: async () => "Upstream update failure"
125+
})
126+
127+
const response = await request(routeTester)
128+
.put("/update")
129+
.set("Content-Type", "application/json")
130+
.send({ "@id": rerumUriOrig, testing: "item" })
131+
132+
assert.equal(response.statusCode, 502)
133+
assert.match(response.text, /Upstream update failure/)
134+
})
135+
136+
it("Falls back to generic RERUM error text when upstream .text() throws.", async () => {
137+
global.fetch = async () => ({
138+
ok: false,
139+
status: 500,
140+
text: async () => {
141+
throw new Error("text stream consumed")
142+
}
143+
})
144+
145+
const response = await request(routeTester)
146+
.put("/update")
147+
.set("Content-Type", "application/json")
148+
.send({ "@id": rerumUriOrig, testing: "item" })
149+
150+
assert.equal(response.statusCode, 502)
151+
assert.match(response.text, /A RERUM error occurred/)
152+
})
153+
154+
it("Maps successful upstream payload without id fields to 502.", async () => {
155+
global.fetch = async () => ({
156+
ok: true,
157+
json: async () => ({ testing: "item" })
158+
})
159+
160+
const response = await request(routeTester)
161+
.put("/update")
162+
.set("Content-Type", "application/json")
163+
.send({ "@id": rerumUriOrig, testing: "item" })
164+
165+
assert.equal(response.statusCode, 502)
166+
assert.match(response.text, /A RERUM error occurred/)
167+
})
119168
})
120169

121170
describe("Check that the properly used update endpoints function and interact with RERUM. __e2e", () => {

0 commit comments

Comments
 (0)