# 沙箱环境验证

{% hint style="info" %}
遇到 API 接入问题时，可登录 [Eva](https://www.atriptech.com/) 寻求帮助。
{% endhint %}

拿到沙箱凭证后，先用这页确认环境已可用。

这一步不需要任何自定义代码。

它用于快速验证凭证、网络和核心预订链路。

### 这项检查验证什么

这套 Test Kit 会在沙箱中运行标准 happy path。

如果前四步都通过，你的沙箱环境就可以进入开发。

| 步骤     | 验证内容          |
| ------ | ------------- |
| Search | 凭证有效，且能返回航班结果 |
| Verify | 能完成验价，并创建会话   |
| Order  | 能成功创建订单       |
| Pay    | 能接受支付         |

### 何时运行

在这些时点运行：

* 收到沙箱凭证后
* 开始开发前
* 网络或 IP 变更后
* 需要快速确认环境健康状态时

### 下载 Test Kit

先下载这两个文件：

* `Atlas_UAT_HappyPath.postman_collection.json`

{% file src="<https://1998191678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FClIWQjtgO3wtMk0oYDks%2Fuploads%2FRRQXSJ3lSNEjDyS2TOIp%2FAtlas_UAT_HappyPath.postman_collection.json?alt=media&token=c454cdbf-6947-4d17-96c6-6813a9d06585>" %}

* `Atlas_UAT_Environment.json`

{% file src="<https://1998191678-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FClIWQjtgO3wtMk0oYDks%2Fuploads%2FvihpTD2pvtG5n3cp2Bh6%2FAtlas_UAT_Environment.json?alt=media&token=891291a2-063d-4ff3-a2c2-dc948aa69b83>" %}

把两个文件下载到同一个本地目录。

不要修改文件名。

然后打开 `Atlas_UAT_Environment.json`。

填入：

* `client_id`
* `client_secret`
* `currency`
* `from_date`

默认使用 `USD` 作为 `currency`。

如果你的测试用例要求其他币种，再改成对应值。

每次运行集合前，都要把 `from_date` 更新为未来日期。

### 如何运行

{% stepper %}
{% step %}

### 填好环境文件

确认 `Atlas_UAT_Environment.json` 中已填入：

* `client_id`
* `client_secret`
* `currency`
* `from_date`

填写规则：

* `currency` 默认使用 `USD`
* 只有测试用例明确要求时，才改用其他币种
* `from_date` 必须是未来日期
* 运行集合前，先检查一次 `from_date` 是否仍然有效
  {% endstep %}

{% step %}

### 安装 Newman

安装 Newman 和 HTML 报告插件。

```bash
npm install -g newman newman-reporter-htmlextra
```

{% endstep %}

{% step %}

### 执行 happy path 集合

在文件所在目录运行：

```bash
newman run Atlas_UAT_HappyPath.postman_collection.json -e Atlas_UAT_Environment.json --delay-request 10000 --reporters htmlextra --reporter-htmlextra-export report.html
```

如果执行失败，可改用：

```bash
npx newman run Atlas_UAT_HappyPath.postman_collection.json -e Atlas_UAT_Environment.json --delay-request 10000 --reporters htmlextra --reporter-htmlextra-export report.html
```

通常需要 2 到 3 分钟。
{% endstep %}

{% step %}

### 查看结果

运行完成后，打开 `report.html`。

重点看 `Search`、`Verify`、`Order` 和 `Pay`。
{% endstep %}
{% endstepper %}

### 通过标准

你的沙箱环境已 ready，当且仅当：

* `Search` 通过
* `Verify` 通过
* `Order` 通过
* `Pay` 通过

这可以视为进入 API 集成的 go signal。

即使最终 retrieve 轮询超时，只要前四步通过，仍视为通过。

{% hint style="success" %}
当前四步都通过后，就可以进入 [沙箱开发](https://resources.atriptech.com/api-wen-dang/ji-cheng-zhi-nan/quick-start/sha-xiang-kai-fa)。
{% endhint %}

### 已知行为

最终的 retrieve 轮询步骤可能超时。

这是预期行为。

出票是异步过程。

这个超时不影响沙箱环境验证结果。

只需关注四个核心步骤：`Search`、`Verify`、`Order` 和 `Pay`。

{% hint style="info" %}
最终 retrieve 轮询仅用于补充观察。
{% endhint %}

### 常见失败原因

如果流程很早就失败，先检查这些项：

* `client_id` 或 `client_secret` 缺失或错误
* `currency` 填写不符合当前测试用例
* `from_date` 不是未来日期
* 选错了环境文件
* 出站网络访问被拦截
* allowlist 后，请求源 IP 发生变化
* 本地修改了集合或环境文件名
* 已安装 Newman，但缺少 reporter 插件

### 快速检查顺序

按这个顺序排查：

1. 确认环境文件中的凭证
2. 确认 `currency` 和 `from_date`
3. 确认沙箱 endpoint 值
4. 确认你的网络可以访问 Atlas
5. 不修改请求顺序，重新执行集合
6. 打开 `report.html`，先看第一个失败请求

### 重要规则

如果 `Search` 失败，先修复凭证或网络。

在 happy path 通过前，不要进入集成开发。

不要跳过失败步骤继续排查后续步骤。

### 通过后做什么

Test Kit 通过后：

* 开始 API 集成
* 开发阶段继续使用同一套沙箱凭证
* 继续阅读 [沙箱开发](https://resources.atriptech.com/api-wen-dang/ji-cheng-zhi-nan/quick-start/sha-xiang-kai-fa)

### 常见问题

#### `newman` 命令找不到怎么办？

先确认 Newman 已安装成功。

重新运行：

```bash
npm install -g newman newman-reporter-htmlextra
```

如果仍找不到命令，检查你的 Node.js 和全局 npm 路径。

#### 没有生成 `report.html` 怎么办？

先确认命令里包含：

* `--reporters htmlextra`
* `--reporter-htmlextra-export report.html`

然后确认 `newman-reporter-htmlextra` 已正确安装。

如果集合在很早阶段就异常退出，也可能不会生成完整报告。

#### 为什么提示找不到集合或环境文件？

通常是以下原因：

* 当前命令不在文件所在目录执行
* 文件名被修改
* 集合文件和环境文件不在同一目录

最稳妥的做法是：

* 保持原始文件名
* 进入文件所在目录后再执行命令

#### 为什么 `Search` 第一步就失败？

先检查：

* `client_id`
* `client_secret`
* `currency` 是否符合当前测试要求
* `from_date` 是否仍是未来日期
* 当前使用的是正确的环境文件
* 出站网络是否可访问 Atlas
* allowlist 后源 IP 是否发生变化

如果 `Search` 未通过，不要继续后续开发。

#### final retrieve 超时算失败吗？

不算。

最终 retrieve 轮询是补充观察步骤。

出票是异步的。

只要 `Search`、`Verify`、`Order` 和 `Pay` 全部通过，就可视为环境验证通过。

### 相关页面

* [快速开始](https://resources.atriptech.com/api-wen-dang/ji-cheng-zhi-nan/quick-start)
* [沙箱访问](https://resources.atriptech.com/api-wen-dang/ji-cheng-zhi-nan/quick-start/making-requests)
* [沙箱开发](https://resources.atriptech.com/api-wen-dang/ji-cheng-zhi-nan/quick-start/sha-xiang-kai-fa)
* [UAT 验证](https://resources.atriptech.com/api-wen-dang/ji-cheng-zhi-nan/quick-start/uat-submission-guide)
