# 创建特定打印机示例

## 方法1：使用 FeieTestDataFactory

```typescript
import { FeieTestDataFactory } from './tests/utils/test-data-factory';
import { DataSource } from 'typeorm';

// 假设已有 dataSource
const dataSource: DataSource = ...;

// 创建特定打印机
const printer = await FeieTestDataFactory.createSpecificTestPrinter(
  dataSource,
  1, // tenantId
  "924744594", // printer_sn
  "mjLsQXUs", // printer_key
  1 // isDefault (设置为默认打印机)
);

console.log('创建的打印机:', {
  id: printer.id,
  tenantId: printer.tenantId,
  printerSn: printer.printerSn,
  printerKey: printer.printerKey,
  printerName: printer.printerName,
  printerType: printer.printerType,
  printerStatus: printer.printerStatus,
  isDefault: printer.isDefault
});
```

## 方法2：使用 FeieTestFactory

```typescript
import { FeieTestFactory } from './tests/factories/feie-test-factory';
import { DataSource } from 'typeorm';

// 假设已有 dataSource
const dataSource: DataSource = ...;

// 创建工厂实例
const factory = new FeieTestFactory(dataSource);

// 创建特定打印机
const printer = await factory.createSpecificTestPrinter(
  1, // tenantId
  "924744594", // printer_sn
  "mjLsQXUs", // printer_key
  1 // isDefault (设置为默认打印机)
);

console.log('创建的打印机:', {
  id: printer.id,
  tenantId: printer.tenantId,
  printerSn: printer.printerSn,
  printerKey: printer.printerKey,
  printerName: printer.printerName,
  printerType: printer.printerType,
  printerStatus: printer.printerStatus,
  isDefault: printer.isDefault
});
```

## 打印机参数说明

| 参数 | 值 | 说明 |
|------|-----|------|
| printer_sn | 924744594 | 打印机序列号 |
| printer_key | mjLsQXUs | 打印机密钥 |
| isDefault | 1 | 设置为默认打印机 |
| printerName | 自动生成 "打印机 924744594" | 打印机名称 |
| printerType | "58mm" | 打印机类型 |
| printerStatus | "ACTIVE" | 打印机状态 |

## 在测试中使用

```typescript
// 在集成测试中创建测试数据
describe('打印机API测试', () => {
  let dataSource: DataSource;
  let testPrinter: FeiePrinterMt;

  beforeAll(async () => {
    // 初始化数据源
    dataSource = await createTestDataSource();

    // 创建特定打印机
    testPrinter = await FeieTestDataFactory.createSpecificTestPrinter(
      dataSource,
      1,
      "924744594",
      "mjLsQXUs",
      1
    );
  });

  it('应该能获取默认打印机', async () => {
    // 测试逻辑...
  });
});
```