import assert from 'node:assert/strict';
import test from 'node:test';
import { createScheduleService } from './schedule-service.mjs';

test('listUserNotifications accepts mysql JSON columns returned as objects', async () => {
  const service = createScheduleService({
    async query(sql) {
      assert.match(sql, /FROM h5_user_notifications/);
      return [
        [
          {
            id: 'notification-1',
            user_id: 'user-1',
            channel: 'wechat',
            notification_type: 'balance_low',
            title: '余额不足提醒',
            body: '你的账户余额已低于 20.00 元，请及时充值。',
            data_json: { thresholdCents: 2000 },
            status: 'unread',
            read_at: null,
            created_at: 1782313300000,
            updated_at: 1782313300000,
          },
        ],
      ];
    },
  });

  const notifications = await service.listUserNotifications({ userId: 'user-1' });

  assert.equal(notifications.length, 1);
  assert.deepEqual(notifications[0].data, { thresholdCents: 2000 });
});
