Skip to content

Commit

Permalink
Added: test case for unauthenticated getDataset call for deaccessioned
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Jan 4, 2024
1 parent 086b981 commit 46fe6d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/core/infra/repositories/ApiRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export abstract class ApiRepository {
requestConfig.withCredentials = true;
break;
case DataverseApiAuthMechanism.API_KEY:
requestConfig.headers['X-Dataverse-Key'] = ApiConfig.dataverseApiKey;
if (typeof ApiConfig.dataverseApiKey !== 'undefined') {
requestConfig.headers['X-Dataverse-Key'] = ApiConfig.dataverseApiKey;
}
break;
}
return requestConfig;
Expand Down
12 changes: 11 additions & 1 deletion test/integration/datasets/DatasetsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ describe('DatasetsRepository', () => {

const latestVersionId = DatasetNotNumberedVersion.LATEST;

beforeAll(async () => {
beforeEach(async () => {
ApiConfig.init(TestConstants.TEST_API_URL, DataverseApiAuthMechanism.API_KEY, process.env.TEST_API_KEY);
});

afterEach(async () => {
ApiConfig.init(TestConstants.TEST_API_URL, DataverseApiAuthMechanism.API_KEY, process.env.TEST_API_KEY);
});

Expand Down Expand Up @@ -107,6 +111,12 @@ describe('DatasetsRepository', () => {
expect(actual.id).toBe(TestConstants.TEST_CREATED_DATASET_2_ID);
});

test('should return dataset when it is deaccessioned, includeDeaccessioned param is set, and user is unauthenticated', async () => {
ApiConfig.init(TestConstants.TEST_API_URL, DataverseApiAuthMechanism.API_KEY, undefined);
const actual = await sut.getDataset(TestConstants.TEST_CREATED_DATASET_2_ID, latestVersionId, true);
expect(actual.id).toBe(TestConstants.TEST_CREATED_DATASET_2_ID);
});

test('should return error when dataset is deaccessioned and includeDeaccessioned param is not set', async () => {
let error: ReadError = undefined;
await sut.getDataset(TestConstants.TEST_CREATED_DATASET_2_ID, latestVersionId, false).catch((e) => (error = e));
Expand Down

0 comments on commit 46fe6d3

Please sign in to comment.