Skip to content

Commit

Permalink
feat(coverage): add some tests to reach coverage check
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Feb 8, 2024
1 parent 0705808 commit 3a701bd
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 6 deletions.
20 changes: 18 additions & 2 deletions test/testHelpers/datasets/datasetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const DATAVERSE_API_REQUEST_HEADERS = {
headers: { 'Content-Type': 'application/json', 'X-Dataverse-Key': process.env.TEST_API_KEY }
}

export const createDatasetModel = (license?: DatasetLicense): Dataset => {
export const createDatasetModel = (
license?: DatasetLicense,
addOptionalParameters = false
): Dataset => {
const datasetModel: Dataset = {
id: 1,
persistentId: 'doi:10.5072/FK2/HC6KTB',
Expand Down Expand Up @@ -70,11 +73,19 @@ export const createDatasetModel = (license?: DatasetLicense): Dataset => {
if (license !== undefined) {
datasetModel.license = license
}
if (addOptionalParameters) {
datasetModel.alternativePersistentId = 'doi:10.5072/FK2/HC6KTB'
datasetModel.publicationDate = '2021-01-01'
datasetModel.citationDate = '2021-01-01'
}
return datasetModel
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const createDatasetVersionPayload = (license?: DatasetLicense): any => {
export const createDatasetVersionPayload = (
license?: DatasetLicense,
addOptionalProperties = false
): any => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const datasetPayload: any = {
id: 19,
Expand Down Expand Up @@ -182,6 +193,11 @@ export const createDatasetVersionPayload = (license?: DatasetLicense): any => {
if (license !== undefined) {
datasetPayload.license = license
}
if (addOptionalProperties) {
datasetPayload.alternativePersistentId = 'doi:10.5072/FK2/HC6KTB'
datasetPayload.publicationDate = '2021-01-01'
datasetPayload.citationDate = '2021-01-01'
}
return datasetPayload
}

Expand Down
108 changes: 104 additions & 4 deletions test/testHelpers/files/fileDataTablesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const createFileDataTableModel = (): FileDataTable => {
varQuantity: 21,
caseQuantity: 122,
UNF: 'UNF:6:awd/lz8bNdoXn8f1sjAAAQ==',
recordsPerCase: 1,
dataVariables: [
{
id: 3,
Expand All @@ -25,7 +26,36 @@ export const createFileDataTableModel = (): FileDataTable => {
medn: '28.27591',
mode: '.',
min: '27.6741'
}
},
formatCategory: 'Character',
format: 'A',
fileStartPosition: 1,
fileEndPosition: 1,
recordSegmentNumber: 1,
numberOfDecimalPoints: 1,
invalidRanges: [
{
beginValue: '1',
endValue: '2',
hasBeginValueType: false,
isBeginValueTypeMax: false,
hasEndValueType: false,
isBeginValueTypePoint: false,
isBeginValueTypeMin: false,
isBeginValueTypeMinExcl: false,
isBeginValueTypeMaxExcl: false,
endValueTypeMax: false,
endValueTypeMaxExcl: false
}
],
variableCategories: [
{
label: 'test1',
value: 'test1',
frequency: 10,
isMissing: false
}
]
},
{
id: 15,
Expand All @@ -37,7 +67,27 @@ export const createFileDataTableModel = (): FileDataTable => {
isOrderedCategorical: false,
fileOrder: 1,
UNF: 'UNF:6:KPoFCWSEsLpy11Lh11CXWQ==',
variableMetadata: []
variableMetadata: [
{
id: 1,
label: 'test1',
metadataId: 1,
isWeighted: false,
isWeightVar: false,
weightVariableId: 1,
literalQuestion: 'test1',
interviewInstruction: 'test1',
postQuestion: 'test1',
universe: 'test1',
notes: 'test1',
categoryMetadatas: [
{
categoryValue: 'test1',
wFreq: 1
}
]
}
]
}
]
}
Expand All @@ -49,6 +99,7 @@ export const createFileDataTablePayload = (): any => {
varQuantity: 21,
caseQuantity: 122,
UNF: 'UNF:6:awd/lz8bNdoXn8f1sjAAAQ==',
recordsPerCase: 1,
dataVariables: [
{
id: 3,
Expand All @@ -65,7 +116,36 @@ export const createFileDataTablePayload = (): any => {
medn: '28.27591',
mode: '.',
min: '27.6741'
}
},
formatCategory: 'Character',
format: 'A',
fileStartPosition: 1,
fileEndPosition: 1,
recordSegmentNumber: 1,
numberOfDecimalPoints: 1,
invalidRanges: [
{
beginValue: '1',
endValue: '2',
hasBeginValueType: false,
isBeginValueTypeMax: false,
hasEndValueType: false,
isBeginValueTypePoint: false,
isBeginValueTypeMin: false,
isBeginValueTypeMinExcl: false,
isBeginValueTypeMaxExcl: false,
endValueTypeMax: false,
endValueTypeMaxExcl: false
}
],
variableCategories: [
{
label: 'test1',
value: 'test1',
frequency: 10,
isMissing: false
}
]
},
{
id: 15,
Expand All @@ -77,7 +157,27 @@ export const createFileDataTablePayload = (): any => {
isOrderedCategorical: false,
fileOrder: 1,
UNF: 'UNF:6:KPoFCWSEsLpy11Lh11CXWQ==',
variableMetadata: []
variableMetadata: [
{
id: 1,
label: 'test1',
metadataId: 1,
isWeighted: false,
isWeightVar: false,
weightVariableId: 1,
literalQuestion: 'test1',
interviewInstruction: 'test1',
postQuestion: 'test1',
universe: 'test1',
notes: 'test1',
categoryMetadatas: [
{
categoryValue: 'test1',
wFreq: 1
}
]
}
]
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions test/testHelpers/files/filesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const createFileModel = (): File => {
version: 1,
restricted: false,
latestRestricted: false,
description: 'some description',
originalSize: 127426,
originalName: 'test.png',
tabularTags: [],
contentType: 'image/png',
friendlyType: 'PNG Image',
storageIdentifier: 'local://18945a85439-9fa52783e5cb',
Expand Down Expand Up @@ -61,6 +65,10 @@ export const createFilePayload = (): any => {
id: 1,
persistentId: '',
filename: 'test',
description: 'some description',
originalSize: 127426,
originalName: 'test.png',
tabularTags: [],
contentType: 'image/png',
friendlyType: 'PNG Image',
filesize: 127426,
Expand Down
26 changes: 26 additions & 0 deletions test/unit/datasets/DatasetsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,32 @@ describe('DatasetsRepository', () => {
expect(actual).toStrictEqual(createDatasetModel(testDatasetLicenseWithoutIconUri))
})

test('should return dataset with alternative persistent id, publication date and citation date when they are present in the response', async () => {
const testDatasetVersionWithAlternativePersistentIdAndDatesSuccessfulResponse = {
data: {
status: 'OK',
data: createDatasetVersionPayload(undefined, true)
}
}
jest
.spyOn(axios, 'get')
.mockResolvedValue(
testDatasetVersionWithAlternativePersistentIdAndDatesSuccessfulResponse
)

const actual = await sut.getDataset(
testDatasetModel.id,
testVersionId,
testIncludeDeaccessioned
)

expect(axios.get).toHaveBeenCalledWith(
`${TestConstants.TEST_API_URL}/datasets/${testDatasetModel.id}/versions/${testVersionId}`,
expectedRequestConfigApiKey
)
expect(actual).toStrictEqual(createDatasetModel(undefined, true))
})

test('should return error on repository read error', async () => {
jest.spyOn(axios, 'get').mockRejectedValue(TestConstants.TEST_ERROR_RESPONSE)

Expand Down

0 comments on commit 3a701bd

Please sign in to comment.