Files
iNaturalistReactNative/tests/helpers/user.js
Ken-ichi Ueda f442603e7a Disable unnecessary API requests on My Obs when signed out
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.
2022-12-09 19:39:13 -08:00

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
};