Skip to content

Commit

Permalink
Merge pull request #440 from dnum-mi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
clairenollet committed Jun 8, 2023
2 parents 45e315a + a7dfa60 commit 72261b9
Show file tree
Hide file tree
Showing 104 changed files with 2,560 additions and 1,008 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci-dso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include:

vault:read_secret:
stage: read-secret
extends: .vault:read_secret

.build-push-branches:
only:
Expand Down
3 changes: 3 additions & 0 deletions apps/client/cypress/components/specs/environment-form.ct.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import '@/main.css'
import * as icons from '@/icons.js'
import EnvironmentForm from '@/components/EnvironmentForm.vue'
import { createRandomDbSetup } from 'test-utils'
import { useSnackbarStore } from '@/stores/snackbar.js'

describe('EnvironmentForm.vue', () => {
it('Should mount a EnvironmentForm', () => {
const pinia = createPinia()

useSnackbarStore(pinia)

const randomDbSetup = createRandomDbSetup({ envs: [] })

const props = {
Expand Down
102 changes: 93 additions & 9 deletions apps/client/cypress/components/specs/permission-form.ct.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useProjectStore } from '@/stores/project.js'
import { useUserStore } from '@/stores/user.js'

describe('PermissionForm.vue', () => {
it('Should mount a PermissionForm', () => {
it('Should mount a PermissionForm with users to licence', () => {
const pinia = createPinia()

const randomDbSetup = createRandomDbSetup({ nbUsers: 3, envs: ['dev'] })
Expand All @@ -24,6 +24,9 @@ describe('PermissionForm.vue', () => {
userStore.userProfile = randomDbSetup.users[1]

const environment = projectStore.selectedProject?.environments[0]
const ownerPermission = environment.permissions.find(permission => permission.user.email === projectStore.selectedProjectOwner.email)
const userPermission = environment.permissions.find(permission => permission.user.email !== projectStore.selectedProjectOwner.email)

const userToLicence = getRandomUser()
randomDbSetup.project.users = [userToLicence, ...randomDbSetup.project.users]

Expand All @@ -48,37 +51,118 @@ describe('PermissionForm.vue', () => {
.should('contain', `Droits des utilisateurs sur l'environnement de ${props.environment?.name}`)
cy.get('li')
.should('have.length', props.environment.permissions.length)
cy.get('li:first')

cy.getByDataTestid(`userPermissionLi-${ownerPermission.user.email}`)
.within(() => {
cy.getByDataTestid('userEmail')
.should('contain', props.environment.permissions[0].user.email)
.should('contain', ownerPermission.user.email)
.get('input#range')
.should('have.value', props.environment.permissions[0].level)
.should('have.value', ownerPermission.level)
.and('be.disabled')
.getByDataTestid('deletePermissionBtn')
.should('have.attr', 'title', 'Les droits du owner ne peuvent être retirés')
.should('have.attr', 'title', 'Les droits du owner ne peuvent être supprimés')
.and('be.disabled')
.get('[data-testid$=UpdatePermissionBtn]')
.should('be.disabled')
.and('have.attr', 'title', 'Les droits du owner ne peuvent être modifiés')
})
cy.get('li:nth-of-type(2)')

cy.getByDataTestid(`userPermissionLi-${userPermission.user.email}`)
.within(() => {
cy.getByDataTestid('userEmail')
.should('contain', props.environment.permissions[1].user.email)
.should('contain', userPermission.user.email)
.get('input#range')
.should('have.value', props.environment.permissions[1].level)
.should('have.value', userPermission.level)
.and('be.enabled')
.getByDataTestid('deletePermissionBtn')
.should('have.attr', 'title', `Retirer les droits de ${props.environment.permissions[1].user.email}`)
.should('have.attr', 'title', `Supprimer les droits de ${userPermission.user.email}`)
.and('be.enabled')
.get('[data-testid$=UpdatePermissionBtn]')
.should('have.attr', 'title', `Modifier les droits de ${userPermission.user.email}`)
})
cy.getByDataTestid('newPermissionFieldset')
.should('contain', 'Accréditer un membre du projet')
.within(() => {
cy.get('label')
.should('contain', `E-mail de l'utilisateur à accréditer sur l'environnement de ${props.environment?.name}`)
cy.get('.fr-hint-text')
.should('contain', `Entrez l'e-mail d'un membre du projet ${projectStore.selectedProject.name}. Ex : ${userToLicence.email}`)
cy.get('datalist#suggestionList')
.find('option')
.should('have.length', randomDbSetup.project.users.length - props.environment.permissions.length)
.should('have.value', userToLicence.email)
})
})
it('Should mount a PermissionForm with no user to licence', () => {
const pinia = createPinia()

const randomDbSetup = createRandomDbSetup({ nbUsers: 3, envs: ['dev'] })
const projectStore = useProjectStore(pinia)
const userStore = useUserStore(pinia)

projectStore.selectedProject = randomDbSetup.project
projectStore.selectedProjectOwner = randomDbSetup.users[0]
userStore.userProfile = randomDbSetup.users[1]

const environment = projectStore.selectedProject?.environments[0]

const props = {
environment,
}

const extensions = {
use: [
[
VueDsfr, { icons: Object.values(icons) },
],
],
global: {
plugins: [pinia],
},
}

cy.mount(PermissionForm, { extensions, props })

cy.getByDataTestid('newPermissionFieldset')
.should('contain', 'Accréditer un membre du projet')
.within(() => {
cy.get('label')
.should('contain', `E-mail de l'utilisateur à accréditer sur l'environnement de ${props.environment?.name}`)
cy.get('.fr-hint-text')
.should('contain', `Tous les membres du projet ${projectStore.selectedProject.name} sont déjà accrédités.`)
})
})
it('Should mount a PermissionForm without permission for current user', () => {
const pinia = createPinia()

const randomDbSetup = createRandomDbSetup({ nbUsers: 3, envs: ['dev'] })
const projectStore = useProjectStore(pinia)
const userStore = useUserStore(pinia)

projectStore.selectedProject = randomDbSetup.project
projectStore.selectedProjectOwner = randomDbSetup.users[0]
userStore.userProfile = getRandomUser()

const environment = projectStore.selectedProject?.environments[0]

const props = {
environment,
}

const extensions = {
use: [
[
VueDsfr, { icons: Object.values(icons) },
],
],
global: {
plugins: [pinia],
},
}

cy.mount(PermissionForm, { extensions, props })

cy.getByDataTestid('notPermittedAlert')
.should('contain', `Vous n'avez aucun droit sur l'environnement de ${props.environment?.name}. Un membre possédant des droits sur cet environnement peut vous accréditer.`)
})
})
2 changes: 1 addition & 1 deletion apps/client/cypress/components/specs/range.input.ct.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '@gouvfr/dsfr/dist/utility/utility.main.min.css'
import '@/main.css'
import * as icons from '@/icons.js'
import RangeInput from '@/components/RangeInput.vue'
import { levels } from 'shared/src/utils/const.js'
import { levels } from 'shared'

describe('RangeInput.vue', () => {
it('Should mount a RangeInput', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/client/cypress/components/specs/repo-form.ct.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as icons from '@/icons.js'
import RepoForm from '@/components/RepoForm.vue'
import { createRandomDbSetup } from 'test-utils'
import { useProjectStore } from '@/stores/project.js'
import { allOrganizations } from 'shared/src/utils/const.js'
import { allOrganizations } from 'shared'

describe('RepoForm.vue', () => {
it('Should mount a RepoForm', () => {
Expand Down
10 changes: 10 additions & 0 deletions apps/client/cypress/e2e/specs/admin/organizations.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ describe('Administration organizations', () => {
.get(`select#organization-select > option[value="${newOrg.name}"]`)
.should('not.exist')
})

it('Should synchronize organizations from plugins', () => {
cy.intercept('PUT', '/api/v1/admin/organizations/sync/organizations').as('syncOrganizations')

cy.getByDataTestid('syncOrgsBtn')
.click()
.wait('@syncOrganizations')

cy.getByDataTestid('snackbar').should('contain', 'Aucune organisation à synchroniser')
})
})
47 changes: 47 additions & 0 deletions apps/client/cypress/e2e/specs/admin/projects.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getOrganizations } from '../../support/func.js'
import { statusDict, formatDate } from 'shared'

describe('Administration projects', () => {
const organizations = getOrganizations()
let projects

beforeEach(() => {
cy.intercept('GET', 'api/v1/admin/projects').as('getAllProjects')

cy.kcLogin('tcolin')
cy.visit('/admin/projects')
cy.url().should('contain', '/admin/projects')
cy.wait('@getAllProjects', { timeout: 10000 }).its('response').then(response => {
projects = response?.body
?.sort((a, b) => a.name >= b.name ? 1 : -1)
?.map(project => ({
organization: organizations.find(organization => organization.id === project.organization).label,
name: project.name,
description: project.description ?? '',
owner: project.owner,
status: project.status,
locked: project.locked,
createdAt: project.createdAt,
updatedAt: project.updatedAt,
}),
)
})
})

it('Should display projects table, loggedIn as admin', () => {
cy.getByDataTestid('tableAdministrationProjects').within(() => {
projects.forEach((project, index) => {
cy.get(`tbody tr:nth-of-type(${index + 1})`).within(() => {
cy.get('td:nth-of-type(1)').should('contain', project.organization)
cy.get('td:nth-of-type(2)').should('contain', project.name)
cy.get('td:nth-of-type(3)').should('contain', project.description)
cy.get('td:nth-of-type(4)').should('contain', project.owner.email)
cy.get('td:nth-of-type(5) svg title').should('contain', `Le projet ${project.name} est ${statusDict.status[project.status].wording}`)
cy.get('td:nth-of-type(6) svg title').should('contain', `Le projet ${project.name} est ${statusDict.locked[!!project.locked].wording}`)
cy.get('td:nth-of-type(7)').should('contain', formatDate(project.createdAt))
cy.get('td:nth-of-type(8)').should('contain', formatDate(project.updatedAt))
})
})
})
})
})
33 changes: 22 additions & 11 deletions apps/client/cypress/e2e/specs/dashboard.e2e.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getProjectbyId, getUserById } from '../support/func.js'
import { statusDict } from 'shared'

describe('Dashboard', () => {
const projectToArchive = getProjectbyId('9dabf3f9-6c86-4358-8598-65007d78df65')
Expand All @@ -23,19 +24,29 @@ describe('Dashboard', () => {
cy.assertCreateProjects([projectToKeep.name, projectCreated.name, projectFailed.name])
})

it('Should display project status', () => {
it('Should display project statuses', () => {
const projects = [projectCreated, projectFailed]

cy.kcLogin('test')
.goToProjects()
.getByDataTestid(`projectTile-${projectCreated.name}`).click()
.getByDataTestid('menuDashboard').click()
.getByDataTestid(`${projectCreated.status}-badge`)
.should('contain', 'Projet correctement déployé')
projects.forEach(project => {
cy.goToProjects()
.getByDataTestid(`projectTile-${project.name}`).click()
.getByDataTestid('menuDashboard').click()
.getByDataTestid(`${project.id}-${project.status}-badge`)
.should('contain', `Projet ${project.name} : ${statusDict.status[project.status]?.wording}`)
.getByDataTestid(`${project.id}-${project.locked ? '' : 'un'}locked-badge`)
.should('contain', `Projet ${project.name} : ${statusDict.locked[project.locked]?.wording}`)

.goToProjects()
.getByDataTestid(`projectTile-${projectFailed.name}`).click()
.getByDataTestid('menuDashboard').click()
.getByDataTestid(`${projectFailed.status}-badge`)
.should('contain', 'Echec des opérations')
project.repositories?.forEach(repository => {
cy.get(`[data-testid$="-${repository.status}-badge"]`)
.should('contain', `Dépôt ${repository.internalRepoName} : ${statusDict.status[repository.status]?.wording}`)
})

project.environments?.forEach(environment => {
cy.get(`[data-testid$="-${environment.status}-badge"]`)
.should('contain', `Environnement ${environment.name} : ${statusDict.status[environment.status]?.wording}`)
})
})
})

it('Should add, display and edit description', () => {
Expand Down
Loading

0 comments on commit 72261b9

Please sign in to comment.