#!/usr/bin/partner2-test -w
{
   "name" : "Добавление правила с блоками",
   "options" : {
      "fields" : {
         "business_rules" : [
            "rule_id",
            "caption",
            "cpm",
            "conditions",
            "position",
            "multistate",
            "multistate_name",
            "blocks_count"
         ]
      },
      "mock_bk" : true,
      "read_only" : false
   },
   "testcase" : "",
   "tests" : [
      {
         "request" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "blocks" : [
                        "D-A-142898-1",
                        "R-A-41443-1"
                     ],
                     "caption" : "XXX_2",
                     "conditions" : {
                        "browsers" : [
                           2,
                           3
                        ],
                        "query_args" : {
                           "puid10" : [
                              "xxx",
                              "yy"
                           ],
                           "puid20" : [
                              "foo"
                           ]
                        }
                     },
                     "cpm" : 9999
                  },
                  "type" : "business_rules"
               }
            },
            "method" : "post",
            "name" : "Добавление бизнес правила под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules"
         },
         "response" : {
            "body" : {
               "data" : {
                  "attributes" : {},
                  "id" : "22",
                  "links" : {
                     "self" : "https://127.0.0.1:80/v1/business_rules/22"
                  },
                  "relationships" : {},
                  "type" : "business_rules"
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "201"
         }
      },
      {
         "request" : {
            "method" : "get",
            "name" : "Проверка добавленного только что бизнес правила под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules/$LAST_CREATED_ID?$FIELDS[business_rules]"
         },
         "response" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "blocks_count" : 2,
                     "caption" : "XXX_2",
                     "conditions" : {
                        "browsers" : [
                           2,
                           3
                        ],
                        "query_args" : {
                           "puid10" : [
                              "xxx",
                              "yy"
                           ],
                           "puid20" : [
                              "foo"
                           ]
                        }
                     },
                     "cpm" : 9999,
                     "multistate" : 2,
                     "multistate_name" : "Stopped.",
                     "position" : 0,
                     "rule_id" : 22
                  },
                  "id" : "22",
                  "relationships" : {},
                  "type" : "business_rules"
               },
               "links" : {
                  "add_fields" : "https://127.0.0.1:80/v1/business_rules/add_fields",
                  "self" : "https://127.0.0.1:80/v1/business_rules/22"
               },
               "meta" : {
                  "fields" : [
                     "blocks_count",
                     "caption",
                     "conditions",
                     "cpm",
                     "multistate",
                     "multistate_name",
                     "position",
                     "rule_id"
                  ]
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "200"
         }
      },
      {
         "request" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "caption" : "XXX_100500",
                     "conditions" : {
                        "browsers" : [
                           2,
                           3
                        ]
                     },
                     "cpm" : 9999,
                     "login" : "mocked-yan-partner"
                  },
                  "type" : "business_rules"
               }
            },
            "method" : "post",
            "name" : "Добавление бизнес правила c указанием своего логина под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules"
         },
         "response" : {
            "body" : {
               "data" : {
                  "attributes" : {},
                  "id" : "23",
                  "links" : {
                     "self" : "https://127.0.0.1:80/v1/business_rules/23"
                  },
                  "relationships" : {},
                  "type" : "business_rules"
               }
            },
            "content_type" : "application/vnd.api+json",
            "status" : "201"
         }
      },
      {
         "request" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "caption" : "XXX_100500",
                     "conditions" : {
                        "browsers" : [
                           2,
                           3
                        ]
                     },
                     "cpm" : 9999,
                     "login" : "mocked-context-adblock-partner"
                  },
                  "type" : "business_rules"
               }
            },
            "method" : "post",
            "name" : "Добавление бизнес правила для чужого логина (mocked-context-adblock-partner) под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules"
         },
         "response" : {
            "body" : {
               "errors" : [
                  {
                     "detail" : "Login is not yours \"mocked-context-adblock-partner\"",
                     "id" : "4",
                     "source" : {
                        "pointer" : "/data/attributes/login"
                     },
                     "title" : "Validation error"
                  }
               ]
            },
            "content_type" : "application/vnd.api+json",
            "status" : "400"
         }
      },
      {
         "request" : {
            "body" : {
               "data" : {
                  "attributes" : {
                     "blocks" : [
                        "D-A-142898-1",
                        "R-A-41443-1"
                     ],
                     "caption" : "XXX_2",
                     "conditions" : {
                        "browsers" : [
                           2,
                           3
                        ],
                        "query_args" : {
                           "adb_enabled" : [
                              1
                           ],
                           "puid10" : [
                              "xxx",
                              "yy"
                           ],
                           "puid20" : [
                              "foo"
                           ]
                        }
                     },
                     "cpm" : 9999
                  },
                  "type" : "business_rules"
               }
            },
            "method" : "post",
            "name" : "Попытка добавления 'adb_enabled'' бизнес правила под юзером $TOKEN",
            "token" : "mocked-yan-partner",
            "url" : "/v1/business_rules"
         },
         "response" : {
            "body" : {
               "errors" : [
                  {
                     "detail" : "Extra values: adb_enabled",
                     "id" : "4",
                     "source" : {
                        "pointer" : "/data/attributes/conditions/query_args"
                     },
                     "title" : "Validation error"
                  }
               ]
            },
            "content_type" : "application/vnd.api+json",
            "status" : "400"
         }
      }
   ]
}
