mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-19 05:01:07 -04:00
Also added a signOut test helper... and maybe have introduced some problems with parallel test execution as a result, as parallel jest runs don't seem to totally separate with regards to the in-memory realm db. Something to think about.
33 lines
968 B
JavaScript
33 lines
968 B
JavaScript
import inatjs from "inaturalistjs";
|
|
import RNSInfo from "react-native-sensitive-info";
|
|
|
|
import { makeResponse } from "../factory";
|
|
|
|
async function signOut( ) {
|
|
// This is the nuclear option, maybe revisit if it's a source of bugs
|
|
global.realm.write( ( ) => {
|
|
global.realm.deleteAll( );
|
|
} );
|
|
await RNSInfo.deleteItem( "username" );
|
|
await RNSInfo.deleteItem( "jwtToken" );
|
|
await RNSInfo.deleteItem( "jwtTokenExpiration" );
|
|
await RNSInfo.deleteItem( "accessToken" );
|
|
}
|
|
|
|
async function signIn( user ) {
|
|
await RNSInfo.setItem( "username", user.login );
|
|
await RNSInfo.setItem( "jwtToken", "yaddayadda" );
|
|
await RNSInfo.setItem( "jwtTokenExpiration", Date.now( ).toString( ), {} );
|
|
await RNSInfo.setItem( "accessToken", "yaddayadda" );
|
|
inatjs.users.me.mockResolvedValue( makeResponse( [user] ) );
|
|
user.signedIn = true;
|
|
global.realm.write( ( ) => {
|
|
global.realm.create( "User", user, "modified" );
|
|
} );
|
|
}
|
|
|
|
export {
|
|
signIn,
|
|
signOut
|
|
};
|