Skip to content

Instantly share code, notes, and snippets.

@goodwin64
Last active June 22, 2020 16:17
Show Gist options
  • Save goodwin64/953f06140052ea439fecc267c7eacfa1 to your computer and use it in GitHub Desktop.
Save goodwin64/953f06140052ea439fecc267c7eacfa1 to your computer and use it in GitHub Desktop.
// pathIds, pathNames, paths
export enum urlPathIds {
PATIENT_ID = 'patientId',
MEASUREMENT_ID = 'measurementId',
NOTE_ID = 'noteId',
}
export enum urlPathNames {
OVERVIEW = 'overview',
PATIENTS = 'patients',
MEASUREMENTS = 'measurements',
NOTES = 'notes',
ALERTS = 'alerts',
REPORTS = 'reports',
LOGIN = 'login',
FORGOT_PASSWORD = 'forgot-password',
RESET_PASSWORD = 'reset-password',
}
const { MEASUREMENT_ID, NOTE_ID, PATIENT_ID } = urlPathIds;
const {
OVERVIEW,
PATIENTS,
MEASUREMENTS,
NOTES,
ALERTS,
REPORTS,
LOGIN,
FORGOT_PASSWORD,
RESET_PASSWORD,
} = urlPathNames;
export const paths = {
overview: `/${OVERVIEW}`,
patients: `/${PATIENTS}`,
specificPatient: `/${PATIENTS}/:${PATIENT_ID}`,
specificPatientMeasurements: `/${PATIENTS}/:${PATIENT_ID}/${MEASUREMENTS}`,
specificPatientSpecificMeasurement: `/${PATIENTS}/:${PATIENT_ID}/${MEASUREMENTS}/:${MEASUREMENT_ID}`,
specificPatientNotes: `/${PATIENTS}/:${PATIENT_ID}/${NOTES}`,
specificPatientSpecificNote: `/${PATIENTS}/:${PATIENT_ID}/${NOTES}/:${NOTE_ID}`,
alerts: `/${ALERTS}`,
notes: `/${NOTES}`,
specificNote: `/${NOTES}/:${NOTE_ID}`,
reports: `/${REPORTS}`,
login: `/${LOGIN}`,
forgotPassword: `/${LOGIN}/${FORGOT_PASSWORD}`,
resetPassword: `/${LOGIN}/${RESET_PASSWORD}`,
};
// createUrl.test.ts
describe('createUrl', () => {
it('should create a url from simple path without params', () => {
const actual = createUrl(paths.overview);
const expected = '/overview';
expect(actual).toEqual(expected);
});
it('should create a url from path with one param', () => {
const actual = createUrl(
paths.specificPatient,
{
[urlPathIds.PATIENT_ID]: '123',
},
);
const expected = '/patients/123';
expect(actual).toEqual(expected);
});
it('should create a url with one param + one simple', () => {
const actual = createUrl(
paths.specificPatientMeasurements,
{
[urlPathIds.PATIENT_ID]: '123',
},
);
const expected = '/patients/123/measurements';
expect(actual).toEqual(expected);
});
it('should create a url from path with several params', () => {
const actual = createUrl(
paths.specificPatientSpecificMeasurement,
{
[urlPathIds.PATIENT_ID]: '123',
[urlPathIds.MEASUREMENT_ID]: '456',
},
);
const expected = '/patients/123/measurements/456';
expect(actual).toEqual(expected);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment