<commit_before>require 'test_helper'

module Bookafy
  class CustomerTest < ActiveSupport::TestCase
    setup do
      Bookafy.access_token = '<PASSWORD>'
    end

    test 'should return customers model instance' do
      customer_service = Bookafy::Customer.new
      service = Bookafy::BaseService.new

      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 1}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":0,"customers":[{"id":365,"created_at":"2015-10-08T12:41:56.036+05:00","updated_at":"2015-10-08T12:42:47.348+05:00","name":"Akmal","email":"<EMAIL>","customer_detail_hstore":{"city":"lahore","name":"Akmal","email":"<EMAIL>","state":"punjab","mobile":"03238784647","address":"johar town","zip code":"54000"},"notes":null,"image":{"url":null,"thumb":{"url":null},"small_thumb":{"url":null}},"soft_delete":false}]}}', headers: {})

      customers = customer_service.all

      assert_equal 1, customers.length
      customer = customers.first

      assert_not_equal nil, customer
      assert_equal 365, customer.id
      assert_equal 'Akmal', customer.name
      assert_equal '<EMAIL>', customer.email
    end

    test 'should return all customers when there are more pages' do
      customer_service = Bookafy::Customer.new
      service = Bookafy::BaseService.new

      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 1}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":1,"customers":[{"id":365,"created_at":"2015-10-08T12:41:56.036+05:00","updated_at":"2015-10-08T12:42:47.348+05:00","name":"Akmal","email":"<EMAIL>","customer_detail_hstore":{"city":"lahore","name":"Akmal","email":"<EMAIL>","state":"punjab","mobile":"03238784647","address":"johar town","zip code":"54000"},"notes":null,"image":{"url":null,"thumb":{"url":null},"small_thumb":{"url":null}},"soft_delete":false}]}}', headers: {})
      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 2}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":0,"customers":[{"id":366,"created_at":"2015-11-08T12:41:56.036+05:00","updated_at":"2015-11-08T12:42:47.348+05:00","name":"Lamka","email":"<EMAIL>","customer_detail_hstore":{"city":"lahore","name":"Akmal","email":"<EMAIL>","state":"punjab","mobile":"03238784647","address":"johar town","zip code":"54000"},"notes":null,"image":{"url":null,"thumb":{"url":null},"small_thumb":{"url":null}},"soft_delete":false}]}}', headers: {})

      customers = customer_service.all

      assert_equal 2, customers.length
      customer = customers.first

      assert_not_equal nil, customer
      assert_equal 365, customer.id
      assert_equal 'Akmal', customer.name
      assert_equal '<EMAIL>', customer.email<commit_msg>Add updated query option to tests<commit_after>require 'test_helper'

module Bookafy
  class CustomerTest < ActiveSupport::TestCase
    setup do
      Bookafy.access_token = '<PASSWORD>'
    end

    test 'should return customers model instance' do
      customer_service = Bookafy::Customer.new
      service = Bookafy::BaseService.new

      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 1}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":0,"customers":[{"id":365,"created_at":"2015-10-08T12:41:56.036+05:00","updated_at":"2015-10-08T12:42:47.348+05:00","name":"Akmal","email":"<EMAIL>","customer_detail_hstore":{"city":"lahore","name":"Akmal","email":"<EMAIL>","state":"punjab","mobile":"03238784647","address":"johar town","zip code":"54000"},"notes":null,"image":{"url":null,"thumb":{"url":null},"small_thumb":{"url":null}},"soft_delete":false}]}}', headers: {})

      customers = customer_service.all

      assert_equal 1, customers.length
      customer = customers.first

      assert_not_equal nil, customer
      assert_equal 365, customer.id
      assert_equal 'Akmal', customer.name
      assert_equal '<EMAIL>', customer.email
    end

    test 'should return customers that were updated in the last week' do
      customer_service = Bookafy::Customer.new
      service = Bookafy::BaseService.new

      updated_since = 7.days.ago

      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 1, updated: updated_since.to_i}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":0,"customers":[{"id":365,"created_at":"2015-10-08T12:41:56.036+05:00","updated_at":"2015-10-08T12:42:47.348+05:00","name":"Akmal","email":"<EMAIL>","customer_detail_hstore":{"city":"lahore","name":"Akmal","email":"<EMAIL>","state":"punjab","mobile":"03238784647","address":"johar town","zip code":"54000"},"notes":null,"image":{"url":null,"thumb":{"url":null},"small_thumb":{"url":null}},"soft_delete":false}]}}', headers: {})

      customers = customer_service.all(updated: updated_since.to_i)

      assert_equal 1, customers.length
      customer = customers.first

      assert_not_equal nil, customer
      assert_equal 365, customer.id
      assert_equal 'Akmal', customer.name
      assert_equal '<EMAIL>', customer.email
    end

    test 'should return customers that were updated in the last two days' do
      customer_service = Bookafy::Customer.new
      service = Bookafy::BaseService.new

      updated_since = 2.days.ago

      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 1, updated: updated_since.to_i}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":0,"customers":[]}}', headers: {})

      customers = customer_service.all(updated: updated_since.to_i)

      assert_equal 0, customers.length
      customer = customers.first

      assert_equal nil, customer
    end

    test 'should return all customers when there are more pages' do
      customer_service = Bookafy::Customer.new
      service = Bookafy::BaseService.new

      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 1}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":1,"customers":[{"id":365,"created_at":"2015-10-08T12:41:56.036+05:00","updated_at":"2015-10-08T12:42:47.348+05:00","name":"Akmal","email":"<EMAIL>","customer_detail_hstore":{"city":"lahore","name":"Akmal","email":"<EMAIL>","state":"punjab","mobile":"03238784647","address":"johar town","zip code":"54000"},"notes":null,"image":{"url":null,"thumb":{"url":null},"small_thumb":{"url":null}},"soft_delete":false}]}}', headers: {})
      stub_request(:get, "#{service.bookafy_api_url}customers").with(query: {token: Bookafy.access_token, page: 2}).
          to_return(status: 200, body: '{"response":{"message":"Success","remaining":0,"customers":[{"id":366,"created_at":"2015-11-08T12:41:56.036+05:00","updated_at":"2015-11-08T12:42:47.348+05:00","name":"Lamka","email":"<EMAIL>","customer_detail_hstore":{"city":"lahore","name":"Akmal","email":"<EMAIL>","state":"punjab","mobile":"03238784647","address":"johar town","zip code":"54000"},"notes":null,"image":{"url":null,"thumb":{"url":null},"small_thumb":{"url":null}},"soft_delete":false}]}}', headers: {})

      customers = customer_service.all

      assert_equal 2, customers.length
      customer = customers.first

      assert_not_equal nil, customer
      assert_equal 365, customer.id
      assert_equal 'Akmal', customer.name
      assert_equal '<EMAIL>', customer.email
{'fraction_non_alphanumeric': 0.20138164754953075, 'fraction_numerical': 0.06386861313868614, 'mean_word_length': 6.286799620132953, 'pattern_counts': {'":': 179, '<': 26, '<?xml version=': 0, '>': 24, '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': '3371446', 'n_tokens_mistral': 2827, 'n_tokens_neox': 2455, 'n_words': 334}