JWT/API 流程的场景定义 Cucumber/Behat

Scenarios definition for JWT/API Process with Cucumber/Behat

我的场景基本上是: - 授权 (JWT) 用户访问我的 API - 如果用户存在,信息与数据库同步,如果不存在,则创建 - ETC ETC

我的问题是,我将如何继续创建这个场景?请求中应该有很多(好的,4 个)参数,但我不想用可能混淆阅读场景的普通用户的信息污染场景。

这是我的:

  Scenario: Non Existent user access the API
    Given an authorized user access the API
    And user does not exist on API database
    When user access the API
    Then user details are added to API database
    And user does exist on API database

访问 api 的用户将拥有:电子邮件、auth0_id、昵称和姓名。只是不确定我是应该在场景中对这些信息进行编码还是以某种方式在上下文文件中进行编码。

编辑: 我可以在上下文文件中而不是在 .feature 文件中设置一些 "parameters" 吗?即在功能文件上我说 "Non existent user access the application" 和在上下文文件中,在与此步骤关联的函数中,我确保我创建了一个数据库中不存在的用户等等?这是将想法与 .feature 场景分开的好方法吗?

谢谢

我会这样写:

Scenario: API - new user access the API
   Given I have a new user
   When I access the API with the new user
   Then the user is added to the API database

第一步将生成用户详细信息并将它们保存在一个变量中,第二步将调用 api(使用保存的变量并生成 JWT),最后一步将检查详细信息api.

您可以将 new 声明为参数,例如:

@Then /^I access the API with the (new|other_user) user$/

无论如何,您应该尽可能简单地以您认为有意义的方式声明它,以便您可以轻松地重复使用它。