Skip to content

Commit

Permalink
Merge branch 'feature/PB-35256_WP2-52-Unit-test-performance-of-new-co…
Browse files Browse the repository at this point in the history
…llection-v2-and-ensure-no-regression-is-introduced' into 'develop'

PB-35256 WP2-5.2 Unit test performance of new collection v2 and ensure no regression is introduced

See merge request passbolt/passbolt-styleguide!1774
  • Loading branch information
Benj1er committed Sep 12, 2024
2 parents 83f5252 + b0092c8 commit d073c75
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,20 @@ export const defaultCommentCollectionDto = (data = {}) => ([
withModifier: true,
})
]);

/**
* Build comments dtos.
* @param {number} [commentsCount=10] The number of comments.
* @param {Object} [options]
* @param {Object} [options.withCreator=false] Add creator default dto.
* @param {Object} [options.withModifier=false] Add modifier default dto.
* @returns {object}
*/
export const buildDefineNumberOfCommentsDtos = (commentsCount = 10, options = {}) => {
const dtos = [];
for (let i = 0; i < commentsCount; i++) {
const dto = defaultCommentDto({content: `comment${i}`}, options);
dtos.push(dto);
}
return dtos;
};
30 changes: 30 additions & 0 deletions src/shared/models/entity/folder/foldersCollection.test.data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 4.9.4
*/
import {defaultFolderDto} from "./folderEntity.test.data";

/**
* Build dtos.
* @param {number} [foldersCount=10] The number of dtos.
* @param {object} [data]
* @returns {object}
*/
export const defaultFoldersCollectionDto = (foldersCount = 10, data = {}) => {
const dtos = [];
for (let i = 0; i < foldersCount; i++) {
const dto = defaultFolderDto({name: `folder ${i}`, ...data});
dtos.push(dto);
}
return dtos;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 4.9.4
*/
import {defaultUserTransferDto} from "./groupTransfer.test.data";

/**
* Default user transfers collection
* @param {number} [userTransferCount = 10] number of user transfer dto
* @param {object} [data] The data to override properties
* @returns {*[]}
*/
export const defaultUserTransfersCollectionDto = (userTransferCount = 10, data = {}) => {
const dtos = [];
for (let i = 0; i < userTransferCount; i++) {
const dto = defaultUserTransferDto(data);
dtos.push(dto);
}
return dtos;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 4.9.4
*/

import {defaultPermissionTransferDto} from "./permissionTransferEntity.test.data";

/**
* Build permission transfers collection dtos.
* @param {number} [permissionTransferCount=10] The number of permission transfer.
* @returns {object}
*/
export const defaultPermissionTransfersCollectionDtos = (permissionTransferCount = 10) => {
const dtos = [];
for (let i = 0; i < permissionTransferCount; i++) {
const dto = defaultPermissionTransferDto();
dtos.push(dto);
}
return dtos;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
resourceTypePasswordAndDescriptionDto,
resourceTypePasswordStringDto, resourceTypeTotpDto
} from "./resourceTypeEntity.test.data";
import {v4 as uuidv4} from "uuid";

/**
* Resource types collection dto.
Expand All @@ -28,3 +29,20 @@ export const resourceTypesCollectionDto = () => [
resourceTypePasswordDescriptionTotpDto(),
resourceTypeTotpDto()
];

/**
* Build dtos.
* @param {number} [count=10] The number of dtos.
* @returns {object}
*/
export const buildDefineNumberOfResourceTypesDtos = (count = 10) => {
const resourceTypesDto = resourceTypesCollectionDto();
const dtos = resourceTypesDto;
for (let i = 0; i < count; i++) {
const dto = {...resourceTypesDto[i % resourceTypesDto.length]};
dto.id = uuidv4();
dto.slug = `${dto.slug} ${i + 1}`;
dtos.push(dto);
}
return dtos;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
* @since 4.9.4
*/

import {defaultNeededSecretDto} from "./neededSecretEntity.test.data";

/**
* Build dtos.
* @param {number} [count=10] The number of dtos.
* @param {object} [data] The data to override the default dto.
* @returns {object}
*/
export const defaultNeededSecretsDtos = (count = 10, data = {}) => {
const dtos = [];
for (let i = 0; i < count; i++) {
const dto = defaultNeededSecretDto(data);
dtos.push(dto);
}
return dtos;
};

0 comments on commit d073c75

Please sign in to comment.