mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-08-02 10:27:34 -04:00
It prunes stale joined projects after a successful sync
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import fetchUserProjects from "api/usersTyped";
|
||||
import Project from "realmModels/Project";
|
||||
import safeRealmWrite from "sharedHelpers/safeRealmWrite";
|
||||
import syncJoinedProjects from "sharedHelpers/syncJoinedProjects";
|
||||
import factory from "tests/factory";
|
||||
@@ -41,6 +42,26 @@ describe( "syncJoinedProjects", ( ) => {
|
||||
expect( global.realm.objects( "Project" ) ).toHaveLength( 2 );
|
||||
} );
|
||||
|
||||
it( "prunes stale joined projects after a successful sync", async () => {
|
||||
// Local
|
||||
const staleProject = factory( "RemoteProject", { id: 9999 } );
|
||||
Project.upsertRemoteProjects( [staleProject], global.realm );
|
||||
// API
|
||||
const freshProject = factory( "RemoteProject", { id: 1 } );
|
||||
fetchUserProjects.mockResolvedValue(
|
||||
makeUserProjectsResponse( [freshProject] ),
|
||||
);
|
||||
|
||||
await syncJoinedProjects( global.realm, currentUserId );
|
||||
|
||||
expect(
|
||||
global.realm.objectForPrimaryKey( "Project", staleProject.id ),
|
||||
).toBeNull();
|
||||
expect(
|
||||
global.realm.objectForPrimaryKey( "Project", freshProject.id ),
|
||||
).not.toBeNull();
|
||||
} );
|
||||
|
||||
it( "no-ops when currentUserId is missing", async () => {
|
||||
await syncJoinedProjects( global.realm, undefined );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user