@managesome/eposmatic-toolkit 0.4.73 → 0.4.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/helpers/utils/halfhalf-setup-helpers.js +22 -4
- package/esm/helpers/utils/hr-helpers.js +0 -10
- package/esm/helpers/utils/setup-discount-helpers.js +79 -0
- package/esm/helpers/utils/specials-helpers.js +13 -1
- package/esm/schemas/models/tenant_hr_attendance_records.js +2 -2
- package/esm/schemas/models/tenant_hr_employees.js +0 -10
- package/esm/schemas/models/tenant_hr_shift_schedules.js +3 -38
- package/esm/schemas/models/tenant_hr_shifts.js +27 -13
- package/lib/helpers/utils/halfhalf-setup-helpers.js +22 -4
- package/lib/helpers/utils/hr-helpers.d.ts +0 -2
- package/lib/helpers/utils/hr-helpers.js +0 -10
- package/lib/helpers/utils/setup-discount-helpers.d.ts +29 -0
- package/lib/helpers/utils/setup-discount-helpers.js +82 -0
- package/lib/helpers/utils/specials-helpers.js +13 -1
- package/lib/schemas/models/tenant_hr_attendance_records.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_attendance_records.js +2 -2
- package/lib/schemas/models/tenant_hr_employees.d.ts +0 -6
- package/lib/schemas/models/tenant_hr_employees.js +0 -10
- package/lib/schemas/models/tenant_hr_shift_schedules.d.ts +0 -19
- package/lib/schemas/models/tenant_hr_shift_schedules.js +3 -38
- package/lib/schemas/models/tenant_hr_shifts.d.ts +12 -30
- package/lib/schemas/models/tenant_hr_shifts.js +27 -13
- package/lib/schemas/types/tenant_hr_attendance_records.d.ts +2 -2
- package/lib/schemas/types/tenant_hr_employees.d.ts +1 -3
- package/lib/schemas/types/tenant_hr_shift_schedules.d.ts +2 -9
- package/lib/schemas/types/tenant_hr_shifts.d.ts +6 -6
- package/lib/tests/setup-quantity-discount-scaling.test.d.ts +1 -0
- package/lib/tests/setup-quantity-discount-scaling.test.js +274 -0
- package/lib/tests/tenant_hr_employees.test.d.ts +1 -0
- package/lib/tests/tenant_hr_employees.test.js +82 -0
- package/lib/tests/tenant_hr_shift_schedules.test.d.ts +1 -0
- package/lib/tests/tenant_hr_shift_schedules.test.js +61 -0
- package/lib/tests/tenant_hr_shifts.test.d.ts +1 -0
- package/lib/tests/tenant_hr_shifts.test.js +61 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const tenant_hr_employees_1 = require("../schemas/models/tenant_hr_employees");
|
|
9
|
+
const EmployeeModel = mongoose_1.default.model('TestHrEmployee', tenant_hr_employees_1.TenantHrEmployeeSchema, 'test_hr_employees');
|
|
10
|
+
const validEmployee = () => ({
|
|
11
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
12
|
+
uid: 'firebase-uid-1',
|
|
13
|
+
tenant_id: 'test-store',
|
|
14
|
+
phone_number: '+923001234567',
|
|
15
|
+
join_date: new Date('2026-03-12T00:00:00.000Z'),
|
|
16
|
+
});
|
|
17
|
+
const validate = (overrides = {}) => new EmployeeModel({ ...validEmployee(), ...overrides }).validate();
|
|
18
|
+
describe('tenant_hr_employees schema', () => {
|
|
19
|
+
describe('identity', () => {
|
|
20
|
+
it('accepts a minimal employee record', async () => {
|
|
21
|
+
await expect(validate()).resolves.toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
it('requires uid, tenant_id, phone_number and join_date', async () => {
|
|
24
|
+
await expect(validate({ uid: undefined })).rejects.toThrow(/uid/);
|
|
25
|
+
await expect(validate({ tenant_id: undefined })).rejects.toThrow(/tenant_id/);
|
|
26
|
+
await expect(validate({ phone_number: undefined })).rejects.toThrow(/phone_number/);
|
|
27
|
+
await expect(validate({ join_date: undefined })).rejects.toThrow(/join_date/);
|
|
28
|
+
});
|
|
29
|
+
it('defaults to an enabled employee with unverified contact details', () => {
|
|
30
|
+
const employee = new EmployeeModel(validEmployee());
|
|
31
|
+
expect(employee.is_disabled).toBe(false);
|
|
32
|
+
expect(employee.email_verified).toBe(false);
|
|
33
|
+
expect(employee.phone_number_verified).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe('HR profile', () => {
|
|
37
|
+
it('allows an unassigned position (employee not placed yet)', async () => {
|
|
38
|
+
await expect(validate({ position_id: null })).resolves.toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
it('defaults employment status and pay type', () => {
|
|
41
|
+
const employee = new EmployeeModel(validEmployee());
|
|
42
|
+
expect(employee.employment_status).toBe(constants_1.HR_EMPLOYMENT_STATUS_ENUM.ACTIVE);
|
|
43
|
+
expect(employee.pay_type).toBe(constants_1.HR_PAY_TYPE_ENUM.MONTHLY);
|
|
44
|
+
expect(employee.hr_overtime_multiplier).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
it('rejects an employment status outside the enum', async () => {
|
|
47
|
+
await expect(validate({ employment_status: 'FIRED' })).rejects.toThrow(/employment_status/);
|
|
48
|
+
});
|
|
49
|
+
it('rejects a pay type outside the enum', async () => {
|
|
50
|
+
await expect(validate({ pay_type: 'DAILY' })).rejects.toThrow(/pay_type/);
|
|
51
|
+
});
|
|
52
|
+
it('accepts a partial leave allowance map', async () => {
|
|
53
|
+
await expect(validate({
|
|
54
|
+
leave_allowance: {
|
|
55
|
+
[constants_1.HR_LEAVE_TYPE_ENUM.ANNUAL]: 21,
|
|
56
|
+
[constants_1.HR_LEAVE_TYPE_ENUM.SICK]: 10,
|
|
57
|
+
},
|
|
58
|
+
})).resolves.toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
it('accepts a partial documents map (not every document type is uploaded)', async () => {
|
|
61
|
+
await expect(validate({
|
|
62
|
+
docs: {
|
|
63
|
+
CNIC: {
|
|
64
|
+
doc_url: 'https://storage.example/cnic.pdf',
|
|
65
|
+
doc_name: 'cnic.pdf',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
})).resolves.toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('shift assignment lives elsewhere', () => {
|
|
72
|
+
it('does not carry a shift_id column', () => {
|
|
73
|
+
// the assignment is a dated row in tenant_hr_shift_schedules
|
|
74
|
+
expect(tenant_hr_employees_1.TenantHrEmployeeSchema.path('shift_id')).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
it('does not carry the payroll-policy fields', () => {
|
|
77
|
+
// working days / hours per day now come from the shift at payroll time
|
|
78
|
+
expect(tenant_hr_employees_1.TenantHrEmployeeSchema.path('hr_working_days_per_month')).toBeUndefined();
|
|
79
|
+
expect(tenant_hr_employees_1.TenantHrEmployeeSchema.path('hr_hours_per_working_day')).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const tenant_hr_shift_schedules_1 = require("../schemas/models/tenant_hr_shift_schedules");
|
|
8
|
+
const ScheduleModel = mongoose_1.default.model('TestHrShiftSchedule', tenant_hr_shift_schedules_1.TenantHrShiftScheduleSchema, 'test_hr_shift_schedules');
|
|
9
|
+
const validSchedule = () => ({
|
|
10
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
11
|
+
tenant_id: 'test-store',
|
|
12
|
+
employee_id: 'employee-1',
|
|
13
|
+
shift_id: 'shift-1',
|
|
14
|
+
start_date: new Date('2026-11-02T00:00:00.000Z'),
|
|
15
|
+
});
|
|
16
|
+
const validate = (overrides = {}) => new ScheduleModel({ ...validSchedule(), ...overrides }).validate();
|
|
17
|
+
describe('tenant_hr_shift_schedules schema (a dated assignment)', () => {
|
|
18
|
+
describe('shape', () => {
|
|
19
|
+
it('accepts employee + shift + start_date', async () => {
|
|
20
|
+
await expect(validate()).resolves.toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
it('requires employee_id, shift_id and start_date', async () => {
|
|
23
|
+
await expect(validate({ employee_id: undefined })).rejects.toThrow(/employee_id/);
|
|
24
|
+
await expect(validate({ shift_id: undefined })).rejects.toThrow(/shift_id/);
|
|
25
|
+
await expect(validate({ start_date: undefined })).rejects.toThrow(/start_date/);
|
|
26
|
+
});
|
|
27
|
+
it('treats end_date as optional and nullable (open-ended assignment)', async () => {
|
|
28
|
+
await expect(validate({ end_date: null })).resolves.toBeUndefined();
|
|
29
|
+
await expect(validate({ end_date: undefined })).resolves.toBeUndefined();
|
|
30
|
+
await expect(validate({ end_date: new Date('2026-12-31T00:00:00.000Z') })).resolves.toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
it('accepts notes and defaults them to null', async () => {
|
|
33
|
+
await expect(validate({ notes: 'covering for Ali' })).resolves.toBeUndefined();
|
|
34
|
+
const schedule = new ScheduleModel(validSchedule());
|
|
35
|
+
expect(schedule.notes).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('no shift data on the assignment', () => {
|
|
39
|
+
// These used to be real columns. If any of them comes back, the model has
|
|
40
|
+
// regressed to the pre-thin shape and shift edits would stop propagating.
|
|
41
|
+
const forbidden = ['day_indexes', 'start_time', 'end_time', 'position', 'type', 'status'];
|
|
42
|
+
it.each(forbidden)('does not declare `%s`', (path) => {
|
|
43
|
+
expect(tenant_hr_shift_schedules_1.TenantHrShiftScheduleSchema.path(path)).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
it('drops legacy keys instead of persisting them', () => {
|
|
46
|
+
const schedule = new ScheduleModel({
|
|
47
|
+
...validSchedule(),
|
|
48
|
+
day_indexes: ['MON'],
|
|
49
|
+
start_time: 28800,
|
|
50
|
+
end_time: 57600,
|
|
51
|
+
type: 'REGULAR',
|
|
52
|
+
status: 'SCHEDULED',
|
|
53
|
+
position: 'Line Cook',
|
|
54
|
+
});
|
|
55
|
+
const plain = schedule.toObject();
|
|
56
|
+
for (const path of forbidden) {
|
|
57
|
+
expect(plain).not.toHaveProperty(path);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const tenant_hr_shifts_1 = require("../schemas/models/tenant_hr_shifts");
|
|
9
|
+
const ShiftModel = mongoose_1.default.model('TestHrShift', tenant_hr_shifts_1.TenantHrShiftSchema, 'test_hr_shifts');
|
|
10
|
+
const validShift = () => ({
|
|
11
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
12
|
+
tenant_id: 'test-store',
|
|
13
|
+
name: 'Morning',
|
|
14
|
+
start_time: 28800, // 08:00
|
|
15
|
+
end_time: 57600, // 16:00
|
|
16
|
+
working_days: [constants_1.DAY_INDEX_ENUM.MON, constants_1.DAY_INDEX_ENUM.TUE],
|
|
17
|
+
grace_period_minutes: 10,
|
|
18
|
+
});
|
|
19
|
+
const validate = (overrides = {}) => new ShiftModel({ ...validShift(), ...overrides }).validate();
|
|
20
|
+
describe('tenant_hr_shifts schema', () => {
|
|
21
|
+
describe('shape', () => {
|
|
22
|
+
it('accepts a complete shift', async () => {
|
|
23
|
+
await expect(validate()).resolves.toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
it('requires a name', async () => {
|
|
26
|
+
await expect(validate({ name: undefined })).rejects.toThrow(/name/);
|
|
27
|
+
});
|
|
28
|
+
it('requires both start_time and end_time', async () => {
|
|
29
|
+
await expect(validate({ start_time: undefined })).rejects.toThrow(/start_time/);
|
|
30
|
+
await expect(validate({ end_time: undefined })).rejects.toThrow(/end_time/);
|
|
31
|
+
});
|
|
32
|
+
it('rejects times outside 0..86399 (the seconds-of-day range)', async () => {
|
|
33
|
+
await expect(validate({ start_time: -1 })).rejects.toThrow(/start_time/);
|
|
34
|
+
await expect(validate({ end_time: 86400 })).rejects.toThrow(/end_time/);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('working days', () => {
|
|
38
|
+
it('requires at least one working day', async () => {
|
|
39
|
+
// an empty list used to mean "every day" in three different places; the
|
|
40
|
+
// schema now forbids it so that meaning lives in exactly one rule
|
|
41
|
+
await expect(validate({ working_days: [] })).rejects.toThrow(/working_days/);
|
|
42
|
+
});
|
|
43
|
+
it('accepts every valid day code', async () => {
|
|
44
|
+
await expect(validate({ working_days: [...constants_1.ALL_DAY_INDEX] })).resolves.toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
it('rejects a day code outside the enum', async () => {
|
|
47
|
+
await expect(validate({ working_days: ['FUNDAY'] })).rejects.toThrow(/working_days/);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('flags', () => {
|
|
51
|
+
it('defaults to active with no grace period', () => {
|
|
52
|
+
const shift = new ShiftModel({
|
|
53
|
+
...validShift(),
|
|
54
|
+
is_active: undefined,
|
|
55
|
+
grace_period_minutes: undefined,
|
|
56
|
+
});
|
|
57
|
+
expect(shift.is_active).toBe(true);
|
|
58
|
+
expect(shift.grace_period_minutes).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|