<commit_before>require 'spec_helper_min'

describe Carto::DoLicensingService do

  before(:all) do
    @user = FactoryGirl.create(:valid_user, username: 'fulano')
    @redis_key = "do:fulano:datasets"
    @service = Carto::DoLicensingService.new('fulano')
    @dataset_id = 'carto.abc.dataset1'
    @dataset = {
      dataset_id: @dataset_id,
      available_in: ['bq', 'bigtable'],
      price: 100,
      created_at: Time.new(2020, 9, 27, 7, 59, 0),
      expires_at: Time.new(2021, 9, 27, 8, 0, 0),
      status: 'active'
    }
  end

  after(:all) do
    @user.destroy
  end

  after(:each) do
    $users_metadata.del(@redis_key)
  end

  describe '#subscribe' do
    before(:each) do
      @central_mock = mock
      Cartodb::Central.stubs(:new).returns(@central_mock)
      @service.stubs(:get_initial_sync_status).returns('unsynced')
    end

    after(:each) do
      Cartodb::Central.unstub(:new)
      $users_metadata.del(@redis_key)
    end

    it 'calls create_do_datasets from Central with the expected parameters' do
      @central_mock.expects(:create_do_datasets).once.with(username: 'fulano', datasets: [@dataset])
      @service.subscribe(@dataset)
    end

    it 'stores the metadata in Redis' do
      @central_mock.stubs(:create_do_datasets)

      bq_redis = [
        {
          dataset_id: 'carto.abc.dataset1', created_at: '2020-09-27 07:59:00 +0000', expires_at: '2021-09-27 08:00:00 +0000',<commit_msg>fix tests<commit_after>require 'spec_helper_min'

describe Carto::DoLicensingService do

  before(:all) do
    @user = FactoryGirl.create(:valid_user, username: 'fulano')
    @redis_key = "do:fulano:datasets"
    @service = Carto::DoLicensingService.new('fulano')
    @dataset_id = 'carto.abc.dataset1'
    @dataset = {
      dataset_id: @dataset_id,
      available_in: ['bq', 'bigtable'],
      price: 100,
      created_at: Time.new(2020, 9, 27, 7, 59, 0),
      expires_at: Time.new(2021, 9, 27, 8, 0, 0),
      status: 'active'
    }
  end

  after(:all) do
    @user.destroy
  end

  after(:each) do
    $users_metadata.del(@redis_key)
  end

  describe '#subscribe' do
    before(:each) do
      @central_mock = mock
      @doss = mock
      Cartodb::Central.stubs(:new).returns(@central_mock)
      Carto::DoSyncServiceFactory.stubs(:get_for_user).returns(@doss)
      @doss.stubs(:entity_info).returns({})
      @service.stubs(:get_initial_sync_status).returns('unsynced')
    end

    after(:each) do
      Cartodb::Central.unstub(:new)
      $users_metadata.del(@redis_key)
    end

    it 'calls create_do_datasets from Central with the expected parameters' do
      @central_mock.expects(:create_do_datasets).once.with(username: 'fulano', datasets: [@dataset])
      @service.subscribe(@dataset)
    end

    it 'stores the metadata in Redis' do
      @central_mock.stubs(:create_do_datasets)

      bq_redis = [
        {
          dataset_id: 'carto.abc.dataset1', created_at: '2020-09-27 07:59:00 +0000', expires_at: '2021-09-27 08:00:00 +0000',
{'fraction_non_alphanumeric': 0.1376545272302038, 'fraction_numerical': 0.0414300033411293, 'mean_word_length': 3.39647577092511, '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': '5100520', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1050, 'n_words': 204}