-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '90-file-counts-criteria' into 94-total-file-download-si…
…ze-with-criteria
- Loading branch information
Showing
11 changed files
with
296 additions
and
43 deletions.
There are no files selected for viewing
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
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,14 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase'; | ||
import { IDataverseInfoRepository } from '../repositories/IDataverseInfoRepository'; | ||
|
||
export class GetMaxEmbargoDurationInMonths implements UseCase<number> { | ||
private dataverseInfoRepository: IDataverseInfoRepository; | ||
|
||
constructor(dataverseInfoRepository: IDataverseInfoRepository) { | ||
this.dataverseInfoRepository = dataverseInfoRepository; | ||
} | ||
|
||
async execute(): Promise<number> { | ||
return await this.dataverseInfoRepository.getMaxEmbargoDurationInMonths(); | ||
} | ||
} |
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,14 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase'; | ||
import { IDataverseInfoRepository } from '../repositories/IDataverseInfoRepository'; | ||
|
||
export class GetZipDownloadLimit implements UseCase<number> { | ||
private dataverseInfoRepository: IDataverseInfoRepository; | ||
|
||
constructor(dataverseInfoRepository: IDataverseInfoRepository) { | ||
this.dataverseInfoRepository = dataverseInfoRepository; | ||
} | ||
|
||
async execute(): Promise<number> { | ||
return await this.dataverseInfoRepository.getZipDownloadLimit(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { DataverseInfoRepository } from './infra/repositories/DataverseInfoRepository'; | ||
import { GetDataverseVersion } from './domain/useCases/GetDataverseVersion'; | ||
import { GetZipDownloadLimit } from './domain/useCases/GetZipDownloadLimit'; | ||
import { GetMaxEmbargoDurationInMonths } from './domain/useCases/GetMaxEmbargoDurationInMonths'; | ||
|
||
const getDataverseVersion = new GetDataverseVersion(new DataverseInfoRepository()); | ||
const dataverseInfoRepository = new DataverseInfoRepository(); | ||
|
||
export { getDataverseVersion }; | ||
const getDataverseVersion = new GetDataverseVersion(dataverseInfoRepository); | ||
const getZipDownloadLimit = new GetZipDownloadLimit(dataverseInfoRepository); | ||
const getMaxEmbargoDurationInMonths = new GetMaxEmbargoDurationInMonths(dataverseInfoRepository); | ||
|
||
export { getDataverseVersion, getZipDownloadLimit, getMaxEmbargoDurationInMonths }; |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
POSTGRES_VERSION=13 | ||
DATAVERSE_DB_USER=dataverse | ||
SOLR_VERSION=9.3.0 | ||
DATAVERSE_IMAGE_REGISTRY=ghcr.io | ||
DATAVERSE_IMAGE_TAG=9995-file-total-download-size-criteria | ||
DATAVERSE_IMAGE_REGISTRY=docker.io | ||
DATAVERSE_IMAGE_TAG=unstable | ||
DATAVERSE_BOOTSTRAP_TIMEOUT=5m |
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 |
---|---|---|
@@ -1,14 +1,51 @@ | ||
import { DataverseInfoRepository } from '../../../src/info/infra/repositories/DataverseInfoRepository'; | ||
import { ApiConfig, DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'; | ||
import { TestConstants } from '../../testHelpers/TestConstants'; | ||
import { setMaxEmbargoDurationInMonthsViaApi } from '../../testHelpers/info/infoHelper'; | ||
import { ReadError } from '../../../src/core/domain/repositories/ReadError'; | ||
import { assert } from 'sinon'; | ||
import { fail } from 'assert'; | ||
|
||
describe('getDataverseVersion', () => { | ||
describe('DataverseInfoRepository', () => { | ||
const sut: DataverseInfoRepository = new DataverseInfoRepository(); | ||
|
||
ApiConfig.init(TestConstants.TEST_API_URL, DataverseApiAuthMechanism.API_KEY); | ||
beforeAll(async () => { | ||
ApiConfig.init(TestConstants.TEST_API_URL, DataverseApiAuthMechanism.API_KEY, process.env.TEST_API_KEY); | ||
}); | ||
|
||
describe('getDataverseVersion', () => { | ||
test('should return Dataverse version', async () => { | ||
const actual = await sut.getDataverseVersion(); | ||
expect(typeof actual.number).toBe('string'); | ||
}); | ||
}); | ||
|
||
describe('getZipDownloadLimit', () => { | ||
test('should return zip download limit', async () => { | ||
const actual = await sut.getZipDownloadLimit(); | ||
expect(typeof actual).toBe('number'); | ||
}); | ||
}); | ||
|
||
describe('getMaxEmbargoDurationInMonths', () => { | ||
test('should return error when the setting does not exist', async () => { | ||
let error: ReadError = undefined; | ||
await sut.getMaxEmbargoDurationInMonths().catch((e) => (error = e)); | ||
assert.match( | ||
error.message, | ||
'There was an error when reading the resource. Reason was: [404] Setting :MaxEmbargoDurationInMonths not found', | ||
); | ||
}); | ||
|
||
test('should return Dataverse version', async () => { | ||
const actual = await sut.getDataverseVersion(); | ||
expect(typeof actual.number).toBe('string'); | ||
test('should return duration when the setting exists', async () => { | ||
const testMaxEmbargoDurationInMonths = 12; | ||
await setMaxEmbargoDurationInMonthsViaApi(testMaxEmbargoDurationInMonths) | ||
.then() | ||
.catch(() => { | ||
fail('Test getMaxEmbargoDurationInMonths: Error while setting :MaxEmbargoDurationInMonths'); | ||
}); | ||
const actual = await sut.getMaxEmbargoDurationInMonths(); | ||
assert.match(actual, testMaxEmbargoDurationInMonths); | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
import axios, { AxiosResponse } from 'axios'; | ||
import { TestConstants } from '../TestConstants'; | ||
|
||
export const setMaxEmbargoDurationInMonthsViaApi = async ( | ||
maxEmbargoDurationInMonths: number, | ||
): Promise<AxiosResponse> => { | ||
return await axios.put( | ||
`${TestConstants.TEST_API_URL}/admin/settings/:MaxEmbargoDurationInMonths`, | ||
maxEmbargoDurationInMonths.toString(), | ||
{ | ||
headers: { 'Content-Type': 'text/plain' }, | ||
}, | ||
); | ||
}; |
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
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,35 @@ | ||
import { GetMaxEmbargoDurationInMonths } from '../../../src/info/domain/useCases/GetMaxEmbargoDurationInMonths'; | ||
import { IDataverseInfoRepository } from '../../../src/info/domain/repositories/IDataverseInfoRepository'; | ||
import { ReadError } from '../../../src/core/domain/repositories/ReadError'; | ||
import { assert, createSandbox, SinonSandbox } from 'sinon'; | ||
|
||
describe('execute', () => { | ||
const sandbox: SinonSandbox = createSandbox(); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
test('should return duration on repository success', async () => { | ||
const testDuration = 12; | ||
const dataverseInfoRepositoryStub = <IDataverseInfoRepository>{}; | ||
dataverseInfoRepositoryStub.getMaxEmbargoDurationInMonths = sandbox.stub().returns(testDuration); | ||
const sut = new GetMaxEmbargoDurationInMonths(dataverseInfoRepositoryStub); | ||
|
||
const actual = await sut.execute(); | ||
|
||
assert.match(actual, testDuration); | ||
}); | ||
|
||
test('should return error result on repository error', async () => { | ||
const dataverseInfoRepositoryStub = <IDataverseInfoRepository>{}; | ||
const testReadError = new ReadError(); | ||
dataverseInfoRepositoryStub.getMaxEmbargoDurationInMonths = sandbox.stub().throwsException(testReadError); | ||
const sut = new GetMaxEmbargoDurationInMonths(dataverseInfoRepositoryStub); | ||
|
||
let actualError: ReadError = undefined; | ||
await sut.execute().catch((e) => (actualError = e)); | ||
|
||
assert.match(actualError, testReadError); | ||
}); | ||
}); |
Oops, something went wrong.