@@ -1788,12 +1788,12 @@ describe('Auth Adapter features', () => {
1788
1788
} ,
1789
1789
} ;
1790
1790
1791
- /* const modernAdapter = {
1791
+ const modernAdapter = {
1792
1792
validateAppId : ( ) => Promise . resolve ( ) ,
1793
1793
validateSetUp : ( ) => Promise . resolve ( ) ,
1794
1794
validateUpdate : ( ) => Promise . resolve ( ) ,
1795
1795
validateLogin : ( ) => Promise . resolve ( ) ,
1796
- }; */
1796
+ } ;
1797
1797
1798
1798
const headers = {
1799
1799
'Content-Type' : 'application/json' ,
@@ -1846,9 +1846,105 @@ describe('Auth Adapter features', () => {
1846
1846
expect ( secondCall [ 3 ] . id ) . toEqual ( user . id ) ;
1847
1847
} ) ;
1848
1848
1849
- xit ( 'should trigger correctly validateSetUp' ) ;
1850
- xit ( 'should trigger correctly validateLogin' ) ;
1851
- xit ( 'should trigger correctly validateUpdate' ) ;
1849
+ it ( 'should trigger correctly validateSetUp' , async ( ) => {
1850
+ spyOn ( modernAdapter , 'validateSetUp' ) . and . resolveTo ( { } ) ;
1851
+ spyOn ( modernAdapter , 'validateUpdate' ) . and . resolveTo ( { } ) ;
1852
+ spyOn ( modernAdapter , 'validateLogin' ) . and . resolveTo ( { } ) ;
1853
+
1854
+ await reconfigureServer ( { auth : { modernAdapter } } ) ;
1855
+ const user = new Parse . User ( ) ;
1856
+
1857
+ await user . save ( { authData : { modernAdapter : { id : 'modernAdapter' } } } ) ;
1858
+
1859
+ expect ( modernAdapter . validateUpdate ) . toHaveBeenCalledTimes ( 0 ) ;
1860
+ expect ( modernAdapter . validateLogin ) . toHaveBeenCalledTimes ( 0 ) ;
1861
+ expect ( modernAdapter . validateSetUp ) . toHaveBeenCalledTimes ( 1 ) ;
1862
+ const call = modernAdapter . validateSetUp . calls . argsFor ( 0 ) ;
1863
+ expect ( call [ 0 ] ) . toEqual ( { id : 'modernAdapter' } ) ;
1864
+ expect ( call [ 1 ] ) . toEqual ( modernAdapter ) ;
1865
+ expect ( call [ 2 ] . config ) . toBeDefined ( ) ;
1866
+ expect ( call [ 2 ] . auth ) . toBeDefined ( ) ;
1867
+ expect ( call [ 2 ] . config . headers ) . toBeDefined ( ) ;
1868
+ expect ( call [ 3 ] ) . toBeUndefined ( ) ;
1869
+ expect ( user . getSessionToken ( ) ) . toBeDefined ( ) ;
1870
+ } ) ;
1871
+ it ( 'should trigger correctly validateLogin' , async ( ) => {
1872
+ spyOn ( modernAdapter , 'validateSetUp' ) . and . resolveTo ( { } ) ;
1873
+ spyOn ( modernAdapter , 'validateUpdate' ) . and . resolveTo ( { } ) ;
1874
+ spyOn ( modernAdapter , 'validateLogin' ) . and . resolveTo ( { } ) ;
1875
+
1876
+ await reconfigureServer ( { auth : { modernAdapter } } ) ;
1877
+ const user = new Parse . User ( ) ;
1878
+
1879
+ // Signup
1880
+ await user . save ( { authData : { modernAdapter : { id : 'modernAdapter' } } } ) ;
1881
+
1882
+ expect ( modernAdapter . validateSetUp ) . toHaveBeenCalledTimes ( 1 ) ;
1883
+ // Login
1884
+ const user2 = new Parse . User ( ) ;
1885
+ await user2 . save ( { authData : { modernAdapter : { id : 'modernAdapter' } } } ) ;
1886
+
1887
+ expect ( modernAdapter . validateUpdate ) . toHaveBeenCalledTimes ( 0 ) ;
1888
+ expect ( modernAdapter . validateSetUp ) . toHaveBeenCalledTimes ( 1 ) ;
1889
+ expect ( modernAdapter . validateLogin ) . toHaveBeenCalledTimes ( 1 ) ;
1890
+ const call = modernAdapter . validateLogin . calls . argsFor ( 0 ) ;
1891
+ expect ( call [ 0 ] ) . toEqual ( { id : 'modernAdapter' } ) ;
1892
+ expect ( call [ 1 ] ) . toEqual ( modernAdapter ) ;
1893
+ expect ( call [ 2 ] . config ) . toBeDefined ( ) ;
1894
+ expect ( call [ 2 ] . auth ) . toBeDefined ( ) ;
1895
+ expect ( call [ 2 ] . config . headers ) . toBeDefined ( ) ;
1896
+ expect ( call [ 3 ] instanceof Parse . User ) . toBeTruthy ( ) ;
1897
+ expect ( call [ 3 ] . id ) . toEqual ( user2 . id ) ;
1898
+ expect ( call [ 3 ] . id ) . toEqual ( user . id ) ;
1899
+ expect ( user2 . getSessionToken ( ) ) . toBeDefined ( ) ;
1900
+ } ) ;
1901
+ it ( 'should trigger correctly validateUpdate' , async ( ) => {
1902
+ spyOn ( modernAdapter , 'validateSetUp' ) . and . resolveTo ( { } ) ;
1903
+ spyOn ( modernAdapter , 'validateUpdate' ) . and . resolveTo ( { } ) ;
1904
+ spyOn ( modernAdapter , 'validateLogin' ) . and . resolveTo ( { } ) ;
1905
+
1906
+ await reconfigureServer ( { auth : { modernAdapter } } ) ;
1907
+ const user = new Parse . User ( ) ;
1908
+
1909
+ // Signup
1910
+ await user . save ( { authData : { modernAdapter : { id : 'modernAdapter' } } } ) ;
1911
+ expect ( modernAdapter . validateSetUp ) . toHaveBeenCalledTimes ( 1 ) ;
1912
+
1913
+ // Save same data
1914
+ await user . save (
1915
+ { authData : { modernAdapter : { id : 'modernAdapter' } } } ,
1916
+ { sessionToken : user . getSessionToken ( ) }
1917
+ ) ;
1918
+
1919
+ // Save same data with master key
1920
+ await user . save (
1921
+ { authData : { modernAdapter : { id : 'modernAdapter' } } } ,
1922
+ { useMasterKey : true }
1923
+ ) ;
1924
+
1925
+ expect ( modernAdapter . validateUpdate ) . toHaveBeenCalledTimes ( 0 ) ;
1926
+ expect ( modernAdapter . validateSetUp ) . toHaveBeenCalledTimes ( 1 ) ;
1927
+ expect ( modernAdapter . validateLogin ) . toHaveBeenCalledTimes ( 0 ) ;
1928
+
1929
+ // Change authData
1930
+ await user . save (
1931
+ { authData : { modernAdapter : { id : 'modernAdapter2' } } } ,
1932
+ { sessionToken : user . getSessionToken ( ) }
1933
+ ) ;
1934
+
1935
+ expect ( modernAdapter . validateUpdate ) . toHaveBeenCalledTimes ( 1 ) ;
1936
+ expect ( modernAdapter . validateSetUp ) . toHaveBeenCalledTimes ( 1 ) ;
1937
+ expect ( modernAdapter . validateLogin ) . toHaveBeenCalledTimes ( 0 ) ;
1938
+ const call = modernAdapter . validateUpdate . calls . argsFor ( 0 ) ;
1939
+ expect ( call [ 0 ] ) . toEqual ( { id : 'modernAdapter2' } ) ;
1940
+ expect ( call [ 1 ] ) . toEqual ( modernAdapter ) ;
1941
+ expect ( call [ 2 ] . config ) . toBeDefined ( ) ;
1942
+ expect ( call [ 2 ] . auth ) . toBeDefined ( ) ;
1943
+ expect ( call [ 2 ] . config . headers ) . toBeDefined ( ) ;
1944
+ expect ( call [ 3 ] instanceof Parse . User ) . toBeTruthy ( ) ;
1945
+ expect ( call [ 3 ] . id ) . toEqual ( user . id ) ;
1946
+ expect ( user . getSessionToken ( ) ) . toBeDefined ( ) ;
1947
+ } ) ;
1852
1948
xit ( 'should throw if no triggers found' ) ;
1853
1949
it ( 'should not update authData if provider return doNotSave' , async ( ) => {
1854
1950
spyOn ( doNotSaveAdapter , 'validateAuthData' ) . and . resolveTo ( { doNotSave : true } ) ;
@@ -1988,14 +2084,32 @@ describe('Auth Adapter features', () => {
1988
2084
} ) ;
1989
2085
1990
2086
const user2 = new Parse . User ( ) ;
1991
- await user2 . save ( {
2087
+ user2 . id = user . id ;
2088
+ await user2 . save (
2089
+ {
2090
+ authData : {
2091
+ baseAdapter : { id : 'baseAdapter' } ,
2092
+ alwaysValidateAdapter : { test : true } ,
2093
+ } ,
2094
+ } ,
2095
+ { sessionToken : user . getSessionToken ( ) }
2096
+ ) ;
2097
+
2098
+ expect ( user2 . get ( 'authDataResponse' ) ) . toEqual ( { alwaysValidateAdapter : { someData2 : true } } ) ;
2099
+
2100
+ const user3 = new Parse . User ( ) ;
2101
+ await user3 . save ( {
1992
2102
authData : {
1993
2103
baseAdapter : { id : 'baseAdapter' } ,
1994
2104
alwaysValidateAdapter : { test : true } ,
1995
2105
} ,
1996
2106
} ) ;
1997
2107
1998
- expect ( user2 . get ( 'authDataResponse' ) ) . toEqual ( { alwaysValidateAdapter : { someData2 : true } } ) ;
2108
+ // On logIn all authData are revalidated
2109
+ expect ( user3 . get ( 'authDataResponse' ) ) . toEqual ( {
2110
+ baseAdapter : { someData : true } ,
2111
+ alwaysValidateAdapter : { someData2 : true } ,
2112
+ } ) ;
1999
2113
2000
2114
const userViaMasterKey = new Parse . User ( ) ;
2001
2115
userViaMasterKey . id = user2 . id ;
0 commit comments