import test from 'node:test'
import assert from 'node:assert/strict'

import { mapAdminCloudtentaclesSession, maskPhone, maskSecret } from './mappers.js'

test('maskSecret preserves edges while hiding middle characters', () => {
  assert.equal(maskSecret('abcdef1234567890'), 'abcdef****567890')
  assert.equal(maskSecret('12345678'), '12****78')
  assert.equal(maskSecret(''), '')
})

test('maskPhone hides middle digits for mobile numbers', () => {
  assert.equal(maskPhone('13812345678'), '138****5678')
  assert.equal(maskPhone('123456'), '123456')
  assert.equal(maskPhone(''), '')
})

test('mapAdminCloudtentaclesSession derives masked fields and token presence', () => {
  assert.deepEqual(
    mapAdminCloudtentaclesSession({
      token: 'abcdef1234567890',
      baseUrl: ' https://123.207.217.176 ',
      username: ' admin ',
      phone: '13812345678',
      loggedInAt: ' 2026-05-04T10:00:00.000Z ',
      deviceId: ' dev-1 ',
      deviceType: '2',
    }),
    {
      token: 'abcdef1234567890',
      tokenMasked: 'abcdef****567890',
      baseUrl: 'https://123.207.217.176',
      username: 'admin',
      phoneMasked: '138****5678',
      loggedInAt: '2026-05-04T10:00:00.000Z',
      deviceId: 'dev-1',
      deviceType: 2,
      hasToken: true,
    },
  )
})
