Skip to content

Commit

Permalink
#847: add test for delete journey
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Aug 25, 2023
1 parent 5e0f00e commit 78c0908
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
9 changes: 8 additions & 1 deletion lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
233d4413-922c-4568-85a5-e5cc77efc3be
49 changes: 38 additions & 11 deletions test/type.journey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});

0 comments on commit 78c0908

Please sign in to comment.