#!/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]&filter={\"multistate\":\"working\"}"
         },
         "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"
                  }
               ],
               "links" : {
                  "add_fields" : "https://127.0.0.1:80/v1/business_rules/add_fields"
               },
               "meta" : {
                  "count" : 2,
                  "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" : {
            "method" : "post",
            "name" : "Удляем 'working' правило под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/10/action/archive"
         },
         "response" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "actions" : {
                        "restore" : "Restore"
                     },
                     "multistate" : 14,
                     "multistate_name" : "Stopped.\nArchived.\nNeed update."
                  },
                  "id" : "10",
                  "relationships" : {},
                  "type" : "business_rules"
               },
               "links" : {
                  "self" : "https://127.0.0.1:80/v1/business_rules/10"
               },
               "meta" : {
                  "fields" : [
                     "actions",
                     "multistate",
                     "multistate_name"
                  ]
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "200"
         }
      },
      {
         "request" : {
            "method" : "get",
            "name" : "Конечные статусы и позиции, проверям что позиция удалнного=0, а рабочих сместилась на -1 под $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/?$FIELDS[business_rules]&filter=[\"OR\", [ {\"multistate\":\"working\"}, {\"rule_id\": 10 } ] ]"
         },
         "response" : {
            "body" : {
               "data" : [
                  {
                     "attributes" : {
                        "multistate_name" : "Stopped.\nArchived.\nNeed update.",
                        "position" : 0,
                        "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" : 1,
                        "rule_id" : 11
                     },
                     "id" : "11",
                     "links" : {
                        "self" : "https://127.0.0.1:80/v1/business_rules/11"
                     },
                     "relationships" : {},
                     "type" : "business_rules"
                  }
               ],
               "links" : {
                  "add_fields" : "https://127.0.0.1:80/v1/business_rules/add_fields"
               },
               "meta" : {
                  "count" : 2,
                  "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"
         }
      }
   ]
}
