2023-06-26 06:12:46 +03:00
|
|
|
import {expect, test} from '@playwright/test';
|
2023-10-03 12:20:40 +03:00
|
|
|
import {globalDataRequests, limitRequests, mockApi, responseFixtures} from '../../../utils/acceptance';
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
test.describe('User invitations', async () => {
|
|
|
|
test('Supports inviting a user', async ({page}) => {
|
|
|
|
const futureDate = new Date();
|
|
|
|
futureDate.setDate(futureDate.getDate() + 1);
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
2023-09-25 16:03:47 +03:00
|
|
|
browseUsers: {method: 'GET', path: '/users/?limit=100&include=roles', response: responseFixtures.users},
|
2023-08-03 11:29:14 +03:00
|
|
|
browseInvites: {method: 'GET', path: '/invites/', response: responseFixtures.invites},
|
|
|
|
browseRoles: {method: 'GET', path: '/roles/?limit=all', response: responseFixtures.roles},
|
|
|
|
browseAssignableRoles: {method: 'GET', path: '/roles/?limit=all&permissions=assign', response: responseFixtures.roles},
|
|
|
|
addInvite: {method: 'POST', path: '/invites/', response: {
|
|
|
|
invites: [
|
|
|
|
{
|
|
|
|
id: 'new-invite-id',
|
|
|
|
role_id: '645453f3d254799990dd0e18',
|
|
|
|
status: 'sent',
|
|
|
|
email: 'newuser@test.com',
|
|
|
|
expires: futureDate.getTime(),
|
|
|
|
created_at: new Date().toISOString(),
|
|
|
|
updated_at: new Date().toISOString()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}}
|
2023-06-26 06:12:46 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('users');
|
|
|
|
|
2023-09-12 18:15:42 +03:00
|
|
|
await section.getByRole('button', {name: 'Invite people'}).click();
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
const modal = page.getByTestId('invite-user-modal');
|
|
|
|
await modal.getByLabel('Email address').fill('newuser@test.com');
|
|
|
|
await modal.locator('input[value=author]').check();
|
|
|
|
await modal.getByRole('button', {name: 'Send invitation now'}).click();
|
|
|
|
|
2023-09-22 12:05:38 +03:00
|
|
|
await expect(page.getByTestId('toast-success')).toHaveText(/Invitation successfully sent to newuser@test\.com/);
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
await section.getByRole('tab', {name: 'Invited'}).click();
|
|
|
|
|
|
|
|
const listItem = section.getByTestId('user-invite').last();
|
|
|
|
|
|
|
|
await expect(listItem.getByText('newuser@test.com')).toBeVisible();
|
|
|
|
await expect(listItem.getByText('Author')).toBeVisible();
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.addInvite?.body).toEqual({
|
2023-06-26 06:12:46 +03:00
|
|
|
invites: [{
|
|
|
|
email: 'newuser@test.com',
|
|
|
|
expires: null,
|
|
|
|
role_id: '645453f3d254799990dd0e18',
|
|
|
|
status: null,
|
|
|
|
token: null
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Supports resending invitations', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
2023-09-25 16:03:47 +03:00
|
|
|
browseUsers: {method: 'GET', path: '/users/?limit=100&include=roles', response: responseFixtures.users},
|
2023-08-03 11:29:14 +03:00
|
|
|
browseInvites: {method: 'GET', path: '/invites/', response: responseFixtures.invites},
|
|
|
|
deleteInvite: {method: 'DELETE', path: `/invites/${responseFixtures.invites.invites[0].id}/`, response: {}},
|
|
|
|
addInvite: {method: 'POST', path: '/invites/', response: responseFixtures.invites}
|
|
|
|
}});
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('users');
|
|
|
|
await section.getByRole('tab', {name: 'Invited'}).click();
|
|
|
|
|
|
|
|
const listItem = section.getByTestId('user-invite');
|
|
|
|
await listItem.hover();
|
|
|
|
|
|
|
|
await listItem.getByRole('button', {name: 'Resend'}).click();
|
|
|
|
|
2023-09-22 12:05:38 +03:00
|
|
|
await expect(page.getByTestId('toast-success')).toHaveText(/Invitation resent! \(invitee@test\.com\)/);
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
// Resending works by deleting and re-adding the invite
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.deleteInvite?.url).toMatch(new RegExp(`/invites/${responseFixtures.invites.invites[0].id}`));
|
2023-06-26 06:12:46 +03:00
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.addInvite?.body).toEqual({
|
2023-06-26 06:12:46 +03:00
|
|
|
invites: [{
|
|
|
|
email: 'invitee@test.com',
|
|
|
|
expires: null,
|
|
|
|
role_id: '645453f3d254799990dd0e18',
|
|
|
|
status: null,
|
|
|
|
token: null
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Supports revoking invitations', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
2023-09-25 16:03:47 +03:00
|
|
|
browseUsers: {method: 'GET', path: '/users/?limit=100&include=roles', response: responseFixtures.users},
|
2023-08-03 11:29:14 +03:00
|
|
|
browseInvites: {method: 'GET', path: '/invites/', response: responseFixtures.invites},
|
|
|
|
deleteInvite: {method: 'DELETE', path: `/invites/${responseFixtures.invites.invites[0].id}/`, response: {}}
|
|
|
|
}});
|
2023-06-26 06:12:46 +03:00
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('users');
|
|
|
|
await section.getByRole('tab', {name: 'Invited'}).click();
|
|
|
|
|
|
|
|
const listItem = section.getByTestId('user-invite');
|
|
|
|
await listItem.hover();
|
|
|
|
|
|
|
|
await listItem.getByRole('button', {name: 'Revoke'}).click();
|
|
|
|
|
2023-09-22 12:05:38 +03:00
|
|
|
await expect(page.getByTestId('toast-success')).toHaveText(/Invitation revoked \(invitee@test\.com\)/);
|
2023-06-26 06:12:46 +03:00
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.deleteInvite?.url).toMatch(new RegExp(`/invites/${responseFixtures.invites.invites[0].id}`));
|
2023-06-26 06:12:46 +03:00
|
|
|
});
|
2023-08-24 00:04:27 +03:00
|
|
|
|
|
|
|
test('Limits inviting too many staff users', async ({page}) => {
|
|
|
|
await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
...limitRequests,
|
|
|
|
browseAssignableRoles: {method: 'GET', path: '/roles/?limit=all&permissions=assign', response: responseFixtures.roles},
|
|
|
|
browseConfig: {
|
|
|
|
...globalDataRequests.browseConfig,
|
|
|
|
response: {
|
|
|
|
config: {
|
|
|
|
...responseFixtures.config.config,
|
|
|
|
hostSettings: {
|
|
|
|
limits: {
|
|
|
|
staff: {
|
|
|
|
max: 1,
|
|
|
|
error: 'Your plan does not support more staff'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('users');
|
|
|
|
|
2023-09-12 18:15:42 +03:00
|
|
|
await section.getByRole('button', {name: 'Invite people'}).click();
|
2023-08-24 00:04:27 +03:00
|
|
|
|
|
|
|
const modal = page.getByTestId('invite-user-modal');
|
|
|
|
|
|
|
|
await modal.locator('input[value=author]').check();
|
|
|
|
|
|
|
|
await expect(modal).toHaveText(/Your plan does not support more staff/);
|
|
|
|
|
|
|
|
await modal.locator('input[value=contributor]').check();
|
|
|
|
|
|
|
|
await expect(modal).not.toHaveText(/Your plan does not support more staff/);
|
|
|
|
});
|
2023-06-26 06:12:46 +03:00
|
|
|
});
|