Skip to content

Commit

Permalink
Merge branch 'feature/PB-35323_WP2-54-Remove-resource-entity-test-dat…
Browse files Browse the repository at this point in the history
…a-metadata-v4-massaging-in-default-factory' into 'develop'

PB-35323 Ensure resource test factory does not contain any metadata at the root of the resource

See merge request passbolt/passbolt-styleguide!1769
  • Loading branch information
cedricalfonsi committed Sep 10, 2024
2 parents f471c42 + a585355 commit 2932644
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 875 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,3 @@ export function defaultProps(data = {}) {

return Object.assign(defaultData, data);
}

export const defaultResourceMeta = (data = {}) => ({
name: "Password name",
uris: ["https://uri.dev"],
username: "Password username",
description: "Password description",
...data
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "../../../test/lib/crypto/cryptoGetRandomvalues";
import {ActionFeedbackContext} from "../../../contexts/ActionFeedbackContext";
import PassboltApiFetchError from "../../../../shared/lib/Error/PassboltApiFetchError";
import {waitFor} from "@testing-library/react";
import {defaultAppContext, defaultProps, defaultResourceMeta} from "./CreateResource.test.data";
import {defaultAppContext, defaultProps} from "./CreateResource.test.data";
import CreateResourcePage from "./CreateResource.test.page";
import NotifyError from "../../Common/Error/NotifyError/NotifyError";
import {
Expand All @@ -39,6 +39,9 @@ import ConfirmCreateEdit, {
ConfirmEditCreateOperationVariations,
ConfirmEditCreateRuleVariations
} from "../ConfirmCreateEdit/ConfirmCreateEdit";
import {
defaultResourceMetadataDto
} from "../../../../shared/models/entity/resourceMetadata/resourceMetadataEntity.test.data";

describe("See the Create Resource", () => {
let page, props, context;
Expand Down Expand Up @@ -166,7 +169,7 @@ describe("See the Create Resource", () => {
expect(page.passwordCreate.exists()).toBeTruthy();
const createdResourceId = "f2b4047d-ab6d-4430-a1e2-3ab04a2f4fb9";
// create password
const resourceMeta = defaultResourceMeta();
const resourceMeta = defaultResourceMetadataDto();
const resourcePassword = "RN9n8XuECN3";

// Fill the form
Expand Down Expand Up @@ -212,7 +215,7 @@ describe("See the Create Resource", () => {
const createdResourceId = "f2b4047d-ab6d-4430-a1e2-3ab04a2f4fb9";

// create password
const resourceMeta = defaultResourceMeta();
const resourceMeta = defaultResourceMetadataDto();
const resourcePassword = "RN9n8XuECN3";

// Fill the form
Expand Down Expand Up @@ -347,7 +350,7 @@ describe("See the Create Resource", () => {

expect(page.passwordCreate.exists()).toBeTruthy();
// create password
const resourceMeta = defaultResourceMeta({
const resourceMeta = defaultResourceMetadataDto({
uris: [""],
username: "",
description: ""
Expand Down Expand Up @@ -509,7 +512,7 @@ describe("See the Create Resource", () => {

expect(page.passwordCreate.exists()).toBeTruthy();
// create password
const resourceMeta = defaultResourceMeta({
const resourceMeta = defaultResourceMetadataDto({
uris: [""],
username: "",
description: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import {
import ColumnsResourceSettingCollection
from "../../../../shared/models/entity/resource/columnsResourceSettingCollection";
import {defaultPasswordExpirySettingsContext} from "../../../contexts/PasswordExpirySettingsContext.test.data";
import {
defaultResourceMetadataDto
} from "../../../../shared/models/entity/resourceMetadata/resourceMetadataEntity.test.data";
import {
TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP,
TEST_RESOURCE_TYPE_TOTP
} from "../../../../shared/models/entity/resourceType/resourceTypeEntity.test.data";

/**
* Default props as when initializing the list with no content.
Expand All @@ -46,12 +53,12 @@ export function defaultProps(data = {}) {
* @returns {array}
*/
const getResources = () => [
resourceWithFavoriteDto({name: 'apache'}),
defaultResourceDto({name: 'bower'}),
defaultResourceDto({name: 'test'}),
resourceWithTotpDto({name: 'totp'}),
resourceStandaloneTotpDto({name: 'standalone totp'}),
defaultResourceDto({name: 'will-expire', expired: "3023-12-25T00:00:00.000Z"}),
resourceWithFavoriteDto({metadata: defaultResourceMetadataDto({name: 'apache'})}),
defaultResourceDto({metadata: defaultResourceMetadataDto({name: 'bower'})}),
defaultResourceDto({metadata: defaultResourceMetadataDto({name: 'test'})}),
resourceWithTotpDto({metadata: defaultResourceMetadataDto({name: 'totp', resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP})}),
resourceStandaloneTotpDto({metadata: defaultResourceMetadataDto({name: 'standalone totp', resource_type_id: TEST_RESOURCE_TYPE_TOTP})}),
defaultResourceDto({metadata: defaultResourceMetadataDto({name: 'will-expire'}), expired: "3023-12-25T00:00:00.000Z"}),
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("DisplayResourcesListContextualMenu", () => {
it('As LU I can start to copy the username of a resource', async() => {
expect.assertions(3);
await page.copyUsername();
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(props.resource.username);
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(props.resource.metadata.username);
expect(ActionFeedbackContext._currentValue.displaySuccess).toHaveBeenCalled();
expect(props.hide).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {waitFor} from "@testing-library/react";
import {defaultProps, defaultPropsLegacyResource} from "./EditResource.test.data";
import EditResourcePage from "./EditResource.test.page";
import {
TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION, TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP, TEST_RESOURCE_TYPE_PASSWORD_STRING
TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION,
TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP,
TEST_RESOURCE_TYPE_PASSWORD_STRING
} from "../../../../shared/models/entity/resourceType/resourceTypeEntity.test.data";
import {waitForTrue} from "../../../../../test/utils/waitFor";
import {defaultUserAppContext} from "../../../contexts/ExtAppContext.test.data";
Expand Down Expand Up @@ -68,17 +70,17 @@ describe("See the Edit Resource", () => {
// Dialog title exists and correct
expect(page.passwordEdit.exists()).toBeTruthy();
expect(page.title.header.textContent).toBe("Edit resource");
expect(page.title.subtitle.textContent).toBe(resource.name);
expect(page.title.subtitle.textContent).toBe(resource.metadata.name);

// Close button exists
expect(page.passwordEdit.dialogClose).not.toBeNull();

// Name input field exists.
expect(page.passwordEdit.name.value).toBe(resource.name);
expect(page.passwordEdit.name.value).toBe(resource.metadata.name);
// Uri input field exists.
expect(page.passwordEdit.uri.value).toBe(resource.uri);
expect(page.passwordEdit.uri.value).toBe(resource.metadata.uris[0]);
// Username input field exists.
expect(page.passwordEdit.username.value).toBe(resource.username);
expect(page.passwordEdit.username.value).toBe(resource.metadata.username);
// Password input field exists
expect(page.passwordEdit.password).not.toBeNull();
expect(page.passwordEdit.password.value).toBe("");
Expand All @@ -99,7 +101,7 @@ describe("See the Edit Resource", () => {
expect(page.passwordEdit.passwordGenerateButton).not.toBeNull();

// Description textarea field exists
expect(page.passwordEdit.description.value).toBe(resource.description);
expect(page.passwordEdit.description.value).toBe(resource.metadata.description);

// Add totp button exists
expect(page.passwordEdit.addTotpButton).not.toBeNull();
Expand Down Expand Up @@ -298,8 +300,8 @@ describe("See the Edit Resource", () => {
metadata: {
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION,
name: resourceMeta.name,
uris: [resource.uri],
username: resource.username,
uris: resource.metadata.uris,
username: resource.metadata.username,
description: "",
},
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION
Expand Down Expand Up @@ -334,8 +336,8 @@ describe("See the Edit Resource", () => {
id: resource.id,
metadata: {
name: resourceMeta.name,
uris: [resource.uri],
username: resource.username,
uris: resource.metadata.uris,
username: resource.metadata.username,
description: resourceMeta.description,
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_STRING
},
Expand Down Expand Up @@ -380,8 +382,8 @@ describe("See the Edit Resource", () => {
id: resource.id,
metadata: {
name: resourceMeta.name,
uris: [resource.uri],
username: resource.username,
uris: resource.metadata.uris,
username: resource.metadata.username,
description: "",
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP
},
Expand Down Expand Up @@ -620,7 +622,7 @@ describe("See the Edit Resource", () => {
expect(props.context.port.request).toHaveBeenNthCalledWith(1, "passbolt.secret.find-by-resource-id", resource.id);
expect(props.context.port.request).toHaveBeenNthCalledWith(2, "passbolt.secrets.powned-password", "secret-decrypted");
const confirmDialogProps = {
resourceName: resource.name,
resourceName: resource.metadata.name,
operation: ConfirmEditCreateOperationVariations.EDIT,
rule: ConfirmEditCreateRuleVariations.IN_DICTIONARY,
onConfirm: expect.any(Function),
Expand Down Expand Up @@ -650,7 +652,7 @@ describe("See the Edit Resource", () => {

expect(props.context.port.request).toHaveBeenNthCalledWith(1, "passbolt.secret.find-by-resource-id", resource.id);
const confirmDialogProps = {
resourceName: resource.name,
resourceName: resource.metadata.name,
operation: ConfirmEditCreateOperationVariations.EDIT,
rule: ConfirmEditCreateRuleVariations.MINIMUM_ENTROPY,
onConfirm: expect.any(Function),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ describe("See the Edit Standalone TOTP", () => {
expect(page.dialogClose).not.toBeNull();

// Name input field exists.
expect(page.name.value).toBe(props.resource.name);
expect(page.name.value).toBe(props.resource.metadata.name);
// Uri input field exists.
expect(page.uri.value).toBe(props.resource.uri);
expect(page.uri.value).toBe(props.resource.metadata.uris[0]);
// Username input field exists.
expect(page.secretKey.value).toBe(totp.secret_key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ describe("DisplayResourceDetailsInformation", () => {
expect.assertions(22);
await waitFor(() => {});
expect(page.displayInformationList.usernameLabel).toBe('Username');
expect(page.displayInformationList.username.textContent).toBe(props.resourceWorkspaceContext.details.resource.username);
expect(page.displayInformationList.username.textContent).toBe(props.resourceWorkspaceContext.details.resource.metadata.username);
expect(page.displayInformationList.passwordLabel).toBe('Password');
expect(page.displayInformationList.password.textContent).toBe("Copy password to clipboard");
expect(page.displayInformationList.totpLabel).toBe('TOTP');
expect(page.displayInformationList.totp.textContent).toBe("Copy TOTP to clipboard");
expect(page.displayInformationList.uriLabel).toBe('URI');
expect(page.displayInformationList.uri.textContent).toBe(props.resourceWorkspaceContext.details.resource.uri);
expect(page.displayInformationList.uri.textContent).toBe(props.resourceWorkspaceContext.details.resource.metadata.uris[0]);
expect(page.displayInformationList.modifiedLabel(1)).toBe('Modified');
expect(page.displayInformationList.modified(1).textContent).toBe(modificationDate);
expect(page.displayInformationList.modified(1).getAttribute("title")).toBe(absoluteModificationDate);
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("DisplayResourceDetailsInformation", () => {
await page.displayInformationList.click(page.displayInformationList.username);

expect.assertions(2);
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(props.resourceWorkspaceContext.details.resource.username);
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(props.resourceWorkspaceContext.details.resource.metadata.username);
expect(ActionFeedbackContext._currentValue.displaySuccess).toHaveBeenCalledWith("The username has been copied to clipboard");
});
});
Expand Down
Loading

0 comments on commit 2932644

Please sign in to comment.