Skip to content

Commit

Permalink
Introduce and rollout arbitraryUrl #3239
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiosironi committed May 14, 2024
1 parent e8b10a5 commit 407cdf0
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
5 changes: 2 additions & 3 deletions test/docmaps/docmap/construct-docmap-view-model.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { URL } from 'url';
import * as E from 'fp-ts/Either';
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
Expand All @@ -8,7 +7,7 @@ import { toExpressionDoi } from '../../../src/types/article-id';
import * as DE from '../../../src/types/data-error';
import { RecordEvaluationPublicationCommand } from '../../../src/write-side/commands';
import { TestFramework, createTestFramework } from '../../framework';
import { arbitraryUri } from '../../helpers';
import { arbitraryUrl } from '../../helpers';
import { arbitraryArticleId } from '../../types/article-id.helper';
import { arbitraryDataError } from '../../types/data-error.helper';
import { arbitraryEvaluationLocator } from '../../types/evaluation-locator.helper';
Expand Down Expand Up @@ -56,7 +55,7 @@ describe('construct-docmap-view-model', () => {
});

describe('when we can fetch a human readable original url for the evaluations', () => {
const humanReadableOriginalUrl = new URL(arbitraryUri());
const humanReadableOriginalUrl = arbitraryUrl();

beforeEach(async () => {
viewModel = await pipe(
Expand Down
10 changes: 6 additions & 4 deletions test/docmaps/docmap/render-docmap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { anonymous } from '../../../src/docmaps/docmap/peer-reviewer';
import { publisherAccountId } from '../../../src/docmaps/docmap/publisher-account-id';
import { renderDocmap } from '../../../src/docmaps/docmap/render-docmap';
import { ExpressionDoi } from '../../../src/types/expression-doi';
import { arbitraryDate, arbitraryString, arbitraryUri } from '../../helpers';
import {
arbitraryDate, arbitraryString, arbitraryUrl,
} from '../../helpers';
import { arbitraryEvaluationLocator } from '../../types/evaluation-locator.helper';
import { arbitraryExpressionDoi } from '../../types/expression-doi.helper';
import { arbitraryGroup } from '../../types/group.helper';
Expand Down Expand Up @@ -40,14 +42,14 @@ describe('render-docmap', () => {
group,
evaluations: [
{
sourceUrl: new URL(arbitraryUri()),
sourceUrl: arbitraryUrl(),
evaluationLocator: arbitraryEvaluationLocator(),
recordedAt: earlierEvaluationRecordedDate,
publishedAt: arbitraryDate(),
authors: [],
},
{
sourceUrl: new URL(arbitraryUri()),
sourceUrl: arbitraryUrl(),
evaluationLocator: arbitraryEvaluationLocator(),
recordedAt: laterEvaluationRecordedDate,
publishedAt: arbitraryDate(),
Expand All @@ -63,7 +65,7 @@ describe('render-docmap', () => {
group,
evaluations: [
{
sourceUrl: new URL(arbitraryUri()),
sourceUrl: arbitraryUrl(),
evaluationLocator: arbitraryEvaluationLocator(),
recordedAt: arbitraryDate(),
publishedAt: arbitraryDate(),
Expand Down
7 changes: 3 additions & 4 deletions test/framework/happy-path-third-party-adapters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { URL } from 'url';
import * as E from 'fp-ts/Either';
import * as O from 'fp-ts/Option';
import * as T from 'fp-ts/Task';
Expand All @@ -12,7 +11,7 @@ import { toHtmlFragment } from '../../src/types/html-fragment';
import * as PH from '../../src/types/publishing-history';
import { sanitise } from '../../src/types/sanitised-html-fragment';
import {
arbitraryDate, arbitrarySanitisedHtmlFragment, arbitraryString, arbitraryUri, arbitraryWord,
arbitraryDate, arbitrarySanitisedHtmlFragment, arbitraryString, arbitraryUrl, arbitraryWord,
} from '../helpers';
import { arbitraryArticleServer } from '../types/article-server.helper';
import { arbitraryExpressionDoi } from '../types/expression-doi.helper';
Expand All @@ -27,7 +26,7 @@ export const createHappyPathThirdPartyAdapters = (): HappyPathThirdPartyAdapters
abstract: O.some(sanitise(toHtmlFragment(arbitraryString()))),
server: 'biorxiv' as ArticleServer,
}),
fetchEvaluationHumanReadableOriginalUrl: () => TE.right(new URL(arbitraryUri())),
fetchEvaluationHumanReadableOriginalUrl: () => TE.right(arbitraryUrl()),
fetchRecommendedPapers: () => TE.right([
arbitraryExpressionDoi(),
arbitraryExpressionDoi(),
Expand All @@ -42,7 +41,7 @@ export const createHappyPathThirdPartyAdapters = (): HappyPathThirdPartyAdapters
{
expressionType: 'preprint',
expressionDoi,
publisherHtmlUrl: new URL(arbitraryUri()),
publisherHtmlUrl: arbitraryUrl(),
publishedAt: arbitraryDate(),
publishedTo: arbitraryWord(),
server: O.some(arbitraryArticleServer()),
Expand Down
3 changes: 3 additions & 0 deletions test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { URL } from 'url';
import * as A from 'fp-ts/Array';
import { pipe } from 'fp-ts/function';
import { HtmlFragment, toHtmlFragment } from '../src/types/html-fragment';
Expand Down Expand Up @@ -33,6 +34,8 @@ export const arbitrarySanitisedHtmlFragment = (): SanitisedHtmlFragment => pipe(

export const arbitraryUri = (): string => `http://localhost/${arbitraryWord()}`;

export const arbitraryUrl = (): URL => new URL(arbitraryUri());

export const arbitraryTextLongerThan = (min: number): string => 'xy '.repeat(min);

export const arbitraryDate = (): Date => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { URL } from 'url';
import * as O from 'fp-ts/Option';
import { pipe } from 'fp-ts/function';
import { feedSummary } from '../../../../../src/read-side/html-pages/paper-activity-page/construct-view-model/feed-summary';
import { ExpressionPublishedFeedItem } from '../../../../../src/read-side/html-pages/paper-activity-page/view-model';
import { arbitraryDate, arbitraryString, arbitraryUri } from '../../../../helpers';
import {
arbitraryDate, arbitraryString, arbitraryUrl,
} from '../../../../helpers';
import { arbitraryExpressionDoi } from '../../../../types/expression-doi.helper';
import * as RFI from '../evaluation-feed-item.helper';

const arbitraryPaperExpressionFeedItem = (publishedAt: Date = arbitraryDate()): ExpressionPublishedFeedItem => ({
type: 'expression-published' as const,
source: new URL(arbitraryUri()),
source: arbitraryUrl(),
publishedAt,
server: O.some('biorxiv' as const),
doi: arbitraryExpressionDoi(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { URL } from 'url';
import * as O from 'fp-ts/Option';
import * as T from 'fp-ts/Task';
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
import { toEvaluationPublishedFeedItem } from '../../../../../src/read-side/html-pages/paper-activity-page/construct-view-model/to-evaluation-published-feed-item';
import { EvaluationPublishedFeedItem } from '../../../../../src/read-side/html-pages/paper-activity-page/view-model';
import { TestFramework, createTestFramework } from '../../../../framework';
import { arbitrarySanitisedHtmlFragment, arbitraryUri } from '../../../../helpers';
import { arbitrarySanitisedHtmlFragment, arbitraryUrl } from '../../../../helpers';
import { arbitraryDataError } from '../../../../types/data-error.helper';
import { arbitraryRecordedEvaluation } from '../../../../types/recorded-evaluation.helper';

Expand All @@ -20,7 +19,7 @@ describe('to-evaluation-published-feed-item', () => {
});

describe('when the human readable original URL is available for the evaluation', () => {
const humanReadableOriginalUrl = new URL(arbitraryUri());
const humanReadableOriginalUrl = arbitraryUrl();

beforeEach(async () => {
sourceHref = await pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { pipe } from 'fp-ts/function';
import { EvaluationPublishedFeedItem } from '../../../../src/read-side/html-pages/paper-activity-page/view-model';
import { toHtmlFragment } from '../../../../src/types/html-fragment';
import { sanitise } from '../../../../src/types/sanitised-html-fragment';
import { arbitraryString, arbitraryUri, arbitraryWord } from '../../../helpers';
import {
arbitraryString, arbitraryUrl, arbitraryWord,
} from '../../../helpers';
import { arbitraryEvaluationLocator } from '../../../types/evaluation-locator.helper';

export const arbitrary = (): EvaluationPublishedFeedItem => ({
type: 'evaluation-published',
id: arbitraryEvaluationLocator(),
sourceHref: O.some(new URL(arbitraryUri())),
sourceHref: O.some(arbitraryUrl()),
publishedAt: new Date(),
groupHref: arbitraryWord(),
groupName: 'group 1',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { URL } from 'url';
import * as E from 'fp-ts/Either';
import * as T from 'fp-ts/Task';
import * as TE from 'fp-ts/TaskEither';
import { flow, identity, pipe } from 'fp-ts/function';
import { fetchPrelightsHighlight } from '../../../../src/third-parties/fetch-evaluation/prelights/fetch-prelights-highlight';
import * as DE from '../../../../src/types/data-error';
import { dummyLogger } from '../../../dummy-logger';
import { arbitraryString, arbitraryUri } from '../../../helpers';
import { arbitraryString, arbitraryUrl } from '../../../helpers';
import { shouldNotBeCalled } from '../../../should-not-be-called';

const makeDoc = (descriptions: Array<string>) => `
Expand All @@ -32,7 +31,7 @@ describe('fetch-prelights-highlight', () => {
[[ogDescription]],
[[ogDescription, arbitraryString()]],
])('returns the summary of the prelight', async (descriptions) => {
const guid = new URL(arbitraryUri());
const guid = arbitraryUrl();
const queryExternalService = () => () => TE.right(makeDoc(descriptions));
const fullText = await pipe(
fetchPrelightsHighlight(queryExternalService, dummyLogger)(guid.toString()),
Expand All @@ -44,7 +43,7 @@ describe('fetch-prelights-highlight', () => {

describe('cant find fullText', () => {
it('returns unavailable', async () => {
const guid = new URL(arbitraryUri());
const guid = arbitraryUrl();
const queryExternalService = () => () => TE.right(makeDoc([]));
const fullText = await pipe(
guid.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { URL } from 'url';
import * as E from 'fp-ts/Either';
import * as T from 'fp-ts/Task';
import * as TE from 'fp-ts/TaskEither';
Expand All @@ -7,7 +6,7 @@ import { fetchRapidReview } from '../../../../src/third-parties/fetch-evaluation
import * as DE from '../../../../src/types/data-error';
import { HtmlFragment } from '../../../../src/types/html-fragment';
import { dummyLogger } from '../../../dummy-logger';
import { arbitraryString, arbitraryUri } from '../../../helpers';
import { arbitraryString, arbitraryUri, arbitraryUrl } from '../../../helpers';
import { shouldNotBeCalled } from '../../../should-not-be-called';

const rapidReviewResponseWith = (metaTags: ReadonlyArray<[string, string]>) => `
Expand Down Expand Up @@ -137,7 +136,7 @@ describe('fetch-rapid-review', () => {

describe('queryExternalService fails', () => {
it('return "unavailable"', async () => {
const guid = new URL(arbitraryUri());
const guid = arbitraryUrl();
const queryExternalService = () => () => TE.left(DE.unavailable);
const fullText = await pipe(
guid.toString(),
Expand Down
5 changes: 2 additions & 3 deletions test/types/paper-expression.helper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { URL } from 'url';
import * as O from 'fp-ts/Option';
import { arbitraryArticleServer } from './article-server.helper';
import { arbitraryExpressionDoi } from './expression-doi.helper';
import { PaperExpression } from '../../src/types/paper-expression';
import { arbitraryUri, arbitraryDate, arbitraryWord } from '../helpers';
import { arbitraryDate, arbitraryWord, arbitraryUrl } from '../helpers';

export const arbitraryPaperExpression = (): PaperExpression => ({
expressionType: 'preprint',
expressionDoi: arbitraryExpressionDoi(),
publisherHtmlUrl: new URL(arbitraryUri()),
publisherHtmlUrl: arbitraryUrl(),
publishedAt: arbitraryDate(),
publishedTo: arbitraryWord(),
server: O.some(arbitraryArticleServer()),
Expand Down

0 comments on commit 407cdf0

Please sign in to comment.