mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -08:00
fix: Resend invite operation on users list (#11351)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
parent
f4958756b4
commit
e4218debd1
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ export class UserService {
|
|||
email,
|
||||
inviteAcceptUrl,
|
||||
emailSent: false,
|
||||
role,
|
||||
},
|
||||
error: '',
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1189,6 +1189,7 @@ export interface IInviteResponse {
|
|||
email: string;
|
||||
emailSent: boolean;
|
||||
inviteAcceptUrl: string;
|
||||
role: IRole;
|
||||
};
|
||||
error?: string;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@ 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(),
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -13,6 +14,10 @@ vi.mock('@/api/users', () => ({
|
|||
loginCurrentUser,
|
||||
}));
|
||||
|
||||
vi.mock('@/api/invitation', () => ({
|
||||
inviteUsers,
|
||||
}));
|
||||
|
||||
vi.mock('@/composables/useTelemetry', () => ({
|
||||
useTelemetry: vi.fn(() => ({
|
||||
identify,
|
||||
|
@ -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: '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,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
})),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue