@@ -1808,6 +1808,157 @@ describe('utils', () => {
1808
1808
} ) ;
1809
1809
} ) ;
1810
1810
1811
+ describe ( 'verifyGeolocationOption' , ( ) => {
1812
+ let utilsearchForOptionGeolocationStub , userOption , testOption ;
1813
+
1814
+ beforeEach ( function ( ) {
1815
+ utilsearchForOptionGeolocationStub = sinon
1816
+ . stub ( utils , 'searchForOption' )
1817
+ . callsFake ( ( ...userOption ) => {
1818
+ return userOption == testOption ;
1819
+ } ) ;
1820
+ } ) ;
1821
+
1822
+ afterEach ( function ( ) {
1823
+ utilsearchForOptionGeolocationStub . restore ( ) ;
1824
+ } ) ;
1825
+
1826
+ it ( '-gl user option' , ( ) => {
1827
+ testOption = '-gl' ;
1828
+ expect ( utils . verifyGeolocationOption ( ) ) . to . be . true ;
1829
+ sinon . assert . calledWithExactly (
1830
+ utilsearchForOptionGeolocationStub ,
1831
+ testOption
1832
+ ) ;
1833
+ } ) ;
1834
+
1835
+ it ( '--gl user option' , ( ) => {
1836
+ testOption = '--gl' ;
1837
+ expect ( utils . verifyGeolocationOption ( ) ) . to . be . true ;
1838
+ sinon . assert . calledWithExactly (
1839
+ utilsearchForOptionGeolocationStub ,
1840
+ testOption
1841
+ ) ;
1842
+ } ) ;
1843
+
1844
+ it ( '-geo-location user option' , ( ) => {
1845
+ testOption = '-geo-location' ;
1846
+ expect ( utils . verifyGeolocationOption ( ) ) . to . be . true ;
1847
+ sinon . assert . calledWithExactly (
1848
+ utilsearchForOptionGeolocationStub ,
1849
+ testOption
1850
+ ) ;
1851
+ } ) ;
1852
+
1853
+ it ( '--geo-location user option' , ( ) => {
1854
+ testOption = '--geo-location' ;
1855
+ expect ( utils . verifyGeolocationOption ( ) ) . to . be . true ;
1856
+ sinon . assert . calledWithExactly (
1857
+ utilsearchForOptionGeolocationStub ,
1858
+ testOption
1859
+ ) ;
1860
+ } ) ;
1861
+
1862
+ it ( '-geolocation user option' , ( ) => {
1863
+ testOption = '-geolocation' ;
1864
+ expect ( utils . verifyGeolocationOption ( ) ) . to . be . true ;
1865
+ sinon . assert . calledWithExactly (
1866
+ utilsearchForOptionGeolocationStub ,
1867
+ testOption
1868
+ ) ;
1869
+ } ) ;
1870
+
1871
+ it ( '--geolocation user option' , ( ) => {
1872
+ testOption = '--geolocation' ;
1873
+ expect ( utils . verifyGeolocationOption ( ) ) . to . be . true ;
1874
+ sinon . assert . calledWithExactly (
1875
+ utilsearchForOptionGeolocationStub ,
1876
+ testOption
1877
+ ) ;
1878
+ } ) ;
1879
+ } ) ;
1880
+
1881
+ describe ( 'setGeolocation' , ( ) => {
1882
+ let verifyGeolocationOptionStub ,
1883
+ glBool ,
1884
+ args ,
1885
+ bsConfig ,
1886
+ geolocation ;
1887
+
1888
+ beforeEach ( function ( ) {
1889
+ verifyGeolocationOptionStub = sinon
1890
+ . stub ( utils , 'verifyGeolocationOption' )
1891
+ . callsFake ( ( ) => glBool ) ;
1892
+
1893
+ args = {
1894
+ geolocation : 'IN' ,
1895
+ } ;
1896
+ } ) ;
1897
+
1898
+ afterEach ( function ( ) {
1899
+ sinon . restore ( ) ;
1900
+ } ) ;
1901
+
1902
+ it ( 'has user provided gl flag' , ( ) => {
1903
+ glBool = true ;
1904
+
1905
+ bsConfig = {
1906
+ run_settings : {
1907
+ geolocation : 'IN' ,
1908
+ } ,
1909
+ } ;
1910
+
1911
+ utils . setGeolocation ( bsConfig , args ) ;
1912
+
1913
+ expect ( bsConfig . run_settings . geolocation ) . to . be . eq (
1914
+ args . geolocation
1915
+ ) ;
1916
+ expect ( bsConfig . run_settings . userProvidedGeolocation ) . to . be . true ;
1917
+ } ) ;
1918
+
1919
+ it ( 'does not have user provided gl flag, sets the value from bsConfig' , ( ) => {
1920
+ glBool = false ;
1921
+ args = {
1922
+ geolocation : null
1923
+ } ;
1924
+ bsConfig = {
1925
+ run_settings : {
1926
+ geolocation : 'IN' ,
1927
+ } ,
1928
+ } ;
1929
+
1930
+ utils . setGeolocation ( bsConfig , args ) ;
1931
+
1932
+ expect ( bsConfig . run_settings . geolocation ) . to . not . be . eq (
1933
+ args . geolocation
1934
+ ) ;
1935
+ expect ( bsConfig . run_settings . geolocation ) . to . be . eq ( 'IN' ) ;
1936
+ expect ( bsConfig . run_settings . userProvidedGeolocation ) . to . be . true ;
1937
+ } ) ;
1938
+
1939
+ it ( 'does not have user provided gl flag and config value, sets geolocation to be null' , ( ) => {
1940
+ geolocation = 'run_settings_geolocation' ;
1941
+ glBool = false ;
1942
+ args = {
1943
+ geolocation : null
1944
+ } ;
1945
+ bsConfig = {
1946
+ run_settings : {
1947
+ geolocation : null ,
1948
+ } ,
1949
+ } ;
1950
+
1951
+ utils . setGeolocation ( bsConfig , args ) ;
1952
+
1953
+ expect ( bsConfig . run_settings . geolocation ) . to . be . eq ( null ) ;
1954
+ expect ( bsConfig . run_settings . userProvidedGeolocation ) . to . be . false ;
1955
+ } ) ;
1956
+
1957
+ afterEach ( function ( ) {
1958
+ verifyGeolocationOptionStub . restore ( ) ;
1959
+ } ) ;
1960
+ } ) ;
1961
+
1811
1962
describe ( 'setDefaults' , ( ) => {
1812
1963
beforeEach ( function ( ) {
1813
1964
delete process . env . BROWSERSTACK_USERNAME ;
0 commit comments