diff --git a/package-lock.json b/package-lock.json index ccbc19cb..ddbacafc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0-semantically-released", "license": "MIT", "dependencies": { - "@faker-js/faker": "^8.0.2", + "@faker-js/faker": "^7.6.0", "axios": "^0.21.4", "map-obj": "^5.0.1", "p-limit": "^4.0.0", @@ -700,18 +700,12 @@ } }, "node_modules/@faker-js/faker": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.0.2.tgz", - "integrity": "sha512-Uo3pGspElQW91PCvKSIAXoEgAUlRnH29sX2/p89kg7sP1m2PzCufHINd0FhTXQf6DYGiUlVncdSPa2F9wxed2A==", - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/fakerjs" - } - ], + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-7.6.0.tgz", + "integrity": "sha512-XK6BTq1NDMo9Xqw/YkYyGjSsg44fbNwYRx7QK2CuoQgyy+f1rrTDHoExVM5PsyXCtfl2vs2vVJ0MN0yN6LppRw==", "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0", - "npm": ">=6.14.13" + "node": ">=14.0.0", + "npm": ">=6.0.0" } }, "node_modules/@humanwhocodes/config-array": { @@ -12787,9 +12781,9 @@ } }, "@faker-js/faker": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.0.2.tgz", - "integrity": "sha512-Uo3pGspElQW91PCvKSIAXoEgAUlRnH29sX2/p89kg7sP1m2PzCufHINd0FhTXQf6DYGiUlVncdSPa2F9wxed2A==" + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-7.6.0.tgz", + "integrity": "sha512-XK6BTq1NDMo9Xqw/YkYyGjSsg44fbNwYRx7QK2CuoQgyy+f1rrTDHoExVM5PsyXCtfl2vs2vVJ0MN0yN6LppRw==" }, "@humanwhocodes/config-array": { "version": "0.9.5", diff --git a/package.json b/package.json index e3e99c23..35f32813 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "homepage": "https://github.com/peerigon/clockodo#readme", "dependencies": { - "@faker-js/faker": "^8.0.2", + "@faker-js/faker": "^7.6.0", "axios": "^0.21.4", "map-obj": "^5.0.1", "p-limit": "^4.0.0", diff --git a/src/models/__snapshots__/absence.mocks.test.ts.snap b/src/models/__snapshots__/absence.mocks.test.ts.snap index dc282a39..502753f2 100644 --- a/src/models/__snapshots__/absence.mocks.test.ts.snap +++ b/src/models/__snapshots__/absence.mocks.test.ts.snap @@ -4,14 +4,14 @@ exports[`createAbsenceMocks() It creates realistic mocks 1`] = ` Array [ Object { "approvedBy": 1, - "countDays": 1, + "countDays": 5, "countHours": null, - "dateApproved": "2019-09-05", - "dateEnquired": null, - "dateSince": "2020-01-28", + "dateApproved": "2019-09-25", + "dateEnquired": "2019-09-24", + "dateSince": "2020-01-26", "dateUntil": "2020-01-31", "id": 0, - "note": null, + "note": "nam commodi ad animi corporis", "status": 1, "type": 1, "usersId": 0, @@ -21,54 +21,41 @@ Array [ "countDays": 0.5, "countHours": null, "dateApproved": null, - "dateEnquired": null, - "dateSince": "2020-02-24", - "dateUntil": "2020-02-24", + "dateEnquired": "2019-12-02", + "dateSince": "2020-03-01", + "dateUntil": "2020-03-01", "id": 1, - "note": null, + "note": "eum dolores", "status": 3, "type": 2, "usersId": 0, }, Object { "approvedBy": null, - "countDays": 0.5, + "countDays": 9, "countHours": null, "dateApproved": null, "dateEnquired": null, - "dateSince": "2020-03-09", - "dateUntil": "2020-03-09", + "dateSince": "2020-03-12", + "dateUntil": "2020-03-24", "id": 2, "note": null, - "status": 0, - "type": 6, + "status": 3, + "type": 4, "usersId": 0, }, Object { - "approvedBy": null, - "countDays": 1, + "approvedBy": 1, + "countDays": 3, "countHours": null, - "dateApproved": null, - "dateEnquired": null, - "dateSince": "2020-04-12", + "dateApproved": "2020-02-02", + "dateEnquired": "2020-01-31", + "dateSince": "2020-04-08", "dateUntil": "2020-04-14", "id": 3, - "note": null, - "status": 2, - "type": 7, - "usersId": 0, - }, - Object { - "approvedBy": null, - "dateApproved": null, - "dateEnquired": "2019-11-08", - "dateSince": "2020-05-01", - "dateUntil": "2020-05-01", - "id": 4, - "note": null, - "sickNote": true, - "status": 3, - "type": 4, + "note": "commodi fuga pariatur voluptates non beatae", + "status": 1, + "type": 5, "usersId": 0, }, Object { @@ -77,26 +64,26 @@ Array [ "countHours": null, "dateApproved": null, "dateEnquired": null, - "dateSince": "2020-05-24", - "dateUntil": "2020-05-25", - "id": 5, - "note": null, - "status": 3, - "type": 9, + "dateSince": "2020-05-02", + "dateUntil": "2020-05-05", + "id": 4, + "note": "unde ut corrupti eum nostrum consequatur aliquam nostrum commodi", + "status": 2, + "type": 6, "usersId": 0, }, Object { "approvedBy": 1, - "countDays": 0.5, - "countHours": null, - "dateApproved": "2020-05-22", + "countDays": null, + "countHours": 6.76, + "dateApproved": "2020-01-09", "dateEnquired": null, - "dateSince": "2020-05-27", - "dateUntil": "2020-05-27", - "id": 6, - "note": null, + "dateSince": "2020-05-23", + "dateUntil": "2020-05-25", + "id": 5, + "note": "cupiditate temporibus error tempora", "status": 1, - "type": 10, + "type": 3, "usersId": 0, }, Object { @@ -104,66 +91,66 @@ Array [ "countDays": 1, "countHours": null, "dateApproved": null, - "dateEnquired": null, - "dateSince": "2020-06-04", - "dateUntil": "2020-06-05", - "id": 7, - "note": null, - "status": 2, - "type": 11, + "dateEnquired": "2020-04-16", + "dateSince": "2020-05-29", + "dateUntil": "2020-05-30", + "id": 6, + "note": "sint dolorem quasi totam officiis consequuntur", + "status": 0, + "type": 8, "usersId": 0, }, Object { - "approvedBy": null, - "countDays": 0.5, - "countHours": null, - "dateApproved": null, - "dateEnquired": null, - "dateSince": "2020-06-07", - "dateUntil": "2020-06-07", - "id": 8, - "note": null, - "status": 0, - "type": 12, + "approvedBy": 1, + "countDays": null, + "countHours": 5.57, + "dateApproved": "2020-04-01", + "dateEnquired": "2020-03-30", + "dateSince": "2020-06-03", + "dateUntil": "2020-06-05", + "id": 7, + "note": "praesentium quia ut sed cumque quidem beatae", + "status": 1, + "type": 3, "usersId": 0, }, Object { "approvedBy": null, - "countDays": 0.5, - "countHours": null, + "countDays": null, + "countHours": 4.5, "dateApproved": null, "dateEnquired": null, - "dateSince": "2020-06-12", - "dateUntil": "2020-06-12", - "id": 9, - "note": "totam officiis", - "status": 2, - "type": 13, + "dateSince": "2020-06-05", + "dateUntil": "2020-06-09", + "id": 8, + "note": "expedita corporis nisi doloremque consectetur aliquam suscipit aliquid corrupti", + "status": 4, + "type": 3, "usersId": 0, }, Object { "approvedBy": 1, - "countDays": 13, - "countHours": null, - "dateApproved": "2020-03-05", - "dateEnquired": null, - "dateSince": "2020-06-28", - "dateUntil": "2020-07-12", - "id": 10, + "countDays": null, + "countHours": 5.57, + "dateApproved": "2020-05-30", + "dateEnquired": "2020-05-30", + "dateSince": "2020-06-15", + "dateUntil": "2020-06-25", + "id": 9, "note": null, "status": 1, - "type": 14, + "type": 3, "usersId": 0, }, Object { "approvedBy": 1, "countDays": null, - "countHours": 4.479627713258378, - "dateApproved": "2020-04-07", - "dateEnquired": "2020-04-03", - "dateSince": "2020-07-17", - "dateUntil": "2020-07-20", - "id": 11, + "countHours": 7, + "dateApproved": "2020-05-12", + "dateEnquired": "2020-05-11", + "dateSince": "2020-07-02", + "dateUntil": "2020-07-13", + "id": 10, "note": null, "status": 1, "type": 3, @@ -171,71 +158,85 @@ Array [ }, Object { "approvedBy": null, - "countDays": 0.5, + "countDays": 1, "countHours": null, "dateApproved": null, - "dateEnquired": null, - "dateSince": "2020-08-04", - "dateUntil": "2020-08-04", - "id": 12, - "note": null, - "status": 3, - "type": 1, + "dateEnquired": "2020-01-19", + "dateSince": "2020-07-16", + "dateUntil": "2020-07-19", + "id": 11, + "note": "esse id sequi illum", + "status": 0, + "type": 13, "usersId": 0, }, Object { "approvedBy": 1, "countDays": null, - "countHours": 7.963332051970065, - "dateApproved": "2020-04-29", - "dateEnquired": "2020-04-27", - "dateSince": "2020-08-17", + "countHours": 4.69, + "dateApproved": "2020-05-29", + "dateEnquired": "2020-05-27", + "dateSince": "2020-08-02", + "dateUntil": "2020-08-05", + "id": 12, + "note": "ullam at dolores autem assumenda ipsa quis iusto quos", + "status": 1, + "type": 3, + "usersId": 0, + }, + Object { + "approvedBy": 1, + "countDays": 1, + "countHours": null, + "dateApproved": "2020-02-18", + "dateEnquired": "2020-02-17", + "dateSince": "2020-08-18", "dateUntil": "2020-08-19", "id": 13, "note": null, "status": 1, - "type": 3, + "type": 15, "usersId": 0, }, Object { - "approvedBy": 1, - "countDays": null, - "countHours": 7.012903982773423, - "dateApproved": "2020-05-13", - "dateEnquired": null, - "dateSince": "2020-09-08", + "approvedBy": null, + "countDays": 1, + "countHours": null, + "dateApproved": null, + "dateEnquired": "2020-05-15", + "dateSince": "2020-09-07", "dateUntil": "2020-09-09", "id": 14, - "note": null, - "status": 1, - "type": 3, + "note": "distinctio molestias totam maxime", + "status": 4, + "type": 1, "usersId": 0, }, Object { - "approvedBy": 1, - "countDays": null, - "countHours": 4.153712440351955, - "dateApproved": "2020-06-30", - "dateEnquired": null, + "approvedBy": null, + "countDays": 0.5, + "countHours": null, + "dateApproved": null, + "dateEnquired": "2020-05-12", "dateSince": "2020-09-11", "dateUntil": "2020-09-11", "id": 15, - "note": null, - "status": 1, - "type": 3, + "note": "pariatur exercitationem doloribus assumenda inventore quae vel alias neque officiis", + "status": 0, + "type": 2, "usersId": 0, }, Object { - "approvedBy": 1, + "approvedBy": null, "countDays": null, - "countHours": 2.643646778725088, - "dateApproved": "2020-07-31", - "dateEnquired": null, + "countHours": 0.48, + "dateApproved": null, + "dateEnquired": "2020-07-16", "dateSince": "2020-09-17", "dateUntil": "2020-09-17", "id": 16, - "note": null, - "status": 1, + "note": "recusandae velit excepturi ipsa esse ab eligendi molestiae soluta", + "status": 0, "type": 3, "usersId": 0, }, @@ -243,42 +244,42 @@ Array [ "approvedBy": 1, "countDays": 0.5, "countHours": null, - "dateApproved": "2020-06-03", - "dateEnquired": "2020-05-30", + "dateApproved": "2020-07-07", + "dateEnquired": "2020-07-03", "dateSince": "2020-09-20", "dateUntil": "2020-09-20", "id": 17, "note": null, "status": 1, - "type": 9, + "type": 5, "usersId": 0, }, Object { "approvedBy": null, - "countDays": 1, - "countHours": null, + "countDays": null, + "countHours": 5.6, "dateApproved": null, - "dateEnquired": "2020-07-02", - "dateSince": "2020-09-26", + "dateEnquired": "2020-05-12", + "dateSince": "2020-09-24", "dateUntil": "2020-09-27", "id": 18, - "note": null, - "status": 0, - "type": 10, + "note": "vitae ratione est odio officiis", + "status": 4, + "type": 3, "usersId": 0, }, Object { "approvedBy": 1, - "countDays": 15, + "countDays": 1, "countHours": null, - "dateApproved": "2020-11-22", - "dateEnquired": "2020-11-18", - "dateSince": "2020-11-23", - "dateUntil": "2020-12-10", + "dateApproved": "2020-07-13", + "dateEnquired": "2020-07-12", + "dateSince": "2020-11-12", + "dateUntil": "2020-11-13", "id": 19, "note": null, "status": 1, - "type": 11, + "type": 7, "usersId": 0, }, ] diff --git a/src/models/absence.mocks.ts b/src/models/absence.mocks.ts index 10775285..221f4b25 100644 --- a/src/models/absence.mocks.ts +++ b/src/models/absence.mocks.ts @@ -7,7 +7,7 @@ import { startOfDay, toPairs, } from "../lib/mocks.js"; -import { AbsenceStatus, AbsenceType, Absence, SickAbsence } from "./absence.js"; +import { AbsenceStatus, AbsenceType, Absence } from "./absence.js"; const DEFAULT_FROM = new Date(2020, 0); const DEFAULT_TO = new Date(2021, 0); @@ -16,18 +16,8 @@ const absenceStatuses = Object.values(AbsenceStatus).filter( (status): status is AbsenceStatus => typeof status === "number" ); const absenceTypesWithoutOvertimeReduction = Object.values(AbsenceType).filter( - ( - status - ): status is Exclude< - AbsenceType, - | AbsenceType.ReductionOfOvertime - | AbsenceType.SickDay - | AbsenceType.SickDayOfChild - > => - typeof status === "number" && - status !== AbsenceType.ReductionOfOvertime && - status !== AbsenceType.SickDay && - status !== AbsenceType.SickDayOfChild + (status): status is Exclude => + typeof status === "number" && status !== AbsenceType.ReductionOfOvertime ); export const createAbsenceMocks = ({ @@ -43,19 +33,15 @@ export const createAbsenceMocks = ({ ); return dayPairs.map(([from, to], index): Absence => { - const isOvertimeReduction = faker.datatype.boolean(0.2); - const isSick = !isOvertimeReduction && faker.datatype.boolean(0.2); - const isHalfDay = !isOvertimeReduction && faker.datatype.boolean(0.4); - const hasNote = faker.datatype.boolean(0.2); - const absencesId = index; + const isOvertimeReduction = faker.datatype.number({ min: 0, max: 10 }) > 6; + const isHalfDay = + isOvertimeReduction === false && + faker.datatype.number({ min: 0, max: 10 }) > 6; + const hasNote = faker.datatype.number({ min: 0, max: 10 }) > 2; - const dateSince = startOfDay( - faker.date.between({ - from, - to, - }) - ); + const absencesId = index; + const dateSince = startOfDay(faker.date.between(from, to)); const dateUntil = isHalfDay ? dateSince : new Date( @@ -63,18 +49,19 @@ export const createAbsenceMocks = ({ to, // Make sure that we don't get absences that are too long dateSince.getTime() + - faker.number.int({ min: 0, max: 30 }) * ONE_DAY, + faker.datatype.number({ min: 0, max: 30 }) * ONE_DAY, // Clockodo makes sure that dateSince and dateUntil are always within the same year endOfYear(dateSince).getTime() ) ); - const status = faker.datatype.boolean(0.4) - ? AbsenceStatus.Approved - : faker.helpers.arrayElement(absenceStatuses); - + const status = + faker.datatype.number({ min: 0, max: 10 }) > 4 + ? AbsenceStatus.Approved + : faker.helpers.arrayElement(absenceStatuses); const dateEnquiredDateTime = new Date( - dateSince.getTime() - faker.number.int({ min: 5, max: 200 }) * ONE_DAY + dateSince.getTime() - + faker.datatype.number({ min: 5, max: 200 }) * ONE_DAY ); const commonAbsence = { @@ -84,17 +71,18 @@ export const createAbsenceMocks = ({ dateUntil: isoDateFromDateTime(dateUntil), status, note: hasNote - ? faker.lorem.words(faker.number.int({ min: 2, max: 10 })) + ? faker.lorem.words(faker.datatype.number({ min: 2, max: 10 })) : null, - dateEnquired: faker.datatype.boolean(0.6) - ? null - : isoDateFromDateTime(dateEnquiredDateTime), + dateEnquired: + faker.datatype.number({ min: 0, max: 10 }) > 6 + ? null + : isoDateFromDateTime(dateEnquiredDateTime), dateApproved: status === AbsenceStatus.Approved ? isoDateFromDateTime( new Date( dateEnquiredDateTime.getTime() + - faker.number.int({ min: 0, max: 4 }) * ONE_DAY + faker.datatype.number({ min: 0, max: 4 }) * ONE_DAY ) ) : null, @@ -106,39 +94,25 @@ export const createAbsenceMocks = ({ ...commonAbsence, type: AbsenceType.ReductionOfOvertime, countDays: null, - countHours: faker.number.float({ min: 0.1, max: 8 }), + countHours: faker.datatype.float({ min: 0.1, max: 8 }), }; } - const commonNonOvertimeReduction = { + return { ...commonAbsence, + // Make sure that we get the most important absence types + // also for lower mock counts. + type: absenceTypesWithoutOvertimeReduction[ + index % absenceTypesWithoutOvertimeReduction.length + ], countDays: isHalfDay ? 0.5 : Math.max( (dateUntil.getTime() - dateSince.getTime()) / ONE_DAY - - faker.number.int({ min: 0, max: 3 }), + faker.datatype.number({ min: 0, max: 3 }), 1 ), countHours: null, }; - - if (isSick) { - return { - ...commonAbsence, - type: faker.datatype.boolean(0.5) - ? AbsenceType.SickDay - : AbsenceType.SickDayOfChild, - sickNote: faker.datatype.boolean(0.5), - } as unknown as SickAbsence; - } - - return { - ...commonNonOvertimeReduction, - // Make sure that we get the most important absence types - // also for lower mock counts. - type: absenceTypesWithoutOvertimeReduction[ - index % absenceTypesWithoutOvertimeReduction.length - ], - }; }); }; diff --git a/src/models/absence.ts b/src/models/absence.ts index 18ed7a51..c574ee9c 100644 --- a/src/models/absence.ts +++ b/src/models/absence.ts @@ -40,11 +40,6 @@ type CommonAbsence = { * Only with access rights for absence administration or in case of own absences */ approvedBy?: number | null; - /** - * Wether or not the absence is with or without a sick note - * Only with access rights for absence administration or in case of own absences - */ - sickNote?: null; }; export type DaysAbsence = CommonAbsence & { @@ -52,7 +47,7 @@ export type DaysAbsence = CommonAbsence & { * Type of the absence. * Only with access rights for absence administration or in case of own absences */ - type?: Exclude; + type?: Exclude; /** * Amount of absence days (null for overtime reduction). * Only with access rights for absence administration or in case of own absences @@ -83,20 +78,7 @@ export type HoursAbsence = CommonAbsence & { countHours?: number; }; -export type SickAbsence = DaysAbsence & { - /** - * Type of the absence. - * Only with access rights for absence administration or in case of own absences - */ - type?: AbsenceType.SickDay | AbsenceType.SickDayOfChild; - /** - * Wether or not the absence is with or without a sick note - * Only with access rights for absence administration or in case of own absences - */ - sickNote: boolean | null; -} - -export type Absence = DaysAbsence | HoursAbsence | SickAbsence; +export type Absence = DaysAbsence | HoursAbsence; export enum AbsenceStatus { Reported = 0,