From 78c0908ea3833dbe9d625ae34f1c5e3aae8c2949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Fri, 25 Aug 2023 10:40:09 +0200 Subject: [PATCH] #847: add test for delete journey --- lib/metadataTypes/Journey.js | 9 +++- .../delete-response.json | 1 + test/type.journey.test.js | 49 ++++++++++++++----- 3 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 test/resources/9999999/interaction/v1/interactions/233d4413-922c-4568-85a5-e5cc77efc3be/delete-response.json diff --git a/lib/metadataTypes/Journey.js b/lib/metadataTypes/Journey.js index 1719dfe47..b2ea341b2 100644 --- a/lib/metadataTypes/Journey.js +++ b/lib/metadataTypes/Journey.js @@ -191,14 +191,21 @@ class Journey extends MetadataType { ); const results = this.parseResponseBody(response, key); singleKey = results[key].id; + if (version && version > results[key].version) { + Util.logger.error( + `The chosen version (${version}) is higher than the latest known version (${results[key].version}). Please choose a lower version.` + ); + return false; + } Util.logger.debug(`Deleting interaction ${key} via its ID ${singleKey}`); } if (!/^\d+$/.test(version)) { - throw new TypeError( + Util.logger.error( 'Version is required for deleting interactions to avoid accidental deletion of the wrong item. Please append it at the end of the key or id, separated by forward-slash. Example for deleting version 4: ' + key + '/4' ); + return false; } Util.logger.warn( `Deleting Journeys via this command breaks following retrieve-by-key/id requests until you've deployed/created a new draft version! You can get still get the latest available version of your journey by retrieving all interactions on this BU.` diff --git a/test/resources/9999999/interaction/v1/interactions/233d4413-922c-4568-85a5-e5cc77efc3be/delete-response.json b/test/resources/9999999/interaction/v1/interactions/233d4413-922c-4568-85a5-e5cc77efc3be/delete-response.json new file mode 100644 index 000000000..db5917a02 --- /dev/null +++ b/test/resources/9999999/interaction/v1/interactions/233d4413-922c-4568-85a5-e5cc77efc3be/delete-response.json @@ -0,0 +1 @@ +233d4413-922c-4568-85a5-e5cc77efc3be \ No newline at end of file diff --git a/test/type.journey.test.js b/test/type.journey.test.js index 6003f511f..60a3a3fa5 100644 --- a/test/type.journey.test.js +++ b/test/type.journey.test.js @@ -141,17 +141,44 @@ describe('type: journey', () => { }); }); describe('Delete ================', () => { - // TODO: add this test - it('Should delete the item'); // , async () => { - // // WHEN - // const result = await handler.deleteByKey('testInstance/testBU', 'mobileKeyword', [ - // 'testExisting_keyword', - // ]); - // // THEN - // assert.equal(process.exitCode, false, 'delete should not have thrown an error'); + it('Should NOT delete the item due to missing version', async () => { + // WHEN + const isDeleted = await handler.deleteByKey( + 'testInstance/testBU', + 'journey', + 'testExisting_interaction' + ); + // THEN + assert.equal(process.exitCode, true, 'delete should have thrown an error'); - // assert.equal(result, true, 'should have deleted the item'); - // return; - // }); + assert.equal(isDeleted, false, 'should not have deleted the item'); + return; + }); + it('Should NOT delete the item due to unknown version', async () => { + // WHEN + const isDeleted = await handler.deleteByKey( + 'testInstance/testBU', + 'journey', + 'testExisting_interaction/2' + ); + // THEN + assert.equal(process.exitCode, true, 'delete should have thrown an error'); + + assert.equal(isDeleted, false, 'should not have deleted the item'); + return; + }); + it('Should delete the item with version', async () => { + // WHEN + const isDeleted = await handler.deleteByKey( + 'testInstance/testBU', + 'journey', + 'testExisting_interaction/1' + ); + // THEN + assert.equal(process.exitCode, false, 'delete should not have thrown an error'); + + assert.equal(isDeleted, true, 'should have deleted the item'); + return; + }); }); });