diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 2d3947d07f..c70c4e37e1 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -133,6 +133,10 @@ Cypress.Commands.add('loginViaForm', loginViaForm); * Generate statistic view event for given object. Useful for testing statistics pages with * pre-generated statistics. This just generates a single "hit", but can be called multiple times to * generate multiple hits. + * + * NOTE: This requires that "solr-statistics.autoCommit=false" be set on the DSpace backend + * (as it is in our docker-compose-ci.yml used in CI). + * Otherwise, by default, new statistical events won't be saved until Solr's autocommit next triggers. * @param uuid UUID of object * @param dsoType type of DSpace Object (e.g. "item", "collection", "community") */ @@ -169,9 +173,13 @@ function generateViewEvent(uuid: string, dsoType: string): void { cy.request({ method: 'POST', url: baseRestUrl + '/api/statistics/viewevents', - headers: { [XSRF_REQUEST_HEADER] : csrfToken}, + headers: { + [XSRF_REQUEST_HEADER] : csrfToken, + // use a known public IP address to avoid being seen as a "bot" + 'X-Forwarded-For': '1.1.1.1', + }, //form: true, // indicates the body should be form urlencoded - body: { targetId: uuid, targetType: dsoType } + body: { targetId: uuid, targetType: dsoType }, }).then((resp) => { // We expect a 201 (which means statistics event was created) expect(resp.status).to.eq(201); diff --git a/docker/docker-compose-ci.yml b/docker/docker-compose-ci.yml index ef84c14f43..9ec8fe664a 100644 --- a/docker/docker-compose-ci.yml +++ b/docker/docker-compose-ci.yml @@ -30,6 +30,9 @@ services: db__P__url: 'jdbc:postgresql://dspacedb:5432/dspace' # solr.server: Ensure we are using the 'dspacesolr' image for Solr solr__P__server: http://dspacesolr:8983/solr + # Tell Statistics to commit all views immediately instead of waiting on Solr's autocommit. + # This allows us to generate statistics in e2e tests so that statistics pages can be tested thoroughly. + solr__D__statistics__P__autoCommit: 'false' depends_on: - dspacedb image: dspace/dspace:dspace-7_x-test