mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-21 05:58:37 -04:00
* Shows notice when user or obs is opted out of Community Taxon on ObsDetails (closes #882) * Unifies mapApiToRealm methods around a single interface * Ensure that the remote obs used on ObsDetail is normalized to look like a local obs * Ensure some tests that use signIn() have isolated Realm instances * Update current user's obs from ObsDetails (closes #1045) * Fixed CC0 license display on ObsDetails (was not actually related to updating the local copy of the obs
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
import { API_HOST } from "components/LoginSignUp/AuthenticationService";
|
|
import i18next from "i18next";
|
|
import inatjs from "inaturalistjs";
|
|
import nock from "nock";
|
|
import RNSInfo from "react-native-sensitive-info";
|
|
import { makeResponse } from "tests/factory";
|
|
|
|
const TEST_JWT = "test-json-web-token";
|
|
const TEST_ACCESS_TOKEN = "test-access-token";
|
|
|
|
async function signOut( options = {} ) {
|
|
const realm = options.realm || global.realm;
|
|
i18next.language = undefined;
|
|
// This is the nuclear option, maybe revisit if it's a source of bugs
|
|
realm.write( ( ) => {
|
|
realm.deleteAll( );
|
|
} );
|
|
await RNSInfo.deleteItem( "username" );
|
|
await RNSInfo.deleteItem( "jwtToken" );
|
|
await RNSInfo.deleteItem( "jwtGeneratedAt" );
|
|
await RNSInfo.deleteItem( "accessToken" );
|
|
inatjs.users.me.mockClear( );
|
|
}
|
|
|
|
async function signIn( user, options = {} ) {
|
|
const realm = options.realm || global.realm;
|
|
await RNSInfo.setItem( "username", user.login );
|
|
await RNSInfo.setItem( "jwtToken", TEST_JWT );
|
|
await RNSInfo.setItem( "jwtGeneratedAt", Date.now( ).toString( ), {} );
|
|
await RNSInfo.setItem( "accessToken", TEST_ACCESS_TOKEN );
|
|
inatjs.users.me.mockResolvedValue( makeResponse( [user] ) );
|
|
user.signedIn = true;
|
|
realm.write( ( ) => {
|
|
realm.create( "User", user, "modified" );
|
|
} );
|
|
nock( API_HOST )
|
|
.post( "/oauth/token" )
|
|
.reply( 200, { access_token: TEST_ACCESS_TOKEN } )
|
|
.get( "/users/edit.json" )
|
|
.reply( 200, { login: user.login, id: user.id } );
|
|
nock( API_HOST, {
|
|
reqheaders: {
|
|
authorization: `Bearer ${TEST_ACCESS_TOKEN}`
|
|
}
|
|
} )
|
|
.get( "/users/api_token.json" )
|
|
.reply( 200, { api_token: "some-jwt" } );
|
|
}
|
|
|
|
export {
|
|
signIn,
|
|
signOut,
|
|
TEST_ACCESS_TOKEN,
|
|
TEST_JWT
|
|
};
|