Skip to content

Commit

Permalink
Remove deprecated functions
Browse files Browse the repository at this point in the history
CI started failing as there was an unexpected update to fast-check, and local ESLint caches prevented us from seeing the problems in unchanged code.

Refs #1834, 8f6b150
  • Loading branch information
thewilkybarkid committed Aug 28, 2024
1 parent d999759 commit e6c1fb1
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 194 deletions.
4 changes: 2 additions & 2 deletions test/about-us.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
52 changes: 26 additions & 26 deletions test/cloudinary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions test/clubs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/code-of-conduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/edia-statement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
46 changes: 23 additions & 23 deletions test/fc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export const {
option,
record,
string,
stringOf,
tuple,
uniqueArray,
webUrl,
Expand Down Expand Up @@ -423,14 +422,14 @@ export const oauth = (): fc.Arbitrary<Omit<OrcidOAuthEnv['orcidOauth'] & OAuthEn
export const doiRegistrant = (): fc.Arbitrary<string> =>
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 = <R extends string>(withRegistrant?: fc.Arbitrary<R>): fc.Arbitrary<Doi<R>> =>
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<unknown, Doi<R>>)

Expand Down Expand Up @@ -486,8 +485,8 @@ export const africarxivFigsharePreprintId = (): fc.Arbitrary<AfricarxivFigshareP
export const africarxivFigsharePreprintUrl = (): fc.Arbitrary<[URL, AfricarxivFigsharePreprintId]> =>
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]) => [
Expand All @@ -503,7 +502,7 @@ export const africarxivOsfPreprintId = (): fc.Arbitrary<AfricarxivOsfPreprintId>

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'> },
Expand All @@ -529,7 +528,7 @@ export const arxivPreprintId = (): fc.Arbitrary<ArxivPreprintId> =>

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}`),
Expand All @@ -553,7 +552,7 @@ export const biorxivPreprintId = (): fc.Arbitrary<BiorxivPreprintId> =>

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}`),
Expand All @@ -568,7 +567,7 @@ export const chemrxivPreprintId = (): fc.Arbitrary<ChemrxivPreprintId> =>

export const chemrxivPreprintUrl = (): fc.Arbitrary<URL> =>
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<CurvenotePreprintId> =>
Expand Down Expand Up @@ -603,7 +602,7 @@ export const edarxivPreprintId = (): fc.Arbitrary<EdarxivPreprintId> =>

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'> },
Expand Down Expand Up @@ -631,7 +630,7 @@ export const medrxivPreprintId = (): fc.Arbitrary<MedrxivPreprintId> =>

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}`),
Expand All @@ -646,7 +645,7 @@ export const metaarxivPreprintId = (): fc.Arbitrary<MetaarxivPreprintId> =>

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'> },
Expand All @@ -666,7 +665,7 @@ export const osfPreprintsPreprintId = (): fc.Arbitrary<OsfPreprintsPreprintId> =

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'> },
Expand All @@ -690,7 +689,7 @@ export const preprintsorgPreprintId = (): fc.Arbitrary<PreprintsorgPreprintId> =
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]) => [
Expand All @@ -706,7 +705,7 @@ export const psyarxivPreprintId = (): fc.Arbitrary<PsyarxivPreprintId> =>

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'> },
Expand Down Expand Up @@ -766,7 +765,7 @@ export const socarxivPreprintId = (): fc.Arbitrary<SocarxivPreprintId> =>

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'> },
Expand Down Expand Up @@ -879,7 +878,8 @@ export const datacitePreprintId = (): fc.Arbitrary<DatacitePreprintId> =>

export const orcid = (): fc.Arbitrary<Orcid> =>
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,
})
Expand Down Expand Up @@ -1062,10 +1062,10 @@ export const requestMethod = (): fc.Arbitrary<RequestMethod> =>
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<Record<string, string>> = constant({})) =>
fc
Expand Down Expand Up @@ -1160,7 +1160,7 @@ export const nonEmptyArray = <T>(
export const nonEmptyString = (): fc.Arbitrary<NonEmptyString> => fc.string({ minLength: 1 }).filter(isNonEmptyString)

export const nonEmptyStringOf = (charArb: fc.Arbitrary<string>): fc.Arbitrary<NonEmptyString> =>
fc.stringOf(charArb, { minLength: 1 }).filter(isNonEmptyString)
fc.string({ unit: charArb, minLength: 1 }).filter(isNonEmptyString)

export const languageCode = (): fc.Arbitrary<LanguageCode> => constantFrom(...ISO6391.getAllCodes())

Expand Down
Loading

0 comments on commit e6c1fb1

Please sign in to comment.