'use strict';

const test = require('node:test');
const assert = require('node:assert/strict');
const { calculateLine, riyadhDate, isIsoDate } = require('../src/utils');

 test('معادلات العهدة تطابق ملف الإكسل', () => {
  const result = calculateLine({ quantity: 5, packSize: 18, unitCost: 57.5, salePrice: 4.5 });
  assert.equal(result.totalUnits, 90);
  assert.equal(result.totalCost, 287.5);
  assert.equal(result.costPerUnit, 3.1944);
  assert.equal(result.salePrice, 4.5);
});

test('لا يظهر قسمة على صفر', () => {
  const result = calculateLine({ quantity: 3, packSize: '', unitCost: 43 });
  assert.equal(result.totalUnits, null);
  assert.equal(result.totalCost, 129);
  assert.equal(result.costPerUnit, null);
});

test('التاريخ بصيغة يوم صحيحة', () => {
  const value = riyadhDate(new Date('2026-08-02T15:30:00Z'));
  assert.equal(value, '2026-08-02');
  assert.equal(isIsoDate(value), true);
  assert.equal(isIsoDate('2026-02-31'), false);
});
