diff --git a/test/about-us.test.ts b/test/about-us.test.ts index 2d2c03b62..915de2dab 100644 --- a/test/about-us.test.ts +++ b/test/about-us.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('aboutUs', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6154aa157741400e8722bb14', @@ -32,7 +32,7 @@ describe('aboutUs', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/cloudinary.test.ts b/test/cloudinary.test.ts index 03307cc95..fddadb567 100644 --- a/test/cloudinary.test.ts +++ b/test/cloudinary.test.ts @@ -15,8 +15,8 @@ describe('getAvatarFromCloudinary', () => { test.prop([ fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), fc.nonEmptyStringOf(fc.alphanumeric()), @@ -41,8 +41,8 @@ describe('getAvatarFromCloudinary', () => { test.prop([ fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), ])("when the ORCID iD doesn't have an avatar", async (cloudinaryApi, orcid) => { @@ -57,8 +57,8 @@ describe('getAvatarFromCloudinary', () => { test.prop([ fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), ])('when the avatar is unavailable', async (cloudinaryApi, orcid) => { @@ -77,8 +77,8 @@ describe('saveAvatarOnCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.origin(), fc.orcid(), @@ -134,8 +134,8 @@ describe('saveAvatarOnCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.origin(), fc.orcid(), @@ -212,8 +212,8 @@ describe('saveAvatarOnCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.origin(), fc.orcid(), @@ -266,8 +266,8 @@ describe('saveAvatarOnCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.origin(), fc.orcid(), @@ -312,8 +312,8 @@ describe('saveAvatarOnCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.origin(), fc.orcid(), @@ -354,8 +354,8 @@ describe('removeAvatarFromCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), fc.nonEmptyString(), @@ -401,8 +401,8 @@ describe('removeAvatarFromCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), fc.nonEmptyString(), @@ -435,8 +435,8 @@ describe('removeAvatarFromCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), fc.nonEmptyString(), @@ -462,8 +462,8 @@ describe('removeAvatarFromCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), ])('when the avatar cannot be loaded locally', async (date, cloudinaryApi, orcid) => { @@ -486,8 +486,8 @@ describe('removeAvatarFromCloudinary', () => { fc.date(), fc.record({ cloudName: fc.lorem({ maxCount: 1 }), - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), }), fc.orcid(), ])('when there is no avatar', async (date, cloudinaryApi, orcid) => { diff --git a/test/clubs.test.ts b/test/clubs.test.ts index 45f97cfdf..ed738e52b 100644 --- a/test/clubs.test.ts +++ b/test/clubs.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('clubs', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/64637b4c07fb34a92c7f84ec', @@ -32,7 +32,7 @@ describe('clubs', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/code-of-conduct.test.ts b/test/code-of-conduct.test.ts index 469433631..373bdcf5a 100644 --- a/test/code-of-conduct.test.ts +++ b/test/code-of-conduct.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('codeOfConduct', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6154aa157741400e8722bb00', @@ -32,7 +32,7 @@ describe('codeOfConduct', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/edia-statement.test.ts b/test/edia-statement.test.ts index 49b903c69..219fa0683 100644 --- a/test/edia-statement.test.ts +++ b/test/edia-statement.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('ediaStatement', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6154aa157741400e8722bb17', @@ -32,7 +32,7 @@ describe('ediaStatement', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/fc.ts b/test/fc.ts index 2c18d7d80..3ef2faa9a 100644 --- a/test/fc.ts +++ b/test/fc.ts @@ -140,7 +140,6 @@ export const { option, record, string, - stringOf, tuple, uniqueArray, webUrl, @@ -423,14 +422,14 @@ export const oauth = (): fc.Arbitrary => fc .tuple( - fc.stringOf(constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), { minLength: 2 }), - fc.array(fc.stringOf(constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), { minLength: 1 })), + fc.string({ unit: constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), minLength: 2 }), + fc.array(fc.string({ unit: constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), minLength: 1 })), ) .map(([one, two]) => [one, ...two].join('.')) export const doi = (withRegistrant?: fc.Arbitrary): fc.Arbitrary> => fc - .tuple(withRegistrant ?? doiRegistrant(), fc.unicodeString({ minLength: 1 })) + .tuple(withRegistrant ?? doiRegistrant(), fc.string({ unit: 'grapheme', minLength: 1 })) .map(([prefix, suffix]) => `10.${prefix}/${suffix}`) .filter(isDoi as Refinement>) @@ -486,8 +485,8 @@ export const africarxivFigsharePreprintId = (): fc.Arbitrary => fc .tuple( - fc.stringOf(fc.oneof(alphanumeric(), constant('-')), { minLength: 1 }), - fc.stringOf(fc.oneof(alphanumeric(), constantFrom('_')), { minLength: 1 }), + fc.string({ unit: fc.oneof(alphanumeric(), constant('-')), minLength: 1 }), + fc.string({ unit: fc.oneof(alphanumeric(), constantFrom('_')), minLength: 1 }), fc.integer({ min: 1 }), ) .map(([type, title, id]) => [ @@ -503,7 +502,7 @@ export const africarxivOsfPreprintId = (): fc.Arbitrary export const africarxivOsfPreprintUrl = (): fc.Arbitrary<[URL, AfricarxivOsfPreprintId]> => fc - .stringOf(alphanumeric(), { minLength: 1 }) + .string({ unit: alphanumeric(), minLength: 1 }) .map(id => [ new URL(`https://osf.io/preprints/africarxiv/${id}`), { type: 'africarxiv', value: `10.31730/osf.io/${id}` as Doi<'31730'> }, @@ -529,7 +528,7 @@ export const arxivPreprintId = (): fc.Arbitrary => export const arxivPreprintUrl = (): fc.Arbitrary<[URL, ArxivPreprintId]> => fc - .stringOf(constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'), { minLength: 1 }) + .string({ unit: constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'), minLength: 1 }) .filter(suffix => isDoi(`10.48550/${suffix}`)) .map(suffix => [ new URL(`https://arxiv.org/abs/${suffix}`), @@ -553,7 +552,7 @@ export const biorxivPreprintId = (): fc.Arbitrary => export const biorxivPreprintUrl = (): fc.Arbitrary<[URL, BiorxivPreprintId]> => fc - .stringOf(constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'), { minLength: 1 }) + .string({ unit: constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'), minLength: 1 }) .filter(suffix => isDoi(`10.1101/${suffix}`)) .map(suffix => [ new URL(`https://www.biorxiv.org/content/10.1101/${suffix}`), @@ -568,7 +567,7 @@ export const chemrxivPreprintId = (): fc.Arbitrary => export const chemrxivPreprintUrl = (): fc.Arbitrary => fc - .stringOf(alphanumeric(), { minLength: 1 }) + .string({ unit: alphanumeric(), minLength: 1 }) .map(id => new URL(`https://chemrxiv.org/engage/chemrxiv/article-details/${id}`)) export const curvenotePreprintId = (): fc.Arbitrary => @@ -603,7 +602,7 @@ export const edarxivPreprintId = (): fc.Arbitrary => export const edarxivPreprintUrl = (): fc.Arbitrary<[URL, EdarxivPreprintId]> => fc - .stringOf(alphanumeric(), { minLength: 1 }) + .string({ unit: alphanumeric(), minLength: 1 }) .map(id => [ new URL(`https://edarxiv.org/${id}`), { type: 'edarxiv', value: `10.35542/osf.io/${id}` as Doi<'35542'> }, @@ -631,7 +630,7 @@ export const medrxivPreprintId = (): fc.Arbitrary => export const medrxivPreprintUrl = (): fc.Arbitrary<[URL, MedrxivPreprintId]> => fc - .stringOf(constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'), { minLength: 1 }) + .string({ unit: constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'), minLength: 1 }) .filter(suffix => isDoi(`10.1101/${suffix}`)) .map(suffix => [ new URL(`https://www.medrxiv.org/content/10.1101/${suffix}`), @@ -646,7 +645,7 @@ export const metaarxivPreprintId = (): fc.Arbitrary => export const metaarxivPreprintUrl = (): fc.Arbitrary<[URL, MetaarxivPreprintId]> => fc - .stringOf(alphanumeric(), { minLength: 1 }) + .string({ unit: alphanumeric(), minLength: 1 }) .map(id => [ new URL(`https://osf.io/preprints/metaarxiv/${id}`), { type: 'metaarxiv', value: `10.31222/osf.io/${id}` as Doi<'31222'> }, @@ -666,7 +665,7 @@ export const osfPreprintsPreprintId = (): fc.Arbitrary = export const osfPreprintsPreprintUrl = (): fc.Arbitrary<[URL, OsfPreprintsPreprintId]> => fc - .stringOf(alphanumeric(), { minLength: 1 }) + .string({ unit: alphanumeric(), minLength: 1 }) .map(id => [ new URL(`https://osf.io/${id}`), { type: 'osf-preprints', value: `10.31219/osf.io/${id}` as Doi<'31219'> }, @@ -690,7 +689,7 @@ export const preprintsorgPreprintId = (): fc.Arbitrary = export const preprintsorgPreprintUrl = (): fc.Arbitrary<[URL, PreprintsorgPreprintId]> => fc .tuple( - fc.stringOf(fc.oneof(alphanumeric(), constant('.')), { minLength: 1 }).filter(id => !/^\.{1,2}$/.test(id)), + fc.string({ unit: fc.oneof(alphanumeric(), constant('.')), minLength: 1 }).filter(id => !/^\.{1,2}$/.test(id)), fc.integer({ min: 1 }), ) .map(([id, version]) => [ @@ -706,7 +705,7 @@ export const psyarxivPreprintId = (): fc.Arbitrary => export const psyarxivPreprintUrl = (): fc.Arbitrary<[URL, PsyarxivPreprintId]> => fc - .stringOf(alphanumeric(), { minLength: 1 }) + .string({ unit: alphanumeric(), minLength: 1 }) .map(id => [ new URL(`https://psyarxiv.com/${id}`), { type: 'psyarxiv', value: `10.31234/osf.io/${id}` as Doi<'31234'> }, @@ -766,7 +765,7 @@ export const socarxivPreprintId = (): fc.Arbitrary => export const socarxivPreprintUrl = (): fc.Arbitrary<[URL, SocarxivPreprintId]> => fc - .stringOf(alphanumeric(), { minLength: 1 }) + .string({ unit: alphanumeric(), minLength: 1 }) .map(id => [ new URL(`https://osf.io/preprints/socarxiv/${id}`), { type: 'socarxiv', value: `10.31235/osf.io/${id}` as Doi<'31235'> }, @@ -879,7 +878,8 @@ export const datacitePreprintId = (): fc.Arbitrary => export const orcid = (): fc.Arbitrary => fc - .stringOf(constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), { + .string({ + unit: constantFrom('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), minLength: 4 + 4 + 4 + 3, maxLength: 4 + 4 + 4 + 3, }) @@ -1062,10 +1062,10 @@ export const requestMethod = (): fc.Arbitrary => constantFrom('CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE') const headerName = () => - fc.stringOf( - fc.char().filter(char => /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]$/.test(char)), - { minLength: 1 }, - ) + fc.string({ + unit: fc.string({ minLength: 1, maxLength: 1 }).filter(char => /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]$/.test(char)), + minLength: 1, + }) export const headers = (include: fc.Arbitrary> = constant({})) => fc @@ -1160,7 +1160,7 @@ export const nonEmptyArray = ( export const nonEmptyString = (): fc.Arbitrary => fc.string({ minLength: 1 }).filter(isNonEmptyString) export const nonEmptyStringOf = (charArb: fc.Arbitrary): fc.Arbitrary => - fc.stringOf(charArb, { minLength: 1 }).filter(isNonEmptyString) + fc.string({ unit: charArb, minLength: 1 }).filter(isNonEmptyString) export const languageCode = (): fc.Arbitrary => constantFrom(...ISO6391.getAllCodes()) diff --git a/test/funding.test.ts b/test/funding.test.ts index 767b61b88..e8c8ca4fc 100644 --- a/test/funding.test.ts +++ b/test/funding.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('funding', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6154aa157741400e8722bb12', @@ -32,7 +32,7 @@ describe('funding', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/ghost.test.ts b/test/ghost.test.ts index a1e352af0..f399b9abb 100644 --- a/test/ghost.test.ts +++ b/test/ghost.test.ts @@ -10,8 +10,8 @@ import { shouldNotBeCalled } from './should-not-be-called.js' describe('getPage', () => { test.prop([ - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.sanitisedHtml(), ])('when the page can be decoded', async (id, key, html) => { const actual = await _.getPage(id)({ @@ -28,95 +28,93 @@ describe('getPage', () => { expect(actual).toStrictEqual(E.right(html)) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.stringOf(fc.alphanumeric(), { minLength: 1 })])( - 'when the page contains links', - async (id, key) => { - const actual = await _.getPage(id)({ - fetch: fetchMock.sandbox().getOnce( - { url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, - { - body: { - pages: [ - { - html: 'Start a Club!ASAPbio Cancer Biology CrowdASAPbio Metabolism CrowdPREreview', - }, - ], - }, + test.prop([ + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + ])('when the page contains links', async (id, key) => { + const actual = await _.getPage(id)({ + fetch: fetchMock.sandbox().getOnce( + { url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, + { + body: { + pages: [ + { + html: 'Start a Club!ASAPbio Cancer Biology CrowdASAPbio Metabolism CrowdPREreview', + }, + ], }, + }, + ), + ghostApi: { key }, + sleep: shouldNotBeCalled, + })() + + expect(actual).toStrictEqual( + E.right( + rawHtml( + 'Start a Club!ASAPbio Cancer Biology CrowdASAPbio Metabolism CrowdPREreview', ), - ghostApi: { key }, - sleep: shouldNotBeCalled, - })() - - expect(actual).toStrictEqual( - E.right( - rawHtml( - 'Start a Club!ASAPbio Cancer Biology CrowdASAPbio Metabolism CrowdPREreview', - ), - ), - ) - }, - ) - - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.stringOf(fc.alphanumeric(), { minLength: 1 })])( - 'when the page contains an image', - async (id, key) => { - const actual = await _.getPage(id)({ - fetch: fetchMock.sandbox().getOnce( - { url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, - { - body: { - pages: [ - { - html: '
', - }, - ], - }, + ), + ) + }) + + test.prop([ + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + ])('when the page contains an image', async (id, key) => { + const actual = await _.getPage(id)({ + fetch: fetchMock.sandbox().getOnce( + { url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, + { + body: { + pages: [ + { + html: '
', + }, + ], }, + }, + ), + ghostApi: { key }, + sleep: shouldNotBeCalled, + })() + + expect(actual).toStrictEqual( + E.right( + rawHtml( + '', ), - ghostApi: { key }, - sleep: shouldNotBeCalled, - })() - - expect(actual).toStrictEqual( - E.right( - rawHtml( - '', - ), - ), - ) - }, - ) - - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.stringOf(fc.alphanumeric(), { minLength: 1 })])( - 'when the page contains a button', - async (id, key) => { - const actual = await _.getPage(id)({ - fetch: fetchMock.sandbox().getOnce( - { url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, - { - body: { - pages: [ - { - html: '', - }, - ], - }, + ), + ) + }) + + test.prop([ + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + ])('when the page contains a button', async (id, key) => { + const actual = await _.getPage(id)({ + fetch: fetchMock.sandbox().getOnce( + { url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, + { + body: { + pages: [ + { + html: '', + }, + ], }, - ), - ghostApi: { key }, - sleep: shouldNotBeCalled, - })() + }, + ), + ghostApi: { key }, + sleep: shouldNotBeCalled, + })() - expect(actual).toStrictEqual( - E.right(rawHtml('Donate')), - ) - }, - ) + expect(actual).toStrictEqual(E.right(rawHtml('Donate'))) + }) test.prop([ - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.sanitisedHtml(), ])("revalidates the page if it's stale", async (id, key, html) => { const fetch = fetchMock @@ -145,8 +143,8 @@ describe('getPage', () => { }) test.prop([ - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse({ status: fc.constant(Status.OK) }), ])('when the response cannot be decoded', async (id, key, response) => { const fetch = fetchMock @@ -163,29 +161,26 @@ describe('getPage', () => { expect(fetch.done()).toBeTruthy() }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.stringOf(fc.alphanumeric(), { minLength: 1 })])( - 'when the response has a 404 status code', - async (id, key) => { - const fetch = fetchMock - .sandbox() - .getOnce( - { url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, - Status.NotFound, - ) + test.prop([ + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + ])('when the response has a 404 status code', async (id, key) => { + const fetch = fetchMock + .sandbox() + .getOnce({ url: `https://content.prereview.org/ghost/api/content/pages/${id}`, query: { key } }, Status.NotFound) - const actual = await _.getPage(id)({ - fetch, - ghostApi: { key }, - sleep: shouldNotBeCalled, - })() + const actual = await _.getPage(id)({ + fetch, + ghostApi: { key }, + sleep: shouldNotBeCalled, + })() - expect(actual).toStrictEqual(E.left('not-found')) - }, - ) + expect(actual).toStrictEqual(E.left('not-found')) + }) test.prop([ - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.integer({ min: 200, max: 599 }).filter(status => status !== Status.OK && status !== Status.NotFound), ])('when the response has a non-200/404 status code', async (id, key, status) => { const fetch = fetchMock @@ -203,8 +198,8 @@ describe('getPage', () => { }) test.prop([ - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.error(), ])('when fetch throws an error', async (id, key, error) => { const actual = await _.getPage(id)({ diff --git a/test/how-to-use.test.ts b/test/how-to-use.test.ts index 2afe6a8c4..9e6a69a0e 100644 --- a/test/how-to-use.test.ts +++ b/test/how-to-use.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('howToUse', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/651d895e07fb34a92c7f8d28', @@ -32,7 +32,7 @@ describe('howToUse', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/live-reviews.test.ts b/test/live-reviews.test.ts index 991210c71..d64191123 100644 --- a/test/live-reviews.test.ts +++ b/test/live-reviews.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('liveReviews', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6154aa157741400e8722bb10', @@ -32,7 +32,7 @@ describe('liveReviews', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/mailjet.test.ts b/test/mailjet.test.ts index 29c9e95f3..8165a238a 100644 --- a/test/mailjet.test.ts +++ b/test/mailjet.test.ts @@ -10,8 +10,8 @@ import * as fc from './fc.js' describe('sendEmailWithMailjet', () => { test.prop([ fc.record({ - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), sandbox: fc.boolean(), }), fc.email(), @@ -52,8 +52,8 @@ describe('sendEmailWithMailjet', () => { test.prop([ fc.record({ - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), sandbox: fc.boolean(), }), fc.email(), @@ -80,8 +80,8 @@ describe('sendEmailWithMailjet', () => { test.prop([ fc.record({ - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), sandbox: fc.boolean(), }), fc.email(), @@ -109,8 +109,8 @@ describe('sendEmailWithMailjet', () => { test.prop([ fc.record({ - key: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), - secret: fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + key: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), + secret: fc.string({ unit: fc.alphanumeric(), minLength: 1 }), sandbox: fc.boolean(), }), fc.email(), diff --git a/test/people.test.ts b/test/people.test.ts index 600013414..f079841fb 100644 --- a/test/people.test.ts +++ b/test/people.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('people', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6154aa157741400e8722bb0a', @@ -32,7 +32,7 @@ describe('people', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/privacy-policy.test.ts b/test/privacy-policy.test.ts index 704de3172..e85a22468 100644 --- a/test/privacy-policy.test.ts +++ b/test/privacy-policy.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('privacyPolicy', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6154aa157741400e8722bb0f', @@ -32,7 +32,7 @@ describe('privacyPolicy', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/resources.test.ts b/test/resources.test.ts index 69a3e25bd..ef1280fc9 100644 --- a/test/resources.test.ts +++ b/test/resources.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('resources', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/6526c6ae07fb34a92c7f8d6f', @@ -32,7 +32,7 @@ describe('resources', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/slack.test.ts b/test/slack.test.ts index 0f7b5b007..e02258eb4 100644 --- a/test/slack.test.ts +++ b/test/slack.test.ts @@ -12,7 +12,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('getUserFromSlack', () => { - test.prop([fc.string(), fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.nonEmptyString(), fc.url()])( + test.prop([fc.string(), fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.nonEmptyString(), fc.url()])( 'when the user can be decoded', async (slackApiToken, user, name, image) => { const fetch = fetchMock.sandbox().getOnce( @@ -44,7 +44,7 @@ describe('getUserFromSlack', () => { test.prop([ fc.string(), - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse({ status: fc.constant(Status.OK) }), ])("when the user can't be decoded", async (slackApiToken, user, response) => { const fetch = fetchMock.sandbox().getOnce( @@ -67,7 +67,7 @@ describe('getUserFromSlack', () => { expect(fetch.done()).toBeTruthy() }) - test.prop([fc.string(), fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.nonEmptyString()])( + test.prop([fc.string(), fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.nonEmptyString()])( 'when the response has a Slack error', async (slackApiToken, user, error) => { const fetch = fetchMock.sandbox().getOnce( @@ -93,7 +93,7 @@ describe('getUserFromSlack', () => { test.prop([ fc.string(), - fc.stringOf(fc.alphanumeric(), { minLength: 1 }), + fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.integer({ min: 200, max: 599 }).filter(status => status !== Status.OK), ])('when the response has a non-200 status code', async (slackApiToken, user, status) => { const fetch = fetchMock.sandbox().getOnce( @@ -116,7 +116,7 @@ describe('getUserFromSlack', () => { expect(fetch.done()).toBeTruthy() }) - test.prop([fc.string(), fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.error()])( + test.prop([fc.string(), fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.error()])( 'when fetch throws an error', async (slackApiToken, user, error) => { const actual = await _.getUserFromSlack(user)({ diff --git a/test/trainings.test.ts b/test/trainings.test.ts index 6ed681cff..fb48ab5e6 100644 --- a/test/trainings.test.ts +++ b/test/trainings.test.ts @@ -9,7 +9,7 @@ import * as fc from './fc.js' import { shouldNotBeCalled } from './should-not-be-called.js' describe('trainings', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('when the page can be loaded', async key => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { const fetch = fetchMock.sandbox().getOnce( { url: 'https://content.prereview.org/ghost/api/content/pages/64639b5007fb34a92c7f8518', @@ -32,7 +32,7 @@ describe('trainings', () => { }) }) - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 }), fc.fetchResponse()])( + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.fetchResponse()])( 'when the page cannot be loaded', async (key, response) => { const fetch = fetchMock.sandbox().getOnce( diff --git a/test/types/string.test.ts b/test/types/string.test.ts index 2940d3055..3e7b0fbe6 100644 --- a/test/types/string.test.ts +++ b/test/types/string.test.ts @@ -6,13 +6,13 @@ import * as fc from '../fc.js' describe('NonEmptyStringC', () => { describe('decode', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('with a non-empty string', string => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('with a non-empty string', string => { const actual = _.NonEmptyStringC.decode(string) expect(actual).toStrictEqual(D.success(string)) }) - test.prop([fc.stringOf(fc.invisibleCharacter())])('with an empty string', string => { + test.prop([fc.string({ unit: fc.invisibleCharacter() })])('with an empty string', string => { const actual = _.NonEmptyStringC.decode(string) expect(actual).toStrictEqual(D.failure(string, 'NonEmptyString')) @@ -34,11 +34,11 @@ describe('NonEmptyStringC', () => { describe('isNonEmptyString', () => { describe('decode', () => { - test.prop([fc.stringOf(fc.alphanumeric(), { minLength: 1 })])('with a non-empty string', string => { + test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('with a non-empty string', string => { expect(_.isNonEmptyString(string)).toBe(true) }) - test.prop([fc.stringOf(fc.invisibleCharacter())])('with an empty string', string => { + test.prop([fc.string({ unit: fc.invisibleCharacter() })])('with an empty string', string => { expect(_.isNonEmptyString(string)).toBe(false) }) })