import assert from 'node:assert/strict'
import { buildSourceCategories, normalizeSourceProject } from './sourceAdapter.js'

const backendProject = {
  projectId: 10,
  slug: 'dms-platform',
  projectName: 'Commercial DMS',
  category: 'enterprise',
  coverText: 'DMS',
  summary: 'DMS source',
  descriptionMd: '# DMS',
  price: 39900,
  priceLabel: '¥399',
  viewCount: 2860,
  updateTime: '2026-05-18 12:00:00',
  tags: ['Spring Boot', 'Vue2'],
  modules: ['Dealer', 'Repair'],
  scenes: ['Aftermarket'],
  purchased: true
}

const project = normalizeSourceProject(backendProject)

assert.equal(project.id, 'dms-platform')
assert.equal(project.projectId, 10)
assert.equal(project.name, 'Commercial DMS')
assert.equal(project.price, '¥399')
assert.equal(project.views, 2860)
assert.equal(project.updateTime, '2026-05-18')
assert.equal(project.tags[1], 'Vue2')
assert.equal(project.modules[0], 'Dealer')
assert.equal(project.purchased, true)

const categories = buildSourceCategories(
  [
    backendProject,
    { ...backendProject, projectId: 11, slug: 'mall', category: 'mall' }
  ],
  [
    { dictValue: 'enterprise', dictLabel: 'Enterprise Systems' },
    { dictValue: 'mall', dictLabel: 'Mall Systems' }
  ]
)

assert.deepEqual(categories.map((category) => category.value), ['all', 'enterprise', 'mall'])
assert.deepEqual(categories.map((category) => category.label), ['全部源码', 'Enterprise Systems', 'Mall Systems'])
