Skip to content

Commit 7342e20

Browse files
committed
Add tests for PATCH requests
1 parent 3a2af73 commit 7342e20

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
install: npm install
3+
script: npm test
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"data": {
3+
"id": 1234,
4+
"jobId": "1106896193cb7216d96",
5+
"createdDate": "2021-11-16T10:17:06-05:00",
6+
"updatedDate": "2021-11-16T10:17:12-05:00",
7+
"success": false,
8+
"processed": true,
9+
"patron": "987654321",
10+
"nyplSource": "sierra-nypl",
11+
"requestType": "hold",
12+
"recordType": "i",
13+
"record": "15371503",
14+
"pickupLocation": "",
15+
"deliveryLocation": "NH",
16+
"neededBy": "2022-11-16T00:00:00-05:00",
17+
"numberOfCopies": 1,
18+
"docDeliveryData": null,
19+
"error": null
20+
},
21+
"count": 1,
22+
"statusCode": 200,
23+
"debugInfo": []
24+
}

test/patch-test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
let client = null
2+
3+
describe('Client PATCH method', function () {
4+
beforeEach(() => {
5+
client = require('./make-test-client')()
6+
})
7+
8+
afterEach(() => {
9+
client = null
10+
})
11+
12+
// This is a common patch that the
13+
// [HoldRequestResultConsumer makes](https://github.com/NYPL/hold-request-result-consumer/blob/e7bd5b04afe25cf65ed2a5ce2de0576973e592cb/src/OAuthClient/HoldRequestClient.php#L123)
14+
// makes when it detects a hold-request has been fulfilled
15+
var holdRequestPatch = {
16+
success: true,
17+
processed: true
18+
}
19+
20+
describe('when config.json=true (default)', function () {
21+
it('should accept a new schema object via PATCH and return an object', function () {
22+
return client.patch('hold-requests/1234', holdRequestPatch)
23+
.then((resp) => {
24+
expect(resp).to.be.a('object')
25+
})
26+
})
27+
28+
it('should fail if supplied body is plaintext', function () {
29+
let call = client.patch('hold-requests/1234', JSON.stringify(holdRequestPatch))
30+
return expect(call).to.be.rejected
31+
})
32+
33+
// A null/empty body should be accepted as valid if options.json===true
34+
it('should succeed if supplied body is empty', function () {
35+
let call = client.patch('hold-requests/1234')
36+
return expect(call).to.be.fulfilled
37+
})
38+
})
39+
40+
describe('when config.json=false', function () {
41+
it('should accept a plaintext body and return plain text', function () {
42+
let call = client.patch('hold-requests/1234', JSON.stringify(holdRequestPatch), { json: false })
43+
return Promise.all([
44+
expect(call).to.be.fulfilled,
45+
expect(call).to.eventually.be.a('string')
46+
])
47+
})
48+
49+
it('should fail if supplied body is not plaintext', function () {
50+
let call = client.patch('hold-requests/1234', holdRequestPatch, { json: false })
51+
return expect(call).to.be.rejected
52+
})
53+
})
54+
})

0 commit comments

Comments
 (0)