-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EW-539 Add tests for metadata and organization elements
- Loading branch information
1 parent
8145128
commit a933e09
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...ules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(', ')}`, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
.../learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
...ules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(', ')}`, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |