Skip to content

Commit

Permalink
fix: Resend invite operation on users list (#11351)
Browse files Browse the repository at this point in the history
Co-authored-by: Danny Martini <[email protected]>
  • Loading branch information
RicardoE105 and despairblue authored Oct 23, 2024
1 parent f495875 commit e4218de
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/cli/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ export declare namespace UserRequest {
>;

export type InviteResponse = {
user: { id: string; email: string; inviteAcceptUrl?: string; emailSent: boolean };
user: {
id: string;
email: string;
inviteAcceptUrl?: string;
emailSent: boolean;
role: AssignableRole;
};
error?: string;
};

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class UserService {
email,
inviteAcceptUrl,
emailSent: false,
role,
},
error: '',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ describe('InvitationController', () => {
const { user } = response.body.data[0];

expect(user.inviteAcceptUrl).toBeDefined();
expect(user).toHaveProperty('role', 'global:member');

const inviteUrl = new URL(user.inviteAcceptUrl);

Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ export interface IInviteResponse {
email: string;
emailSent: boolean;
inviteAcceptUrl: string;
role: IRole;
};
error?: string;
}
Expand Down
34 changes: 33 additions & 1 deletion packages/editor-ui/src/stores/users.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import type { CurrentUserResponse } from '@/Interface';
import { useUsersStore } from './users.store';
import { createPinia, setActivePinia } from 'pinia';

const { loginCurrentUser, identify } = vi.hoisted(() => {
const { loginCurrentUser, identify, inviteUsers } = vi.hoisted(() => {
return {
loginCurrentUser: vi.fn(),
identify: vi.fn(),
inviteUsers: vi.fn(),
};
});

vi.mock('@/api/users', () => ({
loginCurrentUser,
}));

vi.mock('@/api/invitation', () => ({
inviteUsers,
}));

vi.mock('@/composables/useTelemetry', () => ({
useTelemetry: vi.fn(() => ({
identify,
Expand Down Expand Up @@ -58,4 +63,31 @@ describe('users.store', () => {
expect(identify).toHaveBeenCalledWith('test-instance-id', mockUser.id);
});
});

describe('inviteUsers', () => {
it('should add pending user to the store', async () => {
const usersStore = useUsersStore();

inviteUsers.mockResolvedValueOnce([
{
user: { id: 'random-id', email: '[email protected]', emailSent: true, role: 'global:member' },
},
]);

await usersStore.inviteUsers([{ email: '[email protected]', role: 'global:member' }]);

expect(usersStore.allUsers[0]).toMatchObject(
expect.objectContaining({
id: 'random-id',
email: '[email protected]',
role: 'global:member',
isPending: true,
isDefaultUser: false,
isPendingUser: true,
fullName: undefined,
emailSent: true,
}),
);
});
});
});
3 changes: 1 addition & 2 deletions packages/editor-ui/src/stores/users.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,8 @@ export const useUsersStore = defineStore(STORES.USERS, () => {
const inviteUsers = async (params: Array<{ email: string; role: InvitableRoleName }>) => {
const invitedUsers = await invitationsApi.inviteUsers(rootStore.restApiContext, params);
addUsers(
invitedUsers.map(({ user }, index) => ({
invitedUsers.map(({ user }) => ({
isPending: true,
globalRole: { name: params[index].role },
...user,
})),
);
Expand Down

0 comments on commit e4218de

Please sign in to comment.