Skip to content

Commit

Permalink
test: Add test for membership selector when project not found
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Oct 12, 2023
1 parent b3ba407 commit c86fb67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const generateUser = () => {
};

const generateProject = (
memberships: ProjectMembership[],
memberships: ProjectMembership[] = [],
privacy?: ProjectPrivacy,
): Project => {
const id = uuidv4();
Expand Down Expand Up @@ -107,3 +107,12 @@ test('can select memberships of specific project', () => {
);
expect(memberships).toStrictEqual([[membershipB, user]]);
});

test('not found project returns empty membership', () => {
const store = createStore(initState([], []));
const memberships = selectProjectMembershipsWithUsers(
store.getState(),
'badid',
);
expect(memberships).toStrictEqual([]);
});
2 changes: 1 addition & 1 deletion src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type SharedState } from 'terraso-client-shared/store/store';
import { ProjectMembership } from './project/projectSlice';

const selectProjectMemberships = (state: SharedState, projectId: string) =>
state.project.projects[projectId].memberships;
state.project.projects[projectId]?.memberships ?? [];

const selectUsers = (state: SharedState) => state.account.users;

Expand Down

0 comments on commit c86fb67

Please sign in to comment.