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 569fa9f commit 15edd44
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 111 deletions.
116 changes: 58 additions & 58 deletions frontend/e2e/init.cafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,66 +85,66 @@ 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()
})
//
// test('Roles', async () => {
// await rolesTest()
// await logout()
// })
142 changes: 89 additions & 53 deletions frontend/e2e/tests/environment-permission-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
byId,
click, clickByText, createEnvironment,
click, clickByText, closeModal, createEnvironment,
createFeature, editRemoteConfig,
gotoTraits,
log,
Expand All @@ -17,75 +17,111 @@ 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('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('User without permissions cannot create traits')
log('User with permissions can view identities')
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 waitForElementVisible('#users-link')
await logout()

log('User without permissions cannot see audit logs')
log('User without permissions cannot add user trait')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await click('#project-select-0')
await waitForElementNotExist(byId('audit-log-link'))
await click('#users-link')
await click(byId('user-item-0'))
await waitForElementNotClickable(byId('add-trait'))
await logout()
*/

log('Create new environment')
log('Grant MANAGE_IDENTITIES permission')
await login(E2E_USER, PASSWORD)
await clickByText('My Test Project 6 Env Permission')
await click('#create-env-link')
await createEnvironment('Production')
await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'MANAGE_IDENTITIES', 'Development', 'environment', 'My Test Project 6 Env Permission' )
await logout()
log('User without permissions cannot see environment')
log('User with permissions can add user trait')
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 click('#users-link')
await click(byId('user-item-0'))
await waitForElementClickable(byId('add-trait'))
await logout()

log('Grant view environment permission')
await login(E2E_USER, PASSWORD)
await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'VIEW_ENVIRONMENT', 'Production', 'project', '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')
log('Remove VIEW_IDENTITIES permission')
await login(E2E_USER, PASSWORD)
await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'VIEW_IDENTITIES', 'Development', 'environment', 'My Test Project 6 Env Permission' )
await logout()

log('User without permissions can update feature state')
log('User without permissions cannot view identities')
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 waitForElementNotExist('#users-link')
}

0 comments on commit 15edd44

Please sign in to comment.