From 3388de6fb6a8e66d6cdf3ac8f32d86cebeef1e34 Mon Sep 17 00:00:00 2001 From: williamlardier Date: Thu, 12 May 2022 09:39:28 +0200 Subject: [PATCH] ARSN-178: set to undefined to clear MD --- lib/models/ObjectMD.js | 14 +++++++++----- tests/unit/models/ObjectMD.spec.js | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/models/ObjectMD.js b/lib/models/ObjectMD.js index ddd11d66c..b2ef13462 100644 --- a/lib/models/ObjectMD.js +++ b/lib/models/ObjectMD.js @@ -1208,16 +1208,20 @@ class ObjectMD { /** * Set x-amz-restore * - * @param {ObjectMDAmzRestore} value x-amz-restore object + * @param {ObjectMDAmzRestore|undefined} value x-amz-restore object * @returns {ObjectMD} itself * @throws {Error} case of invalid parameter */ setAmzRestore(value) { - // Accept object instance of ObjectMDAmzRestore and Object - if (!(value instanceof ObjectMDAmzRestore) && !ObjectMDAmzRestore.isValid(value)) { - throw new Error('x-amz-restore must be type of ObjectMDAmzRestore.'); + if (value) { + // Accept object instance of ObjectMDAmzRestore and Object + if (!(value instanceof ObjectMDAmzRestore) && !ObjectMDAmzRestore.isValid(value)) { + throw new Error('x-amz-restore must be type of ObjectMDAmzRestore.'); + } + this._data['x-amz-restore'] = value; + } else { + delete this._data['x-amz-restore']; } - this._data['x-amz-restore'] = value; return this; } } diff --git a/tests/unit/models/ObjectMD.spec.js b/tests/unit/models/ObjectMD.spec.js index 1a00a84b3..25d0c18d6 100644 --- a/tests/unit/models/ObjectMD.spec.js +++ b/tests/unit/models/ObjectMD.spec.js @@ -322,6 +322,11 @@ describe('ObjectMD class setters/getters', () => { }); }); }); + + it('ObjectMD::setAmzRestore should clear AmzRestore', () => { + md.setAmzRestore(); + assert.deepStrictEqual(md.getAmzRestore(), undefined); + }); }); describe('ObjectMD import from stored blob', () => {