Skip to content

Commit

Permalink
Roll out digest language to a composite fetcher #3239
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiosironi committed May 15, 2024
1 parent 3bf0964 commit e4f6ce4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable quote-props */
import { pipe } from 'fp-ts/function';
import { fetchAccessMicrobiologyEvaluation } from './access-microbiology';
import { fetchDoiEvaluationByPublisher } from './fetch-doi-evaluation-by-publisher';
import { fetchDoiEvaluationDigestByPublisher } from './fetch-doi-evaluation-digest-by-publisher';
import { fetchEvaluationFromAppropriateService } from './fetch-evaluation-from-appropriate-service';
import { fetchHypothesisAnnotation } from './hypothesis';
import { fetchNcrcReview } from './ncrc';
Expand All @@ -14,7 +14,7 @@ import { QueryExternalService } from '../query-external-service';

export const createFetchEvaluationDigest = (queryExternalService: QueryExternalService, logger: Logger): ExternalQueries['fetchEvaluationDigest'] => pipe(
{
doi: fetchDoiEvaluationByPublisher(
doi: fetchDoiEvaluationDigestByPublisher(
{
'10.5281': fetchZenodoRecord(queryExternalService, logger),
'10.1099': fetchAccessMicrobiologyEvaluation(queryExternalService, logger),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const deriveDoiPrefixFrom = (key: string) => pipe(
RNEA.head,
);

export const fetchDoiEvaluationByPublisher = (
export const fetchDoiEvaluationDigestByPublisher = (
evaluationFetchers: Record<string, EvaluationDigestFetcher>,
logger: Logger,
): EvaluationDigestFetcher => (key) => pipe(
evaluationFetchers,
R.lookup(deriveDoiPrefixFrom(key)),
O.match(
() => {
logger('warn', 'Attempt to fetch evaluation with an unknown DOI prefix', { key });
logger('warn', 'Attempt to fetch evaluation digest with an unknown DOI prefix', { key });
return TE.left(DE.unavailable);
},
(evaluationFetcher) => evaluationFetcher(key),
(evaluationDigestFetcher) => evaluationDigestFetcher(key),
),
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as E from 'fp-ts/Either';
import * as TE from 'fp-ts/TaskEither';
import { fetchDoiEvaluationByPublisher } from '../../../src/third-parties/fetch-evaluation-digest/fetch-doi-evaluation-by-publisher';
import { fetchDoiEvaluationDigestByPublisher } from '../../../src/third-parties/fetch-evaluation-digest/fetch-doi-evaluation-digest-by-publisher';
import * as DE from '../../../src/types/data-error';
import { SanitisedHtmlFragment } from '../../../src/types/sanitised-html-fragment';
import { dummyLogger } from '../../dummy-logger';
Expand All @@ -10,7 +10,7 @@ import { arbitraryDataError } from '../../types/data-error.helper';
const digest = arbitrarySanitisedHtmlFragment();
const arbitraryDoiPrefix = () => `10.${arbitraryNumber(1, 9999)}`;

describe('fetch-doi-evaluation-by-publisher', () => {
describe('fetch-doi-evaluation-digest-by-publisher', () => {
let result: E.Either<DE.DataError, SanitisedHtmlFragment>;

describe('when a doi with a configured prefix is passed in', () => {
Expand All @@ -22,7 +22,7 @@ describe('fetch-doi-evaluation-by-publisher', () => {
};

beforeEach(async () => {
result = await fetchDoiEvaluationByPublisher(evaluationFetchersConfiguration, dummyLogger)(`${configuredDoiPrefix}/123`)();
result = await fetchDoiEvaluationDigestByPublisher(evaluationFetchersConfiguration, dummyLogger)(`${configuredDoiPrefix}/123`)();
});

it('returns a right', () => {
Expand All @@ -37,7 +37,7 @@ describe('fetch-doi-evaluation-by-publisher', () => {
};

beforeEach(async () => {
result = await fetchDoiEvaluationByPublisher(evaluationFetchersConfiguration, dummyLogger)(`${configuredDoiPrefix}/123`)();
result = await fetchDoiEvaluationDigestByPublisher(evaluationFetchersConfiguration, dummyLogger)(`${configuredDoiPrefix}/123`)();
});

it('returns a left', () => {
Expand All @@ -53,7 +53,7 @@ describe('fetch-doi-evaluation-by-publisher', () => {
};

beforeEach(async () => {
result = await fetchDoiEvaluationByPublisher(evaluationFetchersConfiguration, dummyLogger)(`${unknownDoiPrefix}/123`)();
result = await fetchDoiEvaluationDigestByPublisher(evaluationFetchersConfiguration, dummyLogger)(`${unknownDoiPrefix}/123`)();
});

it('returns unavailable', () => {
Expand Down

0 comments on commit e4f6ce4

Please sign in to comment.