2023-02-25 11:25:54 +01:00
|
|
|
import { randomString } from '../support/random'
|
2021-11-10 00:29:05 +01:00
|
|
|
|
2024-05-10 11:23:34 +02:00
|
|
|
const VALID_PASSWORD = 'hedgE-hog-123%'
|
|
|
|
|
2021-04-16 16:05:02 +02:00
|
|
|
describe('Invite Signup', () => {
|
|
|
|
it('Authenticated user can invite user but cannot use invite for someone else', () => {
|
2023-02-25 11:25:54 +01:00
|
|
|
const user = randomString('user-charlie-')
|
|
|
|
const email = `${user}@posthog.com`
|
|
|
|
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr=menu-item-me]').click()
|
2021-04-16 16:05:02 +02:00
|
|
|
cy.get('[data-attr=top-menu-item-org-settings]').click()
|
|
|
|
|
2024-01-15 10:31:54 +01:00
|
|
|
cy.location('pathname').should('contain', '/settings/organization')
|
2023-11-09 10:08:33 +01:00
|
|
|
cy.get('[id="invites"]').should('exist')
|
2024-03-15 12:43:51 +01:00
|
|
|
cy.contains('Pending invites').should('exist')
|
2021-04-16 16:05:02 +02:00
|
|
|
|
|
|
|
// Test invite creation flow
|
2022-01-14 12:33:18 +01:00
|
|
|
cy.get('[data-attr=invite-teammate-button]').click()
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.get('[data-attr=invite-email-input]').type(email).should('have.value', email)
|
2021-04-16 16:05:02 +02:00
|
|
|
cy.get('[data-attr=invite-team-member-submit]').click()
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.get('[data-attr=invites-table] tbody td').should('contain', email)
|
2021-04-16 16:05:02 +02:00
|
|
|
|
|
|
|
// Assert user cannot use invite for someone else
|
|
|
|
cy.get('[data-attr=invites-table] tbody tr:last-of-type td:nth-last-child(2)').then((element) => {
|
|
|
|
cy.visit(element.text())
|
|
|
|
})
|
2022-08-25 16:07:44 +02:00
|
|
|
cy.get('h2').should('contain', "Oops! This invite link can't be used")
|
2021-04-16 16:05:02 +02:00
|
|
|
cy.get('.error-message div').should('contain', 'This invite is intended for another email address')
|
|
|
|
|
|
|
|
// Delete the invite
|
|
|
|
cy.visit('/organization/members')
|
2022-11-29 17:33:50 +01:00
|
|
|
cy.get('[data-attr=invites-table] [data-attr=invite-delete]').first().click()
|
2022-08-16 09:58:18 +02:00
|
|
|
cy.get('.LemonModal .LemonButton').contains('Yes, cancel invite').click()
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.get('.Toastify__toast-body').should('contain', `Invite for ${email} has been canceled`)
|
|
|
|
cy.get('[data-attr=invites-table] tbody td').should('not.contain', email)
|
2021-04-16 16:05:02 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('New user can use invite', () => {
|
2021-10-19 16:15:11 +02:00
|
|
|
const target_email = `newuser+${Math.floor(Math.random() * 10000)
|
|
|
|
.toString()
|
|
|
|
// Ensure we have a fixed width
|
|
|
|
.padStart(4, '0')}@posthog.com`
|
2021-04-16 16:05:02 +02:00
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/organizations/@current/invites/',
|
|
|
|
body: { target_email: target_email },
|
|
|
|
headers: { Authorization: 'Bearer e2e_demo_api_key' },
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201)
|
2024-08-29 12:51:36 +02:00
|
|
|
cy.get('[data-attr=menu-item-me]').click()
|
|
|
|
cy.get('[data-attr=top-menu-item-logout]').click()
|
2021-04-16 16:05:02 +02:00
|
|
|
cy.visit('/signup/' + response.body.id)
|
|
|
|
})
|
|
|
|
cy.get('.error-view-container').should('not.exist')
|
2022-12-09 14:01:54 +01:00
|
|
|
cy.get('.BridgePage__left').should('contain', "You've been invited to join")
|
2022-11-23 12:55:58 +01:00
|
|
|
cy.get('input[type="email"]').should('have.value', target_email)
|
2024-05-10 11:23:34 +02:00
|
|
|
cy.get('[data-attr="password"]').type(VALID_PASSWORD)
|
2024-01-26 17:03:17 +01:00
|
|
|
cy.get('.LemonProgress__track').should('not.have.css', 'width', '0px') // Password strength indicator is working
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.get('[data-attr="first_name"]').type(randomString('Bob'))
|
2022-11-16 22:35:17 +01:00
|
|
|
cy.get('[data-attr=signup-role-at-organization]').click()
|
2023-04-24 15:08:51 +02:00
|
|
|
cy.get('.Popover li:first-child').click()
|
2022-11-16 22:35:17 +01:00
|
|
|
cy.get('[data-attr=signup-role-at-organization]').contains('Engineering')
|
2021-04-16 16:05:02 +02:00
|
|
|
cy.get('[data-attr=password-signup]').click()
|
2023-05-31 15:24:05 +02:00
|
|
|
cy.location('pathname').should('include', 'verify_email')
|
2021-04-16 16:05:02 +02:00
|
|
|
})
|
2021-05-01 03:21:23 +02:00
|
|
|
|
|
|
|
it('can navigate to organization settings and invite/change users', () => {
|
2023-02-25 11:25:54 +01:00
|
|
|
const user = randomString('user-bob-')
|
|
|
|
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr=menu-item-me]').click()
|
2021-05-01 03:21:23 +02:00
|
|
|
cy.get('[data-attr=top-menu-item-org-settings]').click()
|
2023-11-09 10:08:33 +01:00
|
|
|
cy.location('pathname').should('include', '/settings/organization')
|
2021-05-01 03:21:23 +02:00
|
|
|
|
|
|
|
// Click "Invite team member"
|
|
|
|
cy.get('[data-attr=invite-teammate-button]').first().click()
|
|
|
|
// Enter invite the user
|
|
|
|
cy.get('[data-attr=invite-email-input]').type(`fake+${Math.floor(Math.random() * 10000)}@posthog.com`)
|
2021-10-21 00:02:02 +02:00
|
|
|
cy.get('[data-attr=invite-team-member-submit]').should('not.be.disabled').click()
|
2021-05-01 03:21:23 +02:00
|
|
|
|
|
|
|
// Log in as invited user
|
|
|
|
cy.get('[data-attr=invite-link]')
|
|
|
|
.last()
|
|
|
|
.then((element) => {
|
2024-08-29 12:51:36 +02:00
|
|
|
cy.get('[data-attr=menu-item-me]').click()
|
|
|
|
cy.get('[data-attr=top-menu-item-logout]').click()
|
2021-05-01 03:21:23 +02:00
|
|
|
cy.visit(element.text())
|
|
|
|
})
|
2024-05-10 11:23:34 +02:00
|
|
|
cy.get('[data-attr="password"]').type(VALID_PASSWORD)
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.get('[data-attr="first_name"]').type(user)
|
2022-11-16 22:35:17 +01:00
|
|
|
cy.get('[data-attr=signup-role-at-organization]').click()
|
2023-04-24 15:08:51 +02:00
|
|
|
cy.get('.Popover li:first-child').click()
|
2022-11-16 22:35:17 +01:00
|
|
|
cy.get('[data-attr=signup-role-at-organization]').contains('Engineering')
|
2021-05-01 03:21:23 +02:00
|
|
|
cy.get('[data-attr=password-signup]').click()
|
2023-05-31 15:24:05 +02:00
|
|
|
cy.location('pathname').should('include', 'verify_email')
|
2021-05-01 03:21:23 +02:00
|
|
|
|
|
|
|
// Log out, log in as main
|
2024-08-29 12:51:36 +02:00
|
|
|
cy.visit('/logout')
|
2021-05-01 03:21:23 +02:00
|
|
|
cy.login()
|
|
|
|
|
|
|
|
// Go to organization settings
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr=menu-item-me]').click()
|
2021-05-01 03:21:23 +02:00
|
|
|
cy.get('[data-attr=top-menu-item-org-settings]').click()
|
2023-11-09 10:08:33 +01:00
|
|
|
cy.location('pathname').should('include', '/settings/organization')
|
2021-05-01 03:21:23 +02:00
|
|
|
|
|
|
|
// Change membership level
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.contains('[data-attr=org-members-table] tr', user).within(() => {
|
2024-03-15 12:43:51 +01:00
|
|
|
cy.get('[data-attr=membership-level]').last().should('contain', 'Member')
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.get('[data-attr=more-button]').last().click()
|
|
|
|
})
|
|
|
|
|
|
|
|
// more menu is not within the row
|
2021-05-01 03:21:23 +02:00
|
|
|
cy.get('[data-test-level=8]').click()
|
2023-02-25 11:25:54 +01:00
|
|
|
|
|
|
|
cy.contains('[data-attr=org-members-table] tr', user).within(() => {
|
2024-03-15 12:43:51 +01:00
|
|
|
cy.get('[data-attr=membership-level]').last().should('contain', 'Admin')
|
2023-02-25 11:25:54 +01:00
|
|
|
})
|
2021-05-01 03:21:23 +02:00
|
|
|
|
|
|
|
// Delete member
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.contains('[data-attr=org-members-table] tr', user).within(() => {
|
|
|
|
cy.get('[data-attr=more-button]').last().click()
|
|
|
|
})
|
|
|
|
|
|
|
|
// more menu is not within the row
|
2021-05-01 03:21:23 +02:00
|
|
|
cy.get('[data-attr=delete-org-membership]').last().click()
|
2023-02-25 11:25:54 +01:00
|
|
|
|
2022-08-16 09:58:18 +02:00
|
|
|
cy.get('.LemonModal .LemonButton').last().click()
|
2023-02-25 11:25:54 +01:00
|
|
|
cy.get('.Toastify__toast-body').should('contain', `Removed ${user} from organization`)
|
2021-05-01 03:21:23 +02:00
|
|
|
})
|
2021-04-16 16:05:02 +02:00
|
|
|
})
|