Skip to content

Commit

Permalink
Add new test general function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Cruikshanks committed Dec 30, 2024
1 parent 5b27789 commit 423f47c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/support/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
*
Expand Down Expand Up @@ -111,6 +128,7 @@ function randomRegionCode() {
}

module.exports = {
ids,
postRequestOptions,
randomInteger,
randomRegionCode,
Expand Down

0 comments on commit 423f47c

Please sign in to comment.