Skip to content

Commit

Permalink
Merge pull request #157 from swisstopo/feature/asset-148-elastic-crea…
Browse files Browse the repository at this point in the history
…te-alastic-search-index

Feature 148: Create elastic search index
  • Loading branch information
DmByK authored Jun 13, 2024
2 parents af2e813 + 222faaf commit 760aac1
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 50 deletions.
12 changes: 12 additions & 0 deletions e2e/cypress/e2e/common/create-elastic-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Then, When } from '@badeball/cypress-cucumber-preprocessor';

Then(/^The user should see the sync progress$/, () => {
cy.get('.progress').should('exist').and('be.visible');
});
When(/^The user clicks start sync button$/, () => {
cy.get('button:contains("Synchronisation starten")').click();
});
When(/^A user clicks administration menu button$/, () => {
cy.get('span:contains("Verwaltung")').not(':contains("Benutzer Verwaltung")').click();
cy.wait(1000);
});
45 changes: 45 additions & 0 deletions e2e/cypress/e2e/common/create-test-asset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { assert } from 'chai';
import { Given } from '@badeball/cypress-cucumber-preprocessor';
import { bearerAuth } from '../../support/commands/helper.commands';

const body =
'{"titlePublic":"CypressTestAsset","titleOriginal":"CypressTestAsset","createDate":20240610,"receiptDate":20240610,"publicUse":{"isAvailable":false,"statusAssetUseItemCode":"tobechecked","startAvailabilityDate":null},"internalUse":{"isAvailable":true,"statusAssetUseItemCode":"tobechecked","startAvailabilityDate":null},"assetKindItemCode":"basemap","assetFormatItemCode":"pdf","isNatRel":true,"manCatLabelRefs":["other"],"typeNatRels":[],"assetLanguages":[{"languageItemCode":"DE"}],"assetContacts":[],"ids":[{"idId":null,"id":"123","description":"Beschreibung"}],"studies":[],"assetMainId":null,"siblingAssetIds":[],"newStudies":[],"newStatusWorkItemCode":"initiateAsset"}';

Given('Test asset is created', () => {
cy.window()
.then(win => win.localStorage.getItem('access_token'))
.as('access_token');
cy.get('@access_token').then(token =>
cy.request({
method: 'GET',
url: 'http://localhost:4200/api/search-asset?searchText=CypressTestAsset',
auth: bearerAuth(token),
}).then((response) => {
if (response.body._tag === 'SearchAssetResultEmpty') {
cy.request({
method: 'PUT',
url: 'http://localhost:4200/api/asset-edit',
auth: bearerAuth(token),
body: body,
headers: {
'Content-Type': 'application/json',
},
}).then(response => {
assert.equal(response.status, 200, 'Response status should be 200');
});
}
}));
});

Given('Elastic index is created', () => {
cy.window()
.then(win => win.localStorage.getItem('access_token'))
.as('access_token');
cy.get('@access_token').then(token =>
cy.request({
method: 'GET',
url: '/api/assets/sync',
auth: bearerAuth(token),
}),
);
});
10 changes: 10 additions & 0 deletions e2e/cypress/e2e/create-elastic-index.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Elastic index

Background:
Given The user is logged in
And Test asset is created

Scenario: User creates elastic index
When A user clicks administration menu button
And The user clicks start sync button
Then The user should see the sync progress
8 changes: 5 additions & 3 deletions e2e/cypress/e2e/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ Feature: search

Background:
Given The user is logged in
And Test asset is created
And Elastic index is created

Scenario: Search for test information
When A user types information into the search field
Scenario: Search for test asset
When A user types CypressTestAsset into the search field
And The user clicks enter
Then The user should see a test information in results
Then The user should see the asset in results
11 changes: 6 additions & 5 deletions e2e/cypress/e2e/search/search-steps.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {Then, When} from '@badeball/cypress-cucumber-preprocessor';
import { Then, When } from '@badeball/cypress-cucumber-preprocessor';

Then(/^The user should see a test information in results$/, () => {
Then(/^The user should see the asset in results$/, () => {
cy.get('asset-sg-animate-number:contains("0")', {timeout: 3000}).should('not.exist');
cy.get('.asset-body').should('exist');
cy.get('.search-results div:contains("test")').should('exist');
cy.get('.search-results div:contains("CypressTestAsset")').should('exist');
});
When(/^The user clicks enter$/, () => {
cy.get('.search-input').type('{enter}');
});
When(/^A user types information into the search field$/, () => {
cy.get('.search-input').type('test');
When(/^A user types (.*) into the search field$/, (searchText: string) => {
cy.get('.search-input').type(searchText);
cy.wait(1000);
});
58 changes: 58 additions & 0 deletions e2e/cypress/support/commands/helper.commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
import { assetsBaseUrl } from '../config/config';

//login Eam
/*Cypress.Commands.add('login', (username: string, password: string) => {
cy.visit(assetsBaseUrl);
cy.get('[name="loginWithIdentityProvider"] div input[aria-label="idp-metadata-Swisstopo-BDMS-REF"]').last().click();
cy.get('[type="email"]').type(username);
cy.get('eiam-button[name="continueBtn"]').click();
cy.get('[type="password"]').type(password);
cy.get('eiam-buttonp[name="continueBtn"]').click();
});
*/
export const bearerAuth = token => ({ bearer: token });

Cypress.Commands.add('login', (username: string, password: string) => {
cy.visit(assetsBaseUrl);
cy.get('input[name="username"]').type(username);
cy.get('input[name="password"]').type(password);
cy.get('input[name="signInSubmitButton"]').click();
});

Cypress.Commands.add('login', (username: string, password: string) => {
cy.session(['login', username, password], () => {
cy.visit(assetsBaseUrl);
cy.intercept('http://localhost:4011/connect/token').as('token');
cy.origin('http://localhost:4011', { args: { username, password } }, ({ username, password }) => {
cy.get('#Input_Username').type(username);
cy.get('#Input_Password').type(password);
cy.contains('button', 'Login').click({ force: true });
});
cy.wait('@token')
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.then((interception) => interception.response.body.access_token)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
.then((token) => window.localStorage.setItem('access_token', token));
},
{
validate() {
cy.window()
.then(win => win.localStorage.getItem('access_token'))
.as('access_token');
cy.get('@access_token').then(token =>
cy.request({
method: 'GET',
url: '/api/user',
auth: bearerAuth(token),
}),
);
},
cacheAcrossSpecs: true,
},
);
});

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
//export const bearerAuth = (token) => ({bearer: token});
41 changes: 0 additions & 41 deletions e2e/cypress/support/commands/login.commands.ts

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './commands/login.commands';
import './commands/helper.commands';

declare global {
namespace Cypress {
Expand Down

0 comments on commit 760aac1

Please sign in to comment.