<commit_before>require 'test_helper'

class ApplePushNotificationsControllerTest < ActionController::TestCase

  def setup
    @user = users(:ben)
    @token = ActionsController.new().send(:authentication_token, @user)
  end

  test "should create push package" do
    raw_post :create, default_params, {authentication_token: @token}.to_json
    assert_response :success
    assert_equal response.header['Content-Type'], "application/zip"
    assert_equal @user, assigns(:user)
  end

  test "should not create push package with invalid token" do
    assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
      raw_post :create, default_params, {authentication_token: "#{@token}s"}.to_json
    end
  end

  test "should destroy device token" do
    set_authorization_header
    patch :update, default_params.merge(device_token: "token")
    assert_difference('Device.count', -1) do
      delete :delete, default_params.merge(device_token: "token")
    end
    assert_response :success
  end

  test "should update device token" do
    set_authorization_header
    assert_difference('Device.count') do
      patch :update, default_params.merge(device_token: "token")
    end
    assert_response :success
  end

  private

  def default_params
    {version: 1, website_push_id: ENV['APPLE_PUSH_WEBSITE_ID']}
  end

  def set_authorization_header
    @request.headers["Authorization"] = "ApplePushNotifications #{@token}"
  end

end
<commit_msg>Update push_id.<commit_after>require 'test_helper'

class ApplePushNotificationsControllerTest < ActionController::TestCase

  def setup
    @user = users(:ben)
    @token = ActionsController.new().send(:authentication_token, @user)
  end

  test "should create push package" do
    raw_post :create, default_params, {authentication_token: @token}.to_json
    assert_response :success
    assert_equal response.header['Content-Type'], "application/zip"
    assert_equal @user, assigns(:user)
  end

  test "should not create push package with invalid token" do
    assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
      raw_post :create, default_params, {authentication_token: "#{@token}s"}.to_json
    end
  end

  test "should destroy device token" do
    set_authorization_header
    patch :update, default_params.merge(device_token: "token")
    assert_difference('Device.count', -1) do
      delete :delete, default_params.merge(device_token: "token")
    end
    assert_response :success
  end

  test "should update device token" do
    set_authorization_header
    assert_difference('Device.count') do
      patch :update, default_params.merge(device_token: "token")
    end
    assert_response :success
  end

  private

  def default_params
    {version: 1, website_push_id: "push_id"}
  end

  def set_authorization_header
    @request.headers["Authorization"] = "ApplePushNotifications #{@token}"
  end

end

{'fraction_non_alphanumeric': 0.09298306256481162, 'fraction_numerical': 0.00138264777048047, 'mean_word_length': 4.5761078998073215, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6959221', 'n_tokens_mistral': 871, 'n_tokens_neox': 842, 'n_words': 213}