Skip to content

Commit

Permalink
EW-793 Extend test factories to reduce code duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneRadtke-Cap committed May 27, 2024
1 parent 1ff4491 commit eedfeec
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { faker } from '@faker-js/faker';
import { createMock } from '@golevelup/ts-jest';
import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory';
import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory';
import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums';
import { CommonCartridgeElement } from '../interfaces';
import {
CommonCartridgeOrganizationNode,
CommonCartridgeOrganizationNodeProps,
} from './common-cartridge-organization-node';
import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node';
import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder';

describe('CommonCartridgeOrganizationNode', () => {
const setupOrganizationNodeProps = () => {
const props: CommonCartridgeOrganizationNodeProps = {
type: CommonCartridgeElementType.ORGANIZATION,
version: CommonCartridgeVersion.V_1_1_0,
identifier: faker.string.uuid(),
title: faker.lorem.words(),
};
const props = createCommonCartridgeOrganizationNodeProps();

return props;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { faker } from '@faker-js/faker';
import { createMock } from '@golevelup/ts-jest';
import {
CommonCartridgeElementType,
CommonCartridgeIntendedUseType,
CommonCartridgeResourceType,
CommonCartridgeVersion,
} from '../common-cartridge.enums';
import {
CommonCartridgeOrganizationNode,
CommonCartridgeOrganizationNodeProps,
} from './common-cartridge-organization-node';
import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory';
import { createCommonCartridgeWebContentResourceProps } from '../../testing/common-cartridge-resource-props.factory';
import { CommonCartridgeVersion } from '../common-cartridge.enums';
import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node';
import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder';
import { CommonCartridgeResourceNode, CommonCartridgeResourceNodeProps } from './common-cartridge-resource-node';

Expand All @@ -18,19 +11,10 @@ describe('CommonCartridgeResourceCollectionBuilder', () => {

const setupResourceNode = () => {
const resourceNodeProps: CommonCartridgeResourceNodeProps = {
type: CommonCartridgeResourceType.WEB_CONTENT,
identifier: faker.string.uuid(),
title: faker.lorem.words(),
html: faker.lorem.paragraph(),
intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED,
...createCommonCartridgeWebContentResourceProps(),
version: CommonCartridgeVersion.V_1_1_0,
};
const organizationNodeProps: CommonCartridgeOrganizationNodeProps = {
identifier: faker.string.uuid(),
title: faker.lorem.words(),
version: CommonCartridgeVersion.V_1_1_0,
type: CommonCartridgeElementType.ORGANIZATION,
};
const organizationNodeProps = createCommonCartridgeOrganizationNodeProps();
const organizationNode = new CommonCartridgeOrganizationNode(organizationNodeProps, sut, null);
const resourceNode = new CommonCartridgeResourceNode(resourceNodeProps, organizationNode);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { faker } from '@faker-js/faker';
import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory';
import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory';
import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums';
import { CommonCartridgeVersion } from '../common-cartridge.enums';
import { CommonCartridgeResource } from '../interfaces';
import {
CommonCartridgeOrganizationNode,
CommonCartridgeOrganizationNodeProps,
} from './common-cartridge-organization-node';
import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node';
import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder';
import { CommonCartridgeResourceNode, CommonCartridgeResourceNodeProps } from './common-cartridge-resource-node';

Expand All @@ -20,12 +17,7 @@ describe('CommonCartridgeResourceNode', () => {
version: CommonCartridgeVersion.V_1_1_0,
};

const organizationNodeProps: CommonCartridgeOrganizationNodeProps = {
identifier: faker.string.uuid(),
title: faker.lorem.words(),
version: CommonCartridgeVersion.V_1_1_0,
type: CommonCartridgeElementType.ORGANIZATION,
};
const organizationNodeProps = createCommonCartridgeOrganizationNodeProps();

const resourceCollectionBuilder: CommonCartridgeResourceCollectionBuilder =
new CommonCartridgeResourceCollectionBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { faker } from '@faker-js/faker';
import { CommonCartridgeOrganizationNodeProps } from '../export/builders/common-cartridge-organization-node';
import { CommonCartridgeElementType, CommonCartridgeVersion } from '../export/common-cartridge.enums';

export function createCommonCartridgeOrganizationNodeProps(): CommonCartridgeOrganizationNodeProps {
return {
type: CommonCartridgeElementType.ORGANIZATION,
identifier: faker.string.uuid(),
title: faker.lorem.words(),
version: CommonCartridgeVersion.V_1_1_0,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ export function createCommonCartridgeWebLinkResourceProps(): CommonCartridgeReso
url: faker.internet.url(),
};
}

export function createCommonCartridgeWebContentResourceProps(): CommonCartridgeResourceProps {
return {
type: CommonCartridgeResourceType.WEB_CONTENT,
title: faker.lorem.words(),
identifier: faker.string.uuid(),
html: faker.lorem.paragraph(),
intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED,
};
}

0 comments on commit eedfeec

Please sign in to comment.