createOrderUserContextIntegration.test.mjs 1.72 KB
import assert from 'node:assert/strict'
import { register } from 'node:module'
import test from 'node:test'

register(
  '../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
  import.meta.url
)

test('router init normalizes the operator and merchant fields before submission', async () => {
  let pageConfig
  globalThis.getApp = () => ({ globalData: {} })
  globalThis.Page = config => {
    pageConfig = config
  }
  globalThis.wx = {
    getAccountInfoSync: () => ({
      miniProgram: {
        appId: 'test-app-id',
        envVersion: 'develop'
      }
    }),
    getSystemInfoSync: () => ({ platform: 'devtools' }),
    getStorageSync: () => '',
    $util: {
      getUserInfo: () => ({})
    }
  }

  await import(`../createOrder.js?user-context=${Date.now()}`)

  const page = {
    data: {
      scene: '',
      orderObj: {},
      workOrderUserContext: null
    },
    setData(patch) {
      Object.assign(this.data, patch)
    }
  }
  const rawUser = {
    merchantId: 44211025,
    merchantName: '流程测试园区门店',
    shopMerchantId: 44210895,
    sceneType: 1,
    phone: '18372203315',
    uuid: 'top-user',
    name: 'top-name',
    subLoginUser: {
      uuid: 'sub-user',
      name: 'sub-name'
    }
  }

  pageConfig.init.call(page, rawUser)

  assert.deepEqual(page.data.workOrderUserContext, {
    sceneType: 1,
    phone: '18372203315',
    parkMerchantId: 44211025,
    shopMerchantId: 44210895,
    operatorId: 'sub-user',
    operatorName: 'sub-name',
    parkMerchantName: '流程测试园区门店'
  })
  assert.deepEqual(page.data.orderObj, {
    sellerMerchantName: '流程测试园区门店',
    sellerName: 'sub-name',
    sellerMerchantId: 44211025,
    sellerUserId: 'sub-user'
  })
})