<commit_before><commit_msg>Create unit tests for googlePlayHelper class<commit_after>const StoreUpdate = require('nativescript-store-update')
const GooglePlayHelper = StoreUpdate.GooglePlayHelper

const appId = 'com.nssu.test'
const countryCode = 'ca'
const urlWithCountryCode = `https://play.google.com/store/apps/details?id=${appId}&hl=${countryCode}`
const urlWithoutCountryCode = `https://play.google.com/store/apps/details?id=${appId}`
const storePage = `
<div>
  <div><div itemprop="datePublished">12 Sept 2017</div></div>
  <div><div itemprop="operatingSystems">4.2 and beyond</div></div>
  <div><div itemprop="softwareVersion">1.2.3</div></div>
</div>
`
const storeParsedPage = {
  date: '12 Sept 2017',
  os: '4.2',
  version: '1.2.3',
}

describe('GooglePlayHelper ', function() {
  describe('_getStoreAppUrl function', function() {
    it('should return proper Url', function() {
      expect(GooglePlayHelper._getStoreAppUrl(appId, countryCode)).toEqual(urlWithCountryCode)
    })

    it('should return url without country code if not provided', function() {
      expect(GooglePlayHelper._getStoreAppUrl(appId)).toEqual(urlWithoutCountryCode)
    })
  })

  describe('_parseResource function', function() {
    it('should return parsed resource', function() {
      expect(GooglePlayHelper._parseResource(storePage)).toEqual(storeParsedPage)
    })
  })

  describe('_getAppPage function', function() {
    it('return fetch with Google play lookup url', function() {
      const returnValue = 'Success'
      spyOn(global, 'fetch').and.returnValue(returnValue)
      expect(GooglePlayHelper._getAppPage(appId, countryCode)).toEqual(returnValue)
      expect(global.fetch).toHaveBeenCalledWith(urlWithCountryCode)
    })
  })

  describe('getAppInfos function', function() {
    it('TOFIX - Should return first result', function() {
      const response = {
        status: 200,
        text: () => storePage
      }
      spyOn(global, 'fetch').and.returnValue(Promise.resolve(response))
      console.dir(response)
      GooglePlayHelper.getAppInfos(appId, countryCode)
        .then(result => {
          console.dir(result)
          expect(result).toEqual(storeParsedPage)
        })
    })
  })
})

{'fraction_non_alphanumeric': 0.14208389715832206, 'fraction_numerical': 0.011276499774470004, 'mean_word_length': 4.331730769230769, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '7046632', 'n_tokens_mistral': 677, 'n_tokens_neox': 666, 'n_words': 121}