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

import {
  filterLegacyOrderFulfillmentBindings,
  isKuaishouCloudFulfillmentBinding,
} from './fulfillment-binding-config-service.js'

test('isKuaishouCloudFulfillmentBinding only marks 91kaquan kuaishou rules as cloud rules', () => {
  assert.equal(
    isKuaishouCloudFulfillmentBinding({
      provider: '91kaquan',
      platform: 'kuaishou',
    }),
    true,
  )

  assert.equal(
    isKuaishouCloudFulfillmentBinding({
      provider: 'agiso',
      platform: 'xianyu',
    }),
    false,
  )
})

test('filterLegacyOrderFulfillmentBindings keeps agiso rules and removes 91kaquan kuaishou rules', () => {
  assert.deepEqual(
    filterLegacyOrderFulfillmentBindings([
      {
        provider: 'agiso',
        platform: 'xianyu',
        shopId: 'shop-1',
        skuCode: 'sku-a',
      },
      {
        provider: '91kaquan',
        platform: 'kuaishou',
        shopId: '91kaquan',
        skuCode: 'sku-b',
      },
    ]),
    [
      {
        provider: 'agiso',
        platform: 'xianyu',
        shopId: 'shop-1',
        skuCode: 'sku-a',
      },
    ],
  )
})
