Skip to content

Commit

Permalink
Reduce the amount of work required to let the compiler know not to ty…
Browse files Browse the repository at this point in the history
…pe-widen

My IDE didn't show me all the search results.

Refs 05d2349
  • Loading branch information
thewilkybarkid committed Mar 12, 2024
1 parent 05d2349 commit fee8737
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 195 deletions.
2 changes: 1 addition & 1 deletion test/author-invite-flow/author-invite-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('authorInvite', () => {
title: fc.html(),
}),
}),
fc.either(fc.constant('not-found' as const), fc.unverifiedContactEmailAddress()),
fc.either(fc.constant('not-found'), fc.unverifiedContactEmailAddress()),
])(
"when there isn't a verified email address",
async (inviteId, [user, invite], method, prereview, contactEmailAddress) => {
Expand Down
2 changes: 1 addition & 1 deletion test/author-invite-flow/author-invite-decline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('authorInviteDecline', () => {
}),
doi: fc.doi(),
language: fc.option(fc.languageCode(), { nil: undefined }),
license: fc.constant('CC-BY-4.0' as const),
license: fc.constant('CC-BY-4.0'),
preprint: fc.record({
id: fc.preprintId(),
language: fc.languageCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('authorInviteEnterEmailAddress', () => {
title: fc.html(),
}),
}),
fc.either(fc.constant('not-found' as const), fc.unverifiedContactEmailAddress()),
fc.either(fc.constant('not-found'), fc.unverifiedContactEmailAddress()),
])('using the invite email address', async (inviteId, [user, invite], prereview, contactEmailAddress) => {
const getAuthorInvite = jest.fn<GetAuthorInviteEnv['getAuthorInvite']>(_ => TE.right(invite))
const getContactEmailAddress = jest.fn<GetContactEmailAddressEnv['getContactEmailAddress']>(_ =>
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('authorInviteEnterEmailAddress', () => {
title: fc.html(),
}),
}),
fc.either(fc.constant('not-found' as const), fc.unverifiedContactEmailAddress()),
fc.either(fc.constant('not-found'), fc.unverifiedContactEmailAddress()),
fc.uuid(),
])(
'using a different email address',
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('authorInviteEnterEmailAddress', () => {
title: fc.html(),
}),
}),
fc.either(fc.constant('not-found' as const), fc.unverifiedContactEmailAddress()),
fc.either(fc.constant('not-found'), fc.unverifiedContactEmailAddress()),
fc.uuid(),
])(
"ther verification email can't be sent",
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('authorInviteEnterEmailAddress', () => {
title: fc.html(),
}),
}),
fc.either(fc.constant('not-found' as const), fc.unverifiedContactEmailAddress()),
fc.either(fc.constant('not-found'), fc.unverifiedContactEmailAddress()),
fc.uuid(),
])(
"when the contact email address can't be saved",
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('authorInviteEnterEmailAddress', () => {
title: fc.html(),
}),
}),
fc.either(fc.constant('not-found' as const), fc.unverifiedContactEmailAddress()),
fc.either(fc.constant('not-found'), fc.unverifiedContactEmailAddress()),
])('when the form is invalid', async (inviteId, [user, invite], body, prereview, contactEmailAddress) => {
const actual = await _.authorInviteEnterEmailAddress({ body, id: inviteId, method: 'POST', user })({
generateUuid: shouldNotBeCalled,
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('authorInviteEnterEmailAddress', () => {
title: fc.html(),
}),
}),
fc.either(fc.constant('not-found' as const), fc.unverifiedContactEmailAddress()),
fc.either(fc.constant('not-found'), fc.unverifiedContactEmailAddress()),
])(
'when the form needs submitting',
async (inviteId, [user, invite], method, body, prereview, contactEmailAddress) => {
Expand Down
4 changes: 2 additions & 2 deletions test/author-invite-flow/author-invite-persona.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('authorInvitePersona', () => {
title: fc.html(),
}),
}),
fc.constantFrom('public' as const, 'pseudonym' as const),
fc.constantFrom('public', 'pseudonym'),
])('when the persona is set', async (inviteId, [user, invite], prereview, persona) => {
const getAuthorInvite = jest.fn<GetAuthorInviteEnv['getAuthorInvite']>(_ => TE.right(invite))
const getPrereview = jest.fn<GetPrereviewEnv['getPrereview']>(_ => TE.right(prereview))
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('authorInvitePersona', () => {
title: fc.html(),
}),
}),
fc.constantFrom('public' as const, 'pseudonym' as const),
fc.constantFrom('public', 'pseudonym'),
])("when the persona can't be set", async (inviteId, [user, invite], prereview, persona) => {
const actual = await _.authorInvitePersona({ body: { persona }, id: inviteId, method: 'POST', user })({
getAuthorInvite: () => TE.right(invite),
Expand Down
8 changes: 4 additions & 4 deletions test/author-invite-flow/author-invite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('authorInvite', () => {
}),
doi: fc.doi(),
language: fc.option(fc.languageCode(), { nil: undefined }),
license: fc.constant('CC-BY-4.0' as const),
license: fc.constant('CC-BY-4.0'),
preprint: fc.record({
id: fc.preprintId(),
language: fc.languageCode(),
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('authorInvite', () => {
}),
doi: fc.doi(),
language: fc.option(fc.languageCode(), { nil: undefined }),
license: fc.constant('CC-BY-4.0' as const),
license: fc.constant('CC-BY-4.0'),
preprint: fc.record({
id: fc.preprintId(),
language: fc.languageCode(),
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('authorInvite', () => {
}),
doi: fc.doi(),
language: fc.option(fc.languageCode(), { nil: undefined }),
license: fc.constant('CC-BY-4.0' as const),
license: fc.constant('CC-BY-4.0'),
preprint: fc.record({
id: fc.preprintId(),
language: fc.languageCode(),
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('authorInvite', () => {
}),
doi: fc.doi(),
language: fc.option(fc.languageCode(), { nil: undefined }),
license: fc.constant('CC-BY-4.0' as const),
license: fc.constant('CC-BY-4.0'),
preprint: fc.record({
id: fc.preprintId(),
language: fc.languageCode(),
Expand Down
4 changes: 2 additions & 2 deletions test/my-details-page/change-career-stage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('changeCareerStage', () => {
fc.anything(),
fc.string().filter(method => method !== 'POST'),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.careerStage()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.careerStage()),
])('when there is a logged in user', async (body, method, user, careerStage) => {
const actual = await _.changeCareerStage({ body, method, user })({
deleteCareerStage: shouldNotBeCalled,
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('changeCareerStage', () => {
test.prop([
fc.oneof(fc.careerStageValue(), fc.constant('skip')),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.careerStage()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.careerStage()),
])(
'when the form has been submitted but the career stage cannot be saved',
async (careerStage, user, existingCareerStage) => {
Expand Down
10 changes: 5 additions & 5 deletions test/my-details-page/change-contact-email-address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('changeContactEmailAddress', () => {
fc.anything(),
fc.string().filter(method => method !== 'POST'),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.contactEmailAddress()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.contactEmailAddress()),
])('when there is a logged in user', async (body, method, user, emailAddress) => {
const actual = await _.changeContactEmailAddress({ body, method, user })({
generateUuid: shouldNotBeCalled,
Expand All @@ -39,7 +39,7 @@ describe('changeContactEmailAddress', () => {
test.prop([
fc.emailAddress(),
fc.user(),
fc.either(fc.constant('not-found' as const), fc.contactEmailAddress()),
fc.either(fc.constant('not-found'), fc.contactEmailAddress()),
fc.uuid(),
])(
'when it is different to the previous value',
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('changeContactEmailAddress', () => {
.filter(string => !string.includes('.') || !string.includes('@') || /\s/g.test(string)),
}),
fc.user(),
fc.either(fc.constant('not-found' as const), fc.contactEmailAddress()),
fc.either(fc.constant('not-found'), fc.contactEmailAddress()),
])('it is not an email address', async (body, user, emailAddress) => {
const actual = await _.changeContactEmailAddress({ body, method: 'POST', user })({
generateUuid: shouldNotBeCalled,
Expand All @@ -126,7 +126,7 @@ describe('changeContactEmailAddress', () => {
test.prop([
fc.record({ emailAddress: fc.emailAddress() }),
fc.user(),
fc.either(fc.constant('not-found' as const), fc.contactEmailAddress()),
fc.either(fc.constant('not-found'), fc.contactEmailAddress()),
fc.uuid(),
])('the email address cannot be saved', async (body, user, emailAddress, verificationToken) => {
const actual = await _.changeContactEmailAddress({ body, method: 'POST', user })({
Expand All @@ -149,7 +149,7 @@ describe('changeContactEmailAddress', () => {
test.prop([
fc.record({ emailAddress: fc.emailAddress() }),
fc.user(),
fc.either(fc.constant('not-found' as const), fc.contactEmailAddress()),
fc.either(fc.constant('not-found'), fc.contactEmailAddress()),
fc.uuid(),
])('the verification email cannot be sent', async (body, user, emailAddress, verificationToken) => {
const actual = await _.changeContactEmailAddress({ body, method: 'POST', user })({
Expand Down
4 changes: 2 additions & 2 deletions test/my-details-page/change-languages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('changeLanguages', () => {
fc.anything(),
fc.string().filter(method => method !== 'POST'),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.languages()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.languages()),
])('when there is a logged in user', async (body, method, user, languages) => {
const actual = await _.changeLanguages({ body, method, user })({
deleteLanguages: shouldNotBeCalled,
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('changeLanguages', () => {
test.prop([
fc.record({ languages: fc.nonEmptyString() }),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.languages()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.languages()),
])('when the form has been submitted but languages cannot be saved', async (body, user, existingLanguages) => {
const actual = await _.changeLanguages({ body, method: 'POST', user })({
deleteLanguages: () => TE.left('unavailable'),
Expand Down
4 changes: 2 additions & 2 deletions test/my-details-page/change-location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('changeLocation', () => {
fc.anything(),
fc.string().filter(method => method !== 'POST'),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.location()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.location()),
])('when there is a logged in user', async (body, method, user, location) => {
const actual = await _.changeLocation({ body, method, user })({
deleteLocation: shouldNotBeCalled,
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('changeLocation', () => {
test.prop([
fc.record({ location: fc.nonEmptyString() }),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.location()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.location()),
])('when the form has been submitted but the location cannot be saved', async (body, user, existingLocation) => {
const actual = await _.changeLocation({ body, method: 'POST', user })({
deleteLocation: () => TE.left('unavailable'),
Expand Down
10 changes: 3 additions & 7 deletions test/my-details-page/change-open-for-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('changeOpenForRequests', () => {
fc.anything(),
fc.string().filter(method => method !== 'POST'),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.isOpenForRequests()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.isOpenForRequests()),
])('when there is a logged in user', async (body, method, user, openForRequests) => {
const actual = await _.changeOpenForRequests({ body, method, user })({
isOpenForRequests: () => TE.fromEither(openForRequests),
Expand All @@ -33,7 +33,7 @@ describe('changeOpenForRequests', () => {
})

describe('when the form has been submitted', () => {
test.prop([fc.constantFrom('yes' as const, 'no' as const), fc.user(), fc.isOpenForRequests()])(
test.prop([fc.constantFrom('yes', 'no'), fc.user(), fc.isOpenForRequests()])(
'there is open for requests already',
async (openForRequests, user, existingOpenForRequests) => {
const saveOpenForRequests = jest.fn<_.Env['saveOpenForRequests']>(_ => TE.right(undefined))
Expand Down Expand Up @@ -88,11 +88,7 @@ describe('changeOpenForRequests', () => {
)
})

test.prop([
fc.constantFrom('yes', 'no'),
fc.user(),
fc.either(fc.constantFrom('not-found' as const), fc.isOpenForRequests()),
])(
test.prop([fc.constantFrom('yes', 'no'), fc.user(), fc.either(fc.constantFrom('not-found'), fc.isOpenForRequests())])(
'when the form has been submitted but the career stage cannot be saved',
async (openForRequests, user, existingOpenForRequests) => {
const actual = await _.changeOpenForRequests({ body: { openForRequests }, method: 'POST', user })({
Expand Down
4 changes: 2 additions & 2 deletions test/my-details-page/change-research-interests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('changeResearchInterests', () => {
fc.anything(),
fc.string().filter(method => method !== 'POST'),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.researchInterests()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.researchInterests()),
])('when there is a logged in user', async (body, method, user, researchInterests) => {
const actual = await _.changeResearchInterests({ body, method, user })({
deleteResearchInterests: shouldNotBeCalled,
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('changeResearchInterests', () => {
test.prop([
fc.record({ researchInterests: fc.nonEmptyString() }),
fc.user(),
fc.either(fc.constantFrom('not-found' as const, 'unavailable' as const), fc.researchInterests()),
fc.either(fc.constantFrom('not-found', 'unavailable'), fc.researchInterests()),
])(
'when the form has been submitted but the research interests cannot be saved',
async (body, user, existingResearchInterests) => {
Expand Down
Loading

0 comments on commit fee8737

Please sign in to comment.