flaxandteal/

bedappy

面向实体的 Laravel RESTful API 扩展,用于 Behat(感谢 Christer Edvartsen)

v1.1.2 2021-05-03 22:34 UTC

This package is not auto-updated.

Last update: 2024-09-20 09:06:21 UTC


README

此包简化了使用 Laravel 和 spatie/laravel-permission 进行行为 API 测试

给定自动播种的角色 "admin" 和 "plebeian",Todo Eloquent 模型和匹配的 Route::resource 路由,它允许进行以下功能测试

  Feature: Todo Handling
    In order to manage todos
    As a user
    I want to be able to use the REST API

    Scenario: todo.store
      Given I am logged in as "user@example.com", who is a plebeian
      And I have an API token
      And I want to store a Todo through the API
      And its properties will be:
      """JSON
      {
        "name": "TODO#1",
        "description": "Write that flippin README",
        "owner_id": {KNOWN_ID:User}
      }
      """
      When I send a request
      Then the response should be successful
      And the response should contain JSON:
      """
      {
        "name": "TODO#1",
        "description": "Write that flippin README"
      }
      """

    Scenario: todo.index
      Given I am logged in as "admin@example.com", who is an admin
      And I have an API token
      And I want to list Todos through the API
      When I send a request
      Then the response should be successful
      And the response should contain JSON:
      """
      {
        "data": [
          {
            "type": "todos",
            "id": {KNOWN_ID:Todo},
            "attributes": {
              "name": "TODO#1",
              "description": "Write that flippin README"
            },
            "relations": {
              "owner": {
                "type": "users",
                "id": {KNOWN_ID:plebeian}
              }
            }
          }
        ]
      }
      """