Skip to content

Commit

Permalink
Environment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg committed Dec 17, 2024
1 parent 976d675 commit 3a59576
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 93 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', async () => {
await environmentTest()
await environmentPermissionTest()
await logout()
})

test('Roles', async () => {
await rolesTest()
await logout()
})
// test('Roles', async () => {
// await rolesTest()
// await logout()
// })
35 changes: 30 additions & 5 deletions frontend/e2e/tests/environment-permission-test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
byId,
click,
click, clickByText, createEnvironment,
createFeature,
gotoTraits,
log,
login,
toggleFeature, waitForElementNotExist
} from "../helpers.cafe";
import { PASSWORD, E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS } from '../config'
login, logout,
toggleFeature, waitForElementNotExist, waitForElementVisible,
} from '../helpers.cafe';
import { PASSWORD, E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, E2E_USER } from '../config';
import { Selector, t } from 'testcafe'

export default async function () {
Expand All @@ -18,13 +18,38 @@ export default async function () {
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 createEnvironment('Production')
await logout()
log('User without permissions cannot see environment')
await waitForElementNotExist(byId('audit-log-link'))
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'))
}
32 changes: 16 additions & 16 deletions frontend/e2e/tests/environment-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import {
import { PASSWORD, E2E_USER } from '../config'

export default async function () {
// log('Login')
// await login(E2E_USER, PASSWORD)
// await click('#project-select-0')
// log('Create environment')
// await click('#create-env-link')
// await createEnvironment('Staging')
// log('Edit Environment')
// await click('#env-settings-link')
// await setText("[name='env-name']", 'Internal')
// await click('#save-env-btn')
// await waitForElementVisible(byId('switch-environment-internal-active'))
// log('Delete environment')
// await click('#delete-env-btn')
// await setText("[name='confirm-env-name']", 'Internal')
// await click('#confirm-delete-env-btn')
// await waitForElementVisible(byId('features-page'))
log('Login')
await login(E2E_USER, PASSWORD)
await click('#project-select-0')
log('Create environment')
await click('#create-env-link')
await createEnvironment('Staging')
log('Edit Environment')
await click('#env-settings-link')
await setText("[name='env-name']", 'Internal')
await click('#save-env-btn')
await waitForElementVisible(byId('switch-environment-internal-active'))
log('Delete environment')
await click('#delete-env-btn')
await setText("[name='confirm-env-name']", 'Internal')
await click('#confirm-delete-env-btn')
await waitForElementVisible(byId('features-page'))
}
30 changes: 16 additions & 14 deletions frontend/web/components/pages/EnvironmentSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,22 @@ const EnvironmentSettingsPage = class extends Component {
{ organisation_id: AccountStore.getOrganisation().id },
{ forceRefetch: true },
).then((roles) => {
getRoleEnvironmentPermissions(
getStore(),
{
env_id: env.id,
organisation_id: AccountStore.getOrganisation().id,
role_id: roles.data.results[0].id,
},
{ forceRefetch: true },
).then((res) => {
const matchingItems = roles.data.results.filter((item1) =>
res.data.results.some((item2) => item2.role === item1.id),
)
this.setState({ roles: matchingItems })
})
if (roles.data.results[0]) {
getRoleEnvironmentPermissions(
getStore(),
{
env_id: env.id,
organisation_id: AccountStore.getOrganisation().id,
role_id: roles.data.results[0].id,
},
{ forceRefetch: true },
).then((res) => {
const matchingItems = roles.data.results.filter((item1) =>
res.data.results.some((item2) => item2.role === item1.id),
)
this.setState({ roles: matchingItems })
})
}
})

if (Utils.getPlansPermission('METADATA')) {
Expand Down

0 comments on commit 3a59576

Please sign in to comment.