Skip to content

Commit

Permalink
(PC-32310)[PRO] test: finish e2e migration CollectiveBooking
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliochka authored and scolson-pass committed Oct 21, 2024
1 parent 9c9453e commit aaafc7d
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 100 deletions.
33 changes: 33 additions & 0 deletions api/src/pcapi/sandboxes/scripts/getters/pro.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from pcapi.core.categories import subcategories_v2 as subcategories
from pcapi.core.educational import models as educational_models
import pcapi.core.educational.factories as educational_factories
Expand Down Expand Up @@ -168,3 +170,34 @@ def create_pro_user_with_collective_offers() -> dict:
formats=[subcategories.EacFormat.PROJECTION_AUDIOVISUELLE],
)
return {"user": get_pro_user_helper(pro_user)}


def create_pro_user_with_collective_bookings() -> dict:
pro_user = users_factories.ProFactory()
offerer = offerers_factories.OffererFactory()
offerers_factories.UserOffererFactory(user=pro_user, offerer=offerer)
venue = offerers_factories.VenueFactory(name="Mon Lieu", managingOfferer=offerer, isPermanent=True)
offerers_factories.VirtualVenueFactory(managingOfferer=offerer)

collectiveStock = educational_factories.CollectiveStockFactory(
collectiveOffer__venue=venue,
collectiveOffer__name="Mon offre",
beginningDatetime=datetime.datetime.utcnow() + datetime.timedelta(days=10),
)
collectiveStock_B = educational_factories.CollectiveStockFactory(
collectiveOffer__venue=venue, collectiveOffer__name="Mon autre offre"
)
educational_factories.CollectiveBookingFactory(collectiveStock=collectiveStock)
educational_factories.CollectiveBookingFactory(
collectiveStock__collectiveOffer__name="Encore une autre offre",
collectiveStock__beginningDatetime=datetime.datetime.utcnow() + datetime.timedelta(days=10),
collectiveStock__collectiveOffer__venue=venue,
educationalInstitution__name="Autre collège",
)
educational_factories.CollectiveBookingFactory(
collectiveStock=collectiveStock_B, educationalInstitution__name="Autre établissement"
)
educational_factories.CollectiveBookingFactory(
collectiveStock=collectiveStock_B, educationalInstitution__name="Victor Hugo"
)
return {"user": get_pro_user_helper(pro_user)}
177 changes: 77 additions & 100 deletions pro/cypress/e2e/migrations/collectiveBooking.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { addDays, format } from 'date-fns'

function expectOffersAreFound(expectedResults: Array<Array<string>>) {
for (let rowLine = 0; rowLine < expectedResults.length - 1; rowLine++) {
const offerLineArray = expectedResults[rowLine + 1]
Expand All @@ -24,50 +26,46 @@ function expectOffersAreFound(expectedResults: Array<Array<string>>) {
}
}

describe('Search for collective bookings', () => {
const login = 'retention_structures@example.com'
function IGoToCollectivePage(login: string) {
const password = 'user@AZERTY123'

cy.stepLog({ message: 'I am logged in' })
cy.login({
email: login,
password: password,
redirectUrl: '/',
})
cy.findAllByTestId('spinner').should('not.exist')

cy.stepLog({ message: 'I open the "reservations/collectives" page' })
cy.visit('/reservations/collectives')
}

describe('Search for collective bookings', () => {
let login: string

beforeEach(() => {
cy.visit('/connexion')
// cy.request({
// method: 'GET',
// url: 'http://localhost:5001/sandboxes/pro/create_regular_pro_user',
// }).then((response) => {
// login = response.body.user.email
// })
// I am logged in with account 1

cy.stepLog({ message: 'I am logged in' })
cy.login({
email: login,
password: password,
redirectUrl: '/',
cy.request({
method: 'GET',
url: 'http://localhost:5001/sandboxes/pro/create_pro_user_with_collective_bookings',
}).then((response) => {
login = response.body.user.email
})

cy.stepLog({ message: 'I select offerer "eac_2_lieu [BON EAC]"' })
cy.findByTestId('offerer-select').click()
cy.findByText(/Changer de structure/).click()
cy.findByTestId('offerers-selection-menu')
.findByText('eac_2_lieu [BON EAC]')
.click()
cy.findByTestId('header-dropdown-menu-div').should('not.exist')
cy.findAllByTestId('spinner').should('not.exist')

cy.stepLog({ message: 'I open the "reservations/collectives" page' })
cy.visit('/reservations/collectives')
})

it('It should find collective bookings by offers', () => {
cy.stepLog({ message: 'I display offers' })
IGoToCollectivePage(login)

cy.stepLog({ message: 'I display bookings' })
cy.findByText('Afficher').click()
cy.findByTestId('spinner').should('not.exist')

cy.stepLog({ message: 'I search for "Offre" with text "offer 39"' })
cy.stepLog({ message: 'I search for "Offre" with text "Mon offre"' })
cy.findByTestId('select-omnisearch-criteria').select('Offre')
cy.findByTestId('omnisearch-filter-input-text').type('offer 39')
cy.findByTestId('omnisearch-filter-input-text').type('Mon offre')

cy.stepLog({ message: 'these 1 results should be displayed' })
cy.stepLog({ message: '1 result should be displayed' })
const expectedResults = [
[
'Réservation',
Expand All @@ -76,33 +74,26 @@ describe('Search for collective bookings', () => {
'Places et prix',
'Statut',
],
[
'80',
'offer',
'ECOLE ELEMENTAIRE PUBLIQUE FRANCOIS MOISSON',
'25 places100 €',
'annulée',
],
['1', 'Mon offre', 'COLLEGE DE LA TOUR', '25 places100 €', 'confirmée'],
]

expectOffersAreFound(expectedResults)
})

it('It should find collective bookings by establishments', () => {
cy.stepLog({ message: 'I display offers' })
IGoToCollectivePage(login)

cy.stepLog({ message: 'I display bookings' })
cy.findByText('Afficher').click()
cy.findByTestId('spinner').should('not.exist')

cy.stepLog({
message:
'I search for "Établissement" with text "LYCEE POLYVALENT METIER ROBERT DOISNEAU"',
message: 'I search for "Établissement" with text "Victor Hugo"',
})
cy.findByTestId('select-omnisearch-criteria').select('Établissement')
cy.findByTestId('omnisearch-filter-input-text').type(
'LYCEE POLYVALENT METIER ROBERT DOISNEAU'
)
cy.findByTestId('omnisearch-filter-input-text').type('Victor Hugo')

cy.stepLog({ message: 'These 6 results should be displayed' })
cy.stepLog({ message: '1 result should be displayed' })
const expectedResults = [
[
'Réservation',
Expand All @@ -112,63 +103,30 @@ describe('Search for collective bookings', () => {
'Statut',
],
[
'79',
'offer',
'LYCEE POLYVALENT METIER ROBERT DOISNEAU',
'25 places100 €',
'annulée',
],
[
'72',
'offer',
'LYCEE POLYVALENT METIER ROBERT DOISNEAU',
'25 places100 €',
'annulée',
],
[
'65',
'offer',
'LYCEE POLYVALENT METIER ROBERT DOISNEAU',
'25 places100 €',
'remboursée',
],
[
'58',
'offer',
'LYCEE POLYVALENT METIER ROBERT DOISNEAU',
'25 places100 €',
'terminée',
],
[
'51',
'offer',
'LYCEE POLYVALENT METIER ROBERT DOISNEAU',
'4',
'Mon autre offre',
'COLLEGE Victor Hugo',
'25 places100 €',
'confirmée',
],
[
'44',
'offer',
'LYCEE POLYVALENT METIER ROBERT DOISNEAU',
'25 places100 €',
'préréservée',
],
]
expectOffersAreFound(expectedResults)
})

it('It should find collective bookings by booking number', () => {
cy.stepLog({ message: 'I display offers' })
IGoToCollectivePage(login)

cy.stepLog({ message: 'I display bookings' })
cy.findByText('Afficher').click()
cy.findByTestId('spinner').should('not.exist')

cy.stepLog({
message: 'I search for "Numéro de réservation" with text "66"',
message: 'I search for "Numéro de réservation" with text "2"',
})
cy.findByTestId('select-omnisearch-criteria').select(
'Numéro de réservation'
)
cy.findByTestId('omnisearch-filter-input-text').type('66')
cy.findByTestId('omnisearch-filter-input-text').type('2')

cy.stepLog({ message: '1 result should be displayed' })
const expectedResults = [
Expand All @@ -180,24 +138,43 @@ describe('Search for collective bookings', () => {
'Statut',
],
[
'66',
'offer',
'ECOLE ELEMENTAIRE PUBLIQUE FRANCOIS MOISSON',
'2',
'Encore une autre offre',
'COLLEGE Autre collège',
'25 places100 €',
'annulée',
'confirmée',
],
]
expectOffersAreFound(expectedResults)
})

// # @todo: faire un cas de recherche par date (comme dans https://github.com/pass-culture/pass-culture-main/pull/12931) + établissement
// # Scenario: It should find collective bookings with two filters
// # When I fill venue with "real_venue 1 eac_2_lieu [BON EAC]"
// # And I display offers
// # And I search for "Établissement" with text "ECOLE ELEMENTAIRE PUBLIQUE FRANCOIS MOISSON"
// # Then These results should be displayed
// # | Réservation | Nom de l'offre | Établissement | Places et prix | Statut |
// # | 80 | offer | ECOLE ELEMENTAIRE PUBLIQUE FRANCOIS MOISSON | 25 places100 € | annulée |
// # | 66 | offer | ECOLE ELEMENTAIRE PUBLIQUE FRANCOIS MOISSON | 25 places100 € | annulée |
// # | 52 | offer | ECOLE ELEMENTAIRE PUBLIQUE FRANCOIS MOISSON | 25 places100 € | confirmée |
it('It should find collective bookings by date and by establishment', () => {
IGoToCollectivePage(login)

const dateSearch = format(addDays(new Date(), 10), 'yyyy-MM-dd')
cy.findByLabelText('Date de l’évènement').type(dateSearch)

cy.stepLog({ message: 'I display bookings' })
cy.findByText('Afficher').click()
cy.findByTestId('spinner').should('not.exist')

cy.stepLog({
message: 'I search for "Établissement" with text "COLLEGE DE LA TOUR"',
})
cy.findByTestId('select-omnisearch-criteria').select('Établissement')
cy.findByTestId('omnisearch-filter-input-text').type('COLLEGE DE LA TOUR')

cy.stepLog({ message: '1 result should be displayed' })
const expectedResults = [
[
'Réservation',
"Nom de l'offre",
'Établissement',
'Places et prix',
'Statut',
],
['1', 'Mon offre', 'COLLEGE DE LA TOUR', '25 places100 €', 'confirmée'],
]
expectOffersAreFound(expectedResults)
})
})

0 comments on commit aaafc7d

Please sign in to comment.