|
| 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