<commit_before>Feature: Publish Queue

  @auth
  Scenario: Add a new transmission entry to the queue
    Given empty "archive"
    And empty "subscribers"
    When we post to "/archive"
    """
    [{"headline": "test"}]
    """
    And we post to "/subscribers" with success
    """
    {
      "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
      "destinations":[{"name":"Test","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
    }
    """
    And we post to "/publish_queue" with success
    """
    {
       "item_id":"#archive._id#","publish_schedule": "2016-05-30T10:00:00+00:00", "subscriber_id":"#subscribers._id#",
       "destination":{"name":"Test","format": "nitf","delivery_type":"email","config":{"recipients":"<EMAIL>"}}
    }
    """
    And we get "/publish_queue"
    Then we get list with 1 items
    """
    {
      "_items":
        [
          {"destination":{"name":"Test"}}
        ]
    }
    """

  @auth
  Scenario: Patch a transmission entry
    Given empty "archive"
    And empty "subscribers"
    When we post to "/archive"
    """
    [{"headline": "test"}]
    """
    And we post to "/subscribers" with success
    """
    {
      "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
      "destinations":[{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
    }
    """
    And we post to "/publish_queue" with success
    """
    {
      "item_id":"#archive._id#","subscriber_id":"#subscribers._id#",
      "destination":{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}
    }
    """
    And we get "/publish_queue"
    Then we get list with 1 items
    """
    {
      "_items":
        [
          {"state":"pending"}
        ]
    }
    """
    When we patch "/publish_queue/#publish_queue._id#"
    """
    {
      "state": "in-progress"
    }
    """
    And we get "/publish_queue"
    Then we get list with 1 items
    """
    {
      "_items":
        [
          {"state":"in-progress"}
        ]
    }
    """

  @auth
  Scenario: Published Item should have published sequence number when published and placed in queue
      Given the "validators"
      """
      [{"_id": "publish_text", "act": "publish", "type": "text", "schema":{}}]
      """
      And "desks"
      """
      [{"name": "Sports"}]
      """
      When we post to "/subscribers" with success
      """
      {
        "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
        "destinations":[{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
      }
      """
      And we post to "/archive" with success
      """
      [{"guid": "123", "headline": "test", "body_html": "body", "state": "fetched",
        "subject":[{"qcode": "17004000", "name": "Statistics"}],
        "task": {"desk": "#desks._id#", "stage": "#desks.incoming_stage#", "user": "#CONTEXT_USER_ID#"}}]
      """
      And we post to "/stages" with success
      """
      [
        {
        "name": "another stage",
        "description": "another stage",
        "task_status": "in_progress",
        "desk": "#desks._id#"
        }
      ]
      """
      And we publish "#archive._id#" with "publish" type and "published" state
      Then we get "publish_sequence_no" in "/published/#archive.123.take_package#"

  @auth @notification
  Scenario: Creating a new publish queue entry should add published sequence number
    Given empty "archive"
    And empty "subscribers"
    When we post to "/archive"
    """
    [{"headline": "test"}]
    """
    When we post to "/subscribers" with success
    """
    {
      "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
      "destinations":[{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
    }
    """
    And we post to "/publish_queue"
    """
    {
       "item_id":"#archive._id#","publish_schedule": "2016-05-30T10:00:00+00:00", "subscriber_id":"#subscribers._id#",
       "destination":{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}
    }
    """
    Then we get "published_seq_num" in "/publish_queue/#archive._id#"
    When we patch "/publish_queue/#publish_queue._id#"
    """
    {"state": "success"}
    """
    Then we get latest
    """
    {"state": "success"}
    """
    And we get notifications
    """
    [{"event": "publish_queue:update", "extra": {"queue_id": "#publish_queue._id#", "state": "success"}}]
    """

  @auth
  Scenario: publish queue us returned in correct order
    Given "publish_queue"
    """
    [{"_id":4, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 4, "published_seq_num": 2},
    {"_id":3, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 4, "published_seq_num": 3},
    {"_id":2, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 3, "published_seq_num": 1},
    {"_id":1, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 2, "published_seq_num": 1}]
    """
    When we get "/publish_queue"
    Then we get list ordered by _id with 4 items<commit_msg>Update publish_queue.feature<commit_after>Feature: Publish Queue

  @auth
  Scenario: Add a new transmission entry to the queue
    Given empty "archive"
    And empty "subscribers"
    When we post to "/archive"
    """
    [{"headline": "test"}]
    """
    And we post to "/subscribers" with success
    """
    {
      "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
      "destinations":[{"name":"Test","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
    }
    """
    And we post to "/publish_queue" with success
    """
    {
       "item_id":"#archive._id#","publish_schedule": "2016-05-30T10:00:00+00:00", "subscriber_id":"#subscribers._id#",
       "destination":{"name":"Test","format": "nitf","delivery_type":"email","config":{"recipients":"<EMAIL>"}}
    }
    """
    And we get "/publish_queue"
    Then we get list with 1 items
    """
    {
      "_items":
        [
          {"destination":{"name":"Test"}}
        ]
    }
    """

  @auth
  Scenario: Patch a transmission entry
    Given empty "archive"
    And empty "subscribers"
    When we post to "/archive"
    """
    [{"headline": "test"}]
    """
    And we post to "/subscribers" with success
    """
    {
      "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
      "destinations":[{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
    }
    """
    And we post to "/publish_queue" with success
    """
    {
      "item_id":"#archive._id#","subscriber_id":"#subscribers._id#",
      "destination":{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}
    }
    """
    And we get "/publish_queue"
    Then we get list with 1 items
    """
    {
      "_items":
        [
          {"state":"pending"}
        ]
    }
    """
    When we patch "/publish_queue/#publish_queue._id#"
    """
    {
      "state": "in-progress"
    }
    """
    And we get "/publish_queue"
    Then we get list with 1 items
    """
    {
      "_items":
        [
          {"state":"in-progress"}
        ]
    }
    """

  @auth
  Scenario: Published Item should have published sequence number when published and placed in queue
      Given the "validators"
      """
      [{"_id": "publish_text", "act": "publish", "type": "text", "schema":{}}]
      """
      And "desks"
      """
      [{"name": "Sports"}]
      """
      When we post to "/subscribers" with success
      """
      {
        "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
        "destinations":[{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
      }
      """
      And we post to "/archive" with success
      """
      [{"guid": "123", "headline": "test", "body_html": "body", "state": "fetched",
        "subject":[{"qcode": "17004000", "name": "Statistics"}],
        "task": {"desk": "#desks._id#", "stage": "#desks.incoming_stage#", "user": "#CONTEXT_USER_ID#"}}]
      """
      And we post to "/stages" with success
      """
      [
        {
        "name": "another stage",
        "description": "another stage",
        "task_status": "in_progress",
        "desk": "#desks._id#"
        }
      ]
      """
      And we publish "#archive._id#" with "publish" type and "published" state
      Then we get "publish_sequence_no" in "/published/#archive.123.take_package#"

  @auth @notification
  Scenario: Creating a new publish queue entry should add published sequence number
    Given empty "archive"
    And empty "subscribers"
    When we post to "/archive"
    """
    [{"headline": "test"}]
    """
    When we post to "/subscribers" with success
    """
    {
      "name":"Channel 3","media_type":"media", "subscriber_type": "digital", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "<EMAIL>",
      "destinations":[{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}]
    }
    """
    And we post to "/publish_queue"
    """
    {
       "item_id":"#archive._id#","publish_schedule": "2016-05-30T10:00:00+00:00", "subscriber_id":"#subscribers._id#",
       "destination":{"name":"destination2","format": "nitf", "delivery_type":"email","config":{"recipients":"<EMAIL>"}}
    }
    """
    Then we get "published_seq_num" in "/publish_queue/#archive._id#"
    When we patch "/publish_queue/#publish_queue._id#"
    """
    {"state": "success"}
    """
    Then we get latest
    """
    {"state": "success"}
    """
    And we get notifications
    """
    [{"event": "publish_queue:update", "extra": {"queue_id": "#publish_queue._id#", "state": "success"}}]
    """

  @auth
  Scenario: publish queue us returned in correct order
    Given "publish_queue"
    """
    [{"_id":4, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 4, "published_seq_num": 2},
    {"_id":3, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 4, "published_seq_num": 3},
    {"_id":2, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 3, "published_seq_num": 1},
    {"_id":1, "_created":"2016-05-30T10:00:00+00:00", "subscriber_id": 2, "published_seq_num": 1}]
    """
    When we get "/publish_queue"
    Then we get list ordered by _id with 4 items
    
{'fraction_non_alphanumeric': 0.2049076421586382, 'fraction_numerical': 0.028793915248098514, 'mean_word_length': 3.130516080777861, 'pattern_counts': {'":': 246, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6249902', 'n_tokens_mistral': 3864, 'n_tokens_neox': 3585, 'n_words': 794}