Skip to content

Commit

Permalink
More environment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg committed Dec 17, 2024
1 parent 15edd44 commit 3543adc
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 132 deletions.
111 changes: 53 additions & 58 deletions frontend/e2e/init.cafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,66 +85,61 @@ fixture`E2E Tests`.requestHooks(logger).before(async () => {
await logResults(logger.requests, t)
})

// test('Segment-part-1', async () => {
// await testSegment1()
// await logout()
// })
//
// test('Segment-part-2', async () => {
// await testSegment2()
// await logout()
// })
//
// test('Segment-part-3', async () => {
// await testSegment3()
// await logout()
// })
//
// test('Flag', async () => {
// await flagTests()
// await logout()
// })
//
// test('Signup', async () => {
// await initialiseTests()
// await logout()
// })
//
// test('Invite', async () => {
// await inviteTest()
// })
//
// test('Environment', async () => {
// await environmentTest()
// await logout()
// })
//
// test('Project', async () => {
// await projectTest()
// await logout()
// })
//
// test('Versioning', async () => {
// await versioningTests()
// await logout()
// })
//
// test('Organisation-permission', async () => {
// await organisationPermissionTest()
// await logout()
// })
//
// test('Project-permission', async () => {
// await projectPermissionTest()
// await logout()
// })
test('Segment-part-1', async () => {
await testSegment1()
await logout()
})

test('Segment-part-2', async () => {
await testSegment2()
await logout()
})

test('Segment-part-3', async () => {
await testSegment3()
await logout()
})

test('Flag', async () => {
await flagTests()
await logout()
})

test('Signup', async () => {
await initialiseTests()
await logout()
})

test('Invite', async () => {
await inviteTest()
})

test('Environment', async () => {
await environmentTest()
await logout()
})

test('Project', async () => {
await projectTest()
await logout()
})

test('Versioning', async () => {
await versioningTests()
await logout()
})

test('Organisation-permission', async () => {
await organisationPermissionTest()
await logout()
})

test('Project-permission', async () => {
await projectPermissionTest()
await logout()
})

test('Environment-permission', async () => {
await environmentPermissionTest()
await logout()
})
//
// test('Roles', async () => {
// await rolesTest()
// await logout()
// })
162 changes: 91 additions & 71 deletions frontend/e2e/tests/environment-permission-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,77 +17,97 @@ import { Selector, t } from 'testcafe'
import { cli } from 'yaml/dist/cli';

export default async function () {
// log('Login')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// log('User only can see an project')
// await click('#project-select-0')
// await t
// .expect(Selector('#project-select-1').exists)
// .notOk('The element"#project-select-1" should not be present')
// await logout()
//
// log('User with permissions can Handle the Features')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// await click('#project-select-0')
// await createFeature(0, 'test_feature', false)
// await toggleFeature(0, true)
// await logout()
//
// log('User without permissions cannot create traits')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// await click('#project-select-0')
// await gotoTraits()
// const createTraitBtn = Selector(byId('add-trait'))
// await t.expect(createTraitBtn.hasAttribute('disabled')).ok()
// await logout()
//
// log('User without permissions cannot see audit logs')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// await click('#project-select-0')
// await waitForElementNotExist(byId('audit-log-link'))
// await logout()
//
// log('Create new environment')
// await login(E2E_USER, PASSWORD)
// await clickByText('My Test Project 6 Env Permission')
// await click('#create-env-link')
// await createEnvironment('Production')
// await logout()
// log('User without permissions cannot see environment')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// await click('#project-select-0')
// await waitForElementVisible(byId('switch-environment-development'))
// await waitForElementNotExist(byId('switch-environment-production'))
// await logout()
//
// log('Grant view environment permission')
// await login(E2E_USER, PASSWORD)
// await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'VIEW_ENVIRONMENT', 'Production', 'environment', 'My Test Project 6 Env Permission' )
// await logout()
// log('User with permissions can see environment')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// await click('#project-select-0')
// await waitForElementVisible(byId('switch-environment-production'))
// await waitForElementVisible(byId('switch-environment-production'))
// await logout()
//
// log('User with permissions can update feature state')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// await click('#project-select-0')
// await createFeature(0,'my_feature',"foo",'A test feature')
// await editRemoteConfig(0, 'bar')
// await logout()
//
// log('User without permissions cannot update feature state')
// await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
// await click('#project-select-0')
// await waitForElementClickable(byId('feature-switch-0-on'))
// await click(byId('switch-environment-production'))
// await waitForElementNotClickable(byId('feature-switch-0-on'))
// await click(byId('feature-item-0'))
// await waitForElementNotClickable(byId('update-feature-btn'))
// await closeModal()
// await logout()
log('Login')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
log('User only can see an project')
await click('#project-select-0')
await t
.expect(Selector('#project-select-1').exists)
.notOk('The element"#project-select-1" should not be present')
await logout()

log('User with permissions can Handle the Features')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await createFeature(0, 'test_feature', false)
await toggleFeature(0, true)
await logout()

log('User without permissions cannot create traits')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await gotoTraits()
const createTraitBtn = Selector(byId('add-trait'))
await t.expect(createTraitBtn.hasAttribute('disabled')).ok()
await logout()

log('User without permissions cannot see audit logs')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await waitForElementNotExist(byId('audit-log-link'))
await logout()

log('Create new environment')
await login(E2E_USER, PASSWORD)
await clickByText('My Test Project 6 Env Permission')
await click('#create-env-link')
await createEnvironment('Production')
await logout()
log('User without permissions cannot see environment')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await waitForElementVisible(byId('switch-environment-development'))
await waitForElementNotExist(byId('switch-environment-production'))
await logout()

log('Grant view environment permission')
await login(E2E_USER, PASSWORD)
await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'VIEW_ENVIRONMENT', 'Production', 'environment', 'My Test Project 6 Env Permission' )
await logout()
log('User with permissions can see environment')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await waitForElementVisible(byId('switch-environment-production'))
await waitForElementVisible(byId('switch-environment-production'))
await logout()

log('User with permissions can update feature state')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await createFeature(0,'my_feature',"foo",'A test feature')
await editRemoteConfig(0, 'bar')
await logout()
log('User without permission cannot create a segment override')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await click(byId('feature-item-0'))
await click(byId('segment_overrides'))
await waitForElementNotClickable('#update-feature-segments-btn')
await closeModal()
await logout()
log('Grant MANAGE_IDENTITIES permission')
await login(E2E_USER, PASSWORD)
await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'MANAGE_SEGMENT_OVERRIDES', 'Development', 'environment', 'My Test Project 6 Env Permission' )
await logout()
log('User with permission can create a segment override')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await click(byId('feature-item-0'))
await click(byId('segment_overrides'))
await waitForElementClickable('#update-feature-segments-btn')
await closeModal()


log('User without permissions cannot update feature state')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await waitForElementClickable(byId('feature-switch-0-on'))
await click(byId('switch-environment-production'))
await waitForElementNotClickable(byId('feature-switch-0-on'))
await click(byId('feature-item-0'))
await waitForElementNotClickable(byId('update-feature-btn'))
await closeModal()
await logout()

log('User with permissions can view identities')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
Expand Down
6 changes: 3 additions & 3 deletions frontend/web/components/pages/UsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const UsersPage: FC<UsersPageType> = (props) => {
<FormGroup className='float-right'>
<Button
className='float-right'
data-test='show-create-feature-btn'
data-test='show-create-identity-btn'
id='show-create-feature-btn'
onClick={newUser}
>
Expand All @@ -150,8 +150,8 @@ const UsersPage: FC<UsersPageType> = (props) => {
title={
<Button
disabled
data-test='show-create-feature-btn'
id='show-create-feature-btn'
data-test='show-create-identity-btn'
id='show-create-identity-btn'
onClick={newUser}
>
Create Identities
Expand Down

0 comments on commit 3543adc

Please sign in to comment.