You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't a formal feature proposal. It's more of a collection of thoughts and ideas around providing an application configuration and environment variables to support mocking and switching between servers to enable easier testing and less bugs.
Fragmenting the codebase with conditionals makes logic harder to follow and it can easily introduce bugs. These areas are tightly coupled to production data which makes them difficult to work on and validate that they are working correctly.
How
This probably means a refactoring for the codebase.
We should make room for an overall environment provider to indicate which endpoints and clients are needed for test versus production.
Misc thoughts
Mocked server endpoints
Responds to localhost:3000/v1/login and redirects to frogpond's homepage
Responds to localhost:3000/v1/login/error and redirects with error= query parameter
The implementation below tries to combine environment choice and test endpoints.
Something needs to define which endpoints are for production and which are for test
I'm not so sure about this implementation yet, I think it could have more separation of concerns.
// where this file lives is up for discussionimport{useEnvironment}from'@frogpond/environment'import{client}from'@frogpond/api'import{OLECARD_AUTH_URL}from'./financials/urls'exportclassNoEndpointFoundErrorextendsError{}exporttypeEnvironment='production'|'test'exporttypeLoginTestScenario='testSuccess'|'testFailure'functionolecardEndpoint(scenario?: LoginTestScenario){if(useEnvironment().env==='production'){returnOLECARD_AUTH_URL}switch(scenario){case'testSuccess':
return'login'case'testFailure':
return'login/error'default:
console.warn(`Unexpected login scenario: ${scenario}`)thrownewNoEndpointFoundError('No login url provided')}}
This is where things kind of devolve and break down; things are unclear.
This is not something that should ship
It is a demonstration of what not to do for mixing our url building, environment selecting, and client building
Requirements: build a client and a url (per environment provider)
Needs separation of url building and test case building (should be defined higher up in useEnvironment)
// source/lib.login.tsexportasyncfunctionperformLogin(...): Promise<Credentials>{// ...try{/** * Aligning what client is and endpoint it should use is missing * * const loginResponse = await ky.post(olecardEndpoint(), ... * vs * const loginResponse = await client.post(olecardEndpoint('testFailure'), { * * 1. `ky` posts to anywhere (e.g. localhost:3000/v1) * 2. `client` posts to the production server (ccc) * * Production endpoint * olecardEndpoint() * * Test endpoints * olecardEndpoint('testSuccess') * olecardEndpoint('testFailure') */letloginClient=useEnvironment().clientletloginResponse=awaitloginClient.post(olecardEndpoint(),{body: formData,credentials: 'include',cache: 'no-store',})letresponseUrl=newURL(loginResponse.url)if(responseUrl.href.includes('error=')){thrownewLoginFailedError('Login failed')}}catch(error){thrownewLoginFailedError('Login failed')}return{username, password}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This isn't a formal feature proposal. It's more of a collection of thoughts and ideas around providing an application configuration and environment variables to support mocking and switching between servers to enable easier testing and less bugs.
This is a mix of
What
I agree! We could mock the server with development-only endpoints on ccc-server (current or next), a python server, etc.
Why
Fragmenting the codebase with conditionals makes logic harder to follow and it can easily introduce bugs. These areas are tightly coupled to production data which makes them difficult to work on and validate that they are working correctly.
How
This probably means a refactoring for the codebase.
We should make room for an overall environment provider to indicate which endpoints and clients are needed for test versus production.
Misc thoughts
Mocked server endpoints
localhost:3000/v1/login
and redirects to frogpond's homepagelocalhost:3000/v1/login/error
and redirects witherror=
query parameterEndpoint creation by environment and use case?
This is where things kind of devolve and break down; things are unclear.
useEnvironment
)Where we could see improvement
Beta Was this translation helpful? Give feedback.
All reactions