<commit_before>require 'test_helper'
require 'licence_identifier_migrator'

class LicenceIdentifierMigratorTest < ActiveSupport::TestCase
  context "update_all" do
    setup do
      LicenceIdentifierMigrator.stubs(:mappings_as_hash).returns({
        1083741393 => "1040001",
        1083741799 => "1620001",
        1084062157 => "1580003",
        1075329002 => "1610001"
      })
      @le1 = LicenceEdition.create(licence_identifier: "1083741799", title: "Licence One", panopticon_id: 123)
      @le2 = LicenceEdition.create(licence_identifier: "9999999999", title: "Licence Two", panopticon_id: 321)
    end
    
    should "update licence editions with a matching licence identifier" do
      silence_stream(STDOUT) do
        LicenceIdentifierMigrator.update_all
      end
      @le1.reload
      assert_equal "1620001", @le1.licence_identifier
    end
    
    should "ignore licence editions without a matching licence identifier" do
      silence_stream(STDOUT) do
        LicenceIdentifierMigrator.update_all
      end
      @le2.reload
      assert_equal "9999999999", @le2.licence_identifier
    end
  end
end<commit_msg>Makes test data look more like the real thing<commit_after>require 'test_helper'
require 'licence_identifier_migrator'

class LicenceIdentifierMigratorTest < ActiveSupport::TestCase
  context "update_all" do
    setup do
      LicenceIdentifierMigrator.stubs(:mappings_as_hash).returns({
        1083741393 => "123-1-1",
        1083741799 => "146-7-1",
        1084062157 => "898-1-1",
        1075329002 => "999-4-1"
      })
      @le1 = LicenceEdition.create(licence_identifier: "1083741799", title: "Licence One", panopticon_id: 123)
      @le2 = LicenceEdition.create(licence_identifier: "9999999999", title: "Licence Two", panopticon_id: 321)
    end
    
    should "update licence editions with a matching licence identifier" do
      silence_stream(STDOUT) do
        LicenceIdentifierMigrator.update_all
      end
      @le1.reload
      assert_equal "146-7-1", @le1.licence_identifier
    end
    
    should "ignore licence editions without a matching licence identifier" do
      silence_stream(STDOUT) do
        LicenceIdentifierMigrator.update_all
      end
      @le2.reload
      assert_equal "9999999999", @le2.licence_identifier
    end
  end
end
{'fraction_non_alphanumeric': 0.0842745438748914, 'fraction_numerical': 0.09730668983492616, 'mean_word_length': 3.3700189753320684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '1451436', 'n_tokens_mistral': 866, 'n_tokens_neox': 714, 'n_words': 163}