<commit_before>require 'rails_helper'

describe APNS::DeliverNotification do
  context 'when called without an endpoint_arn' do
    it 'fails with an error message' do
      result = described_class.call(notification: Notification.new)

      expect(result).to_not be_success
      expect(result.message).to eq 'Missing required argument: endpoint_arn'
    end
  end

  context 'when called without a notification' do
    it 'fails with an error message' do
      result = described_class.call(endpoint_arn: Faker::Ello.sns_apns_endpoint_arn)

      expect(result).to_not be_success
      expect(result.message).to eq 'Missing required argument: notification'
    end
  end

  context 'when called with required arguments' do
    let(:sns_client) { Aws::SNS::Client.new }

    let(:notification) { build(:notification, metadata: { some_key: 'value' }) }

    before { allow(Aws::SNS::Client).to receive(:new).and_return(sns_client) }

    it 'delivers the notification with SNS' do
      endpoint_arn = Faker::Ello.sns_apns_endpoint_arn
      expect(sns_client).to receive(:publish)
      # expect(sns_client).to receive(:publish).with({
        # target_arn: endpoint_arn,
        # message_structure: 'json',
        # message: kind_of(String)
      # })

      described_class.call({<commit_msg>Switching back to more explicit test<commit_after>require 'rails_helper'

describe APNS::DeliverNotification do
  context 'when called without an endpoint_arn' do
    it 'fails with an error message' do
      result = described_class.call(notification: Notification.new)

      expect(result).to_not be_success
      expect(result.message).to eq 'Missing required argument: endpoint_arn'
    end
  end

  context 'when called without a notification' do
    it 'fails with an error message' do
      result = described_class.call(endpoint_arn: Faker::Ello.sns_apns_endpoint_arn)

      expect(result).to_not be_success
      expect(result.message).to eq 'Missing required argument: notification'
    end
  end

  context 'when called with required arguments' do
    let(:sns_client) { Aws::SNS::Client.new }

    let(:notification) { build(:notification, metadata: { some_key: 'value' }) }

    before { allow(Aws::SNS::Client).to receive(:new).and_return(sns_client) }

    it 'delivers the notification with SNS' do
      endpoint_arn = Faker::Ello.sns_apns_endpoint_arn
      expect(sns_client).to receive(:publish).with({
        target_arn: endpoint_arn,
        message_structure: 'json',
        message: kind_of(String)
      })

      described_class.call({
{'fraction_non_alphanumeric': 0.09793211080764729, 'fraction_numerical': 0.0, 'mean_word_length': 3.801498127340824, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5136136', 'n_tokens_mistral': 778, 'n_tokens_neox': 751, 'n_words': 194}