#!/usr/bin/partner2-test -w
{
   "name" : "Изменение приоритета правила",
   "options" : {
      "fields" : {
         "business_rules" : [
            "rule_id",
            "multistate_name",
            "position"
         ]
      },
      "mock_bk" : true,
      "read_only" : false
   },
   "testcase" : "",
   "tests" : [
      {
         "request" : {
            "method" : "get",
            "name" : "Изначальные приоритеты под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/?$FIELDS[business_rules]"
         },
         "response" : {
            "body" : {
               "data" : [
                  {
                     "attributes" : {
                        "multistate_name" : "Working.",
                        "position" : 1,
                        "rule_id" : 10
                     },
                     "id" : "10",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/10"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  },
                  {
                     "attributes" : {
                        "multistate_name" : "Working.",
                        "position" : 2,
                        "rule_id" : 11
                     },
                     "id" : "11",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/11"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  },
                  {
                     "attributes" : {
                        "multistate_name" : "Stopped.",
                        "position" : 3,
                        "rule_id" : 12
                     },
                     "id" : "12",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/12"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  },
                  {
                     "attributes" : {
                        "multistate_name" : "Stopped.\nArchived.",
                        "position" : 3,
                        "rule_id" : 13
                     },
                     "id" : "13",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/13"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  }
               ],
               "links" : {
                  "add_fields" : "https://127.0.0.1:80/v1/business_rules/add_fields"
               },
               "meta" : {
                  "count" : 4,
                  "fields" : [
                     "multistate_name",
                     "position",
                     "rule_id"
                  ],
                  "filters" : [
                     {
                        "label" : "Block ID",
                        "name" : "block_public_id",
                        "type" : "text"
                     },
                     {
                        "label" : "Page ID",
                        "name" : "blocks.page_id",
                        "type" : "number"
                     },
                     {
                        "label" : "Business rule caption",
                        "name" : "caption",
                        "type" : "text"
                     },
                     {
                        "label" : "Multistate",
                        "name" : "multistate",
                        "type" : "multistate",
                        "values" : [
                           {
                              "id" : "deleted",
                              "label" : "Archived"
                           },
                           {
                              "id" : "need_update",
                              "label" : "Need update"
                           },
                           {
                              "id" : "stopped",
                              "label" : "Stopped"
                           },
                           {
                              "id" : "updating",
                              "label" : "Updating"
                           },
                           {
                              "id" : "working",
                              "label" : "Working"
                           }
                        ]
                     },
                     {
                        "label" : "Rule ID",
                        "name" : "rule_id",
                        "type" : "number"
                     }
                  ]
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "200"
         }
      },
      {
         "request" : {
            "body" : {
               "insert_before" : 10
            },
            "method" : "post",
            "name" : "Перемещаем 11 (pos=2) перед 10(pos=1) под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/11/action/move/"
         },
         "response" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "actions" : {
                        "archive" : "Archive",
                        "edit" : "Edit",
                        "move" : "Move",
                        "stop" : "Stop"
                     },
                     "multistate" : 9,
                     "multistate_name" : "Working.\nNeed update.",
                     "position" : 1
                  },
                  "id" : "11",
                  "relationships" : {},
                  "type" : "business_rules"
               },
               "links" : {
                  "self" : "https://127.0.0.1:80/v1/business_rules/11"
               },
               "meta" : {
                  "fields" : [
                     "actions",
                     "multistate",
                     "multistate_name",
                     "position"
                  ]
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "200"
         }
      },
      {
         "request" : {
            "body" : {
               "insert_before" : null
            },
            "method" : "post",
            "name" : "Перемещаем 11 в конец $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/11/action/move/"
         },
         "response" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "actions" : {
                        "archive" : "Archive",
                        "edit" : "Edit",
                        "move" : "Move",
                        "stop" : "Stop"
                     },
                     "multistate" : 9,
                     "multistate_name" : "Working.\nNeed update.",
                     "position" : 2
                  },
                  "id" : "11",
                  "relationships" : {},
                  "type" : "business_rules"
               },
               "links" : {
                  "self" : "https://127.0.0.1:80/v1/business_rules/11"
               },
               "meta" : {
                  "fields" : [
                     "actions",
                     "multistate",
                     "multistate_name",
                     "position"
                  ]
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "200"
         }
      },
      {
         "request" : {
            "body" : {
               "insert_before" : 21
            },
            "method" : "post",
            "name" : "Перемещаем 11 (pos=3) перед чужим (mocked-context-adblock-partner) правилом 21(pos=1) под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/11/action/move/"
         },
         "response" : {
            "body" : {
               "errors" : [
                  {
                     "detail" : "Unknown rule_id=21",
                     "id" : "4",
                     "source" : {
                        "pointer" : "/"
                     },
                     "title" : "Validation error"
                  }
               ]
            },
            "content_type" : "application/vnd.api+json",
            "status" : "400"
         }
      },
      {
         "request" : {
            "body" : {
               "insert_before" : 12
            },
            "method" : "post",
            "name" : "Пытаемся переместить 10 (pos=1) перед stopped правилом 12(pos=1) под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/10/action/move/"
         },
         "response" : {
            "body" : {
               "errors" : [
                  {
                     "detail" : "Unknown rule_id=12",
                     "id" : "4",
                     "source" : {
                        "pointer" : "/"
                     },
                     "title" : "Validation error"
                  }
               ]
            },
            "content_type" : "application/vnd.api+json",
            "status" : "400"
         }
      },
      {
         "request" : {
            "method" : "get",
            "name" : "Конечные приоритеты под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/?$FIELDS[business_rules]"
         },
         "response" : {
            "body" : {
               "data" : [
                  {
                     "attributes" : {
                        "multistate_name" : "Working.",
                        "position" : 1,
                        "rule_id" : 10
                     },
                     "id" : "10",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/10"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  },
                  {
                     "attributes" : {
                        "multistate_name" : "Working.\nNeed update.",
                        "position" : 2,
                        "rule_id" : 11
                     },
                     "id" : "11",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/11"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  },
                  {
                     "attributes" : {
                        "multistate_name" : "Stopped.",
                        "position" : 3,
                        "rule_id" : 12
                     },
                     "id" : "12",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/12"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  },
                  {
                     "attributes" : {
                        "multistate_name" : "Stopped.\nArchived.",
                        "position" : 3,
                        "rule_id" : 13
                     },
                     "id" : "13",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/13"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  }
               ],
               "links" : {
                  "add_fields" : "https://127.0.0.1:80/v1/business_rules/add_fields"
               },
               "meta" : {
                  "count" : 4,
                  "fields" : [
                     "multistate_name",
                     "position",
                     "rule_id"
                  ],
                  "filters" : [
                     {
                        "label" : "Block ID",
                        "name" : "block_public_id",
                        "type" : "text"
                     },
                     {
                        "label" : "Page ID",
                        "name" : "blocks.page_id",
                        "type" : "number"
                     },
                     {
                        "label" : "Business rule caption",
                        "name" : "caption",
                        "type" : "text"
                     },
                     {
                        "label" : "Multistate",
                        "name" : "multistate",
                        "type" : "multistate",
                        "values" : [
                           {
                              "id" : "deleted",
                              "label" : "Archived"
                           },
                           {
                              "id" : "need_update",
                              "label" : "Need update"
                           },
                           {
                              "id" : "stopped",
                              "label" : "Stopped"
                           },
                           {
                              "id" : "updating",
                              "label" : "Updating"
                           },
                           {
                              "id" : "working",
                              "label" : "Working"
                           }
                        ]
                     },
                     {
                        "label" : "Rule ID",
                        "name" : "rule_id",
                        "type" : "number"
                     }
                  ]
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "200"
         }
      },
      {
         "request" : {
            "body" : {
               "insert_before" : null
            },
            "method" : "post",
            "name" : "Перемещаем чужое правило (mocked-context-adblock-partner) 21 в конец $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/21/action/move/"
         },
         "response" : {
            "body" : {
               "errors" : [
                  {
                     "detail" : "Not found 21",
                     "id" : "2",
                     "title" : "Conflict"
                  }
               ]
            },
            "content_type" : "application/vnd.api+json",
            "status" : "409"
         }
      },
      {
         "request" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "insert_before" : 10
                  },
                  "id" : "11",
                  "type" : "business_rules"
               }
            },
            "method" : "patch",
            "name" : "Пытаемся move при edit (передаем 'insert_before') под $TOKEN",
            "token" : "mocked-yan-manager",
            "url" : "/v1/business_rules/11"
         },
         "response" : {
            "body" : {
               "errors" : [
                  {
                     "detail" : "You can not edit the following fields: insert_before",
                     "id" : "4",
                     "source" : {
                        "pointer" : "/data/attributes/"
                     },
                     "title" : "Validation error"
                  }
               ]
            },
            "content_type" : "application/vnd.api+json",
            "status" : "400"
         }
      }
   ]
}
