fix: Resend invite operation on users list (#11351)

Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
Ricardo Espinoza 2024-10-23 10:23:28 +02:00 committed by GitHub
parent f4958756b4
commit e4218debd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 44 additions and 4 deletions

View file

@ -244,7 +244,13 @@ export declare namespace UserRequest {
>; >;
export type InviteResponse = { 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; error?: string;
}; };

View file

@ -130,6 +130,7 @@ export class UserService {
email, email,
inviteAcceptUrl, inviteAcceptUrl,
emailSent: false, emailSent: false,
role,
}, },
error: '', error: '',
}; };

View file

@ -246,6 +246,7 @@ describe('InvitationController', () => {
const { user } = response.body.data[0]; const { user } = response.body.data[0];
expect(user.inviteAcceptUrl).toBeDefined(); expect(user.inviteAcceptUrl).toBeDefined();
expect(user).toHaveProperty('role', 'global:member');
const inviteUrl = new URL(user.inviteAcceptUrl); const inviteUrl = new URL(user.inviteAcceptUrl);

View file

@ -1189,6 +1189,7 @@ export interface IInviteResponse {
email: string; email: string;
emailSent: boolean; emailSent: boolean;
inviteAcceptUrl: string; inviteAcceptUrl: string;
role: IRole;
}; };
error?: string; error?: string;
} }

View file

@ -2,10 +2,11 @@ import type { CurrentUserResponse } from '@/Interface';
import { useUsersStore } from './users.store'; import { useUsersStore } from './users.store';
import { createPinia, setActivePinia } from 'pinia'; import { createPinia, setActivePinia } from 'pinia';
const { loginCurrentUser, identify } = vi.hoisted(() => { const { loginCurrentUser, identify, inviteUsers } = vi.hoisted(() => {
return { return {
loginCurrentUser: vi.fn(), loginCurrentUser: vi.fn(),
identify: vi.fn(), identify: vi.fn(),
inviteUsers: vi.fn(),
}; };
}); });
@ -13,6 +14,10 @@ vi.mock('@/api/users', () => ({
loginCurrentUser, loginCurrentUser,
})); }));
vi.mock('@/api/invitation', () => ({
inviteUsers,
}));
vi.mock('@/composables/useTelemetry', () => ({ vi.mock('@/composables/useTelemetry', () => ({
useTelemetry: vi.fn(() => ({ useTelemetry: vi.fn(() => ({
identify, identify,
@ -58,4 +63,31 @@ describe('users.store', () => {
expect(identify).toHaveBeenCalledWith('test-instance-id', mockUser.id); 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: 'test@n8n.io', emailSent: true, role: 'global:member' },
},
]);
await usersStore.inviteUsers([{ email: 'test@n8n.io', role: 'global:member' }]);
expect(usersStore.allUsers[0]).toMatchObject(
expect.objectContaining({
id: 'random-id',
email: 'test@n8n.io',
role: 'global:member',
isPending: true,
isDefaultUser: false,
isPendingUser: true,
fullName: undefined,
emailSent: true,
}),
);
});
});
}); });

View file

@ -278,9 +278,8 @@ export const useUsersStore = defineStore(STORES.USERS, () => {
const inviteUsers = async (params: Array<{ email: string; role: InvitableRoleName }>) => { const inviteUsers = async (params: Array<{ email: string; role: InvitableRoleName }>) => {
const invitedUsers = await invitationsApi.inviteUsers(rootStore.restApiContext, params); const invitedUsers = await invitationsApi.inviteUsers(rootStore.restApiContext, params);
addUsers( addUsers(
invitedUsers.map(({ user }, index) => ({ invitedUsers.map(({ user }) => ({
isPending: true, isPending: true,
globalRole: { name: params[index].role },
...user, ...user,
})), })),
); );