From 83f24a1bb735711bc3144665bc48ab96cb3aa911 Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Mon, 30 Dec 2024 17:58:52 +0000 Subject: [PATCH] Add new test general function This removed the dependence in some of the model tests on verifying a model was 'right' by checking the length of a returned query and asserting that the expected result was always at position `[0]` in the array. --- test/support/general.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/support/general.js b/test/support/general.js index fa426c0f22..848bbe9a56 100644 --- a/test/support/general.js +++ b/test/support/general.js @@ -5,6 +5,23 @@ * @module GeneralHelper */ +/** + * Extracts an array of IDs from a collection of objects + * + * Added to support us moving away from checking, for example, `role.users.length === 1` in tests and instead verify + * that an instance's child property includes the record we expect by using `expect(userIds).to.include(testUser.id)` + * instead. + * + * @param {object[]} collectionToExtractIdsFrom - The collection of objects to extract IDs from + * + * @returns {string[]} An array of IDs extracted from the collection + */ +function ids(collectionToExtractIdsFrom) { + return collectionToExtractIdsFrom.map((item) => { + return item.id + }) +} + /** * Generate the POST request options needed for `server.inject()` * @@ -111,6 +128,7 @@ function randomRegionCode() { } module.exports = { + ids, postRequestOptions, randomInteger, randomRegionCode,