Skip to content

Commit

Permalink
EW-539 Add tests for metadata and organization elements
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneRadtke-Cap committed Dec 8, 2023
1 parent 8145128 commit a933e09
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { faker } from '@faker-js/faker';
import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums';
import {
CommonCartridgeMetadataElementPropsV110,
CommonCartridgeMetadataElementV110,
} from './common-cartridge-metadata-element';

describe('CommonCartridgeMetadataElementV110', () => {
const setup = () => {
const props: CommonCartridgeMetadataElementPropsV110 = {
type: CommonCartridgeElementType.METADATA,
version: CommonCartridgeVersion.V_1_1_0,
title: faker.lorem.words(),
creationDate: faker.date.past(),
copyrightOwners: [faker.person.fullName(), faker.person.fullName()],
};
const sut = new CommonCartridgeMetadataElementV110(props);

return { sut, props };
};

describe('getSupportedVersion', () => {
describe('when using Common Cartridge version 1.1.0', () => {
// AI next 5 lines
it('should return correct version', () => {
const { sut } = setup();
const result = sut.getSupportedVersion();

expect(result).toBe(CommonCartridgeVersion.V_1_1_0);
});
});
});

describe('getManifestXmlObject', () => {
describe('when using common cartridge version 1.1', () => {
it('should return correct manifest xml object', () => {
const { sut, props } = setup();
const result = sut.getManifestXmlObject();

expect(result).toStrictEqual({
schema: 'IMS Common Cartridge',
schemaversion: '1.1.0',
'mnf:lom': {
'mnf:general': {
'mnf:title': {
'mnf:string': props.title,
},
},
'mnf:rights': {
'mnf:copyrightAndOtherRestrictions': {
'mnf:value': 'yes',
},
'mnf:description': {
'mnf:string': `${props.creationDate.getFullYear()} ${props.copyrightOwners.join(', ')}`,
},
},
},
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { faker } from '@faker-js/faker';
import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums';
import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface';
import {
CommonCartridgeOrganizationElementPropsV110,
CommonCartridgeOrganizationElementV110,
} from './common-cartridge-organization-element';

describe('CommonCartridgeOrganizationElementV110', () => {
const setup = () => {
const item: CommonCartridgeElement = {
getManifestXmlObject: () => {
return {
$: {
identifier: faker.string.uuid(),
},
title: faker.lorem.words(),
};
},
getSupportedVersion: () => CommonCartridgeVersion.V_1_1_0,
checkVersion: () => CommonCartridgeVersion.V_1_1_0,
};

const props: CommonCartridgeOrganizationElementPropsV110 = {
type: CommonCartridgeElementType.ORGANIZATION,
version: CommonCartridgeVersion.V_1_1_0,
identifier: faker.string.uuid(),
title: faker.lorem.words(),
items: [item],
};
const sut = new CommonCartridgeOrganizationElementV110(props);

return { sut, props };
};

describe('getSupportedVersion', () => {
describe('when using common cartridge version 1.1.0', () => {
it('should return correct version', () => {
const { sut } = setup();
const result = sut.getSupportedVersion();

expect(result).toBe(CommonCartridgeVersion.V_1_1_0);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { faker } from '@faker-js/faker';
import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums';
import {
CommonCartridgeMetadataElementPropsV130,
CommonCartridgeMetadataElementV130,
} from './common-cartridge-metadata-element';

describe('CommonCartridgeMetadataElementV130', () => {
const setup = () => {
const props: CommonCartridgeMetadataElementPropsV130 = {
type: CommonCartridgeElementType.METADATA,
version: CommonCartridgeVersion.V_1_3_0,
title: faker.lorem.words(),
creationDate: faker.date.past(),
copyrightOwners: [faker.person.fullName(), faker.person.fullName()],
};
const sut = new CommonCartridgeMetadataElementV130(props);

return { sut, props };
};

describe('getSupportedVersion', () => {
describe('when using Common Cartridge version 1.3.0', () => {
it('should return correct version', () => {
const { sut } = setup();
const result = sut.getSupportedVersion();

expect(result).toBe(CommonCartridgeVersion.V_1_3_0);
});
});
});

describe('getManifestXmlObject', () => {
describe('when using common cartridge version 1.3', () => {
it('should return correct manifest xml object', () => {
const { sut, props } = setup();
const result = sut.getManifestXmlObject();

expect(result).toStrictEqual({
schema: 'IMS Common Cartridge',
schemaversion: '1.3.0',
'mnf:lom': {
'mnf:general': {
'mnf:title': {
'mnf:string': props.title,
},
},
'mnf:rights': {
'mnf:copyrightAndOtherRestrictions': {
'mnf:value': 'yes',
},
'mnf:description': {
'mnf:string': `${props.creationDate.getFullYear()} ${props.copyrightOwners.join(', ')}`,
},
},
},
});
});
});
});
});

0 comments on commit a933e09

Please sign in to comment.