Skip to content

Commit

Permalink
Update e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorin95670 committed Oct 30, 2024
1 parent 703b89c commit 880456a
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
83 changes: 83 additions & 0 deletions tests/e2e/features/Secrets.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Feature: Test roundtrip of the application: Secrets

################## List Secrets ##################
## 101 Should display all secrets

################## Filter secret #################
## 201 Should change url on filter key

################## Add secret ##################
## 301 Should successfully add a secret

################## Edit secret ##################
## 401 Should successfully edit a secret

################## Remove secret ##################
## 501 Should successfully remove a secret

Scenario: Roundtrip about Secrets
Given I visit the '/'

When I click on '[data-cy="drawer_item_ai"]'
Then I expect current url is '/ai'

When I click on '[data-cy="page_ai-settings_secrets_tab"]'
Then I expect current url is '/ai\?tab=secrets'
And I set viewport size to '1536' px for width and '960' px for height

####################################################
################## List secrets ####################
####################################################

## 101 Should display all secrets
And I expect '[data-cy="secrets_table"] tbody tr' appear 2 times on screen
And I expect '[data-cy="secrets_table"] tbody tr:nth-child(1) td.secret-key' is 'SONAR_TOKEN'

And I expect '[data-cy="secrets_table"] tbody tr:nth-child(2) td.secret-key' is 'GEMINI_TOKEN'

####################################################
################## Filter key ######################
####################################################

## 201 Should change url on filter name
When I set on '[data-cy="secret_filter_key"]' text 'SONAR'
And I wait 2 seconds
Then I expect current url is 'ai\?tab=secrets&key=SONAR'
And I expect '[data-cy="secrets_table"] tbody tr' appear 1 times on screen
And I expect '[data-cy="secrets_table"] tbody tr:nth-child(1) td.secret-key' is 'SONAR_TOKEN'

####################################################
################## Add secret ######################
####################################################

## 301 Should successfully add a secret
When I click on '[data-cy="secrets_button_add"]'
Then I expect '[data-cy="add-secret-dialog"]' exists

When I set on '[data-cy="secret_field_key"]' text 'key'
And I set on '[data-cy="secret_field_value"]' text 'value'
And I click on '[data-cy="button_confirm"]'
Then I expect 'positive' toast to appear with text 'Secret is added.'

####################################################
################## Edit secret #####################
####################################################

## 401 Should successfully edit a secret
When I click on '[data-cy="user_SONAR_TOKEN_button_edit"]'
Then I expect '[data-cy="edit-secret-dialog"]' exists

When I set on '[data-cy="secret_field_key"]' text 'key'
And I click on '[data-cy="button_confirm"]'
Then I expect 'positive' toast to appear with text 'Secret is updated.'

####################################################
################## Remove secret ###################
####################################################

## 301 Should successfully remove a secret
When I click on '[data-cy="user_SONAR_TOKEN_button_remove"]'
Then I expect '[data-cy="remove-secret-dialog"]' exists

When I click on '[data-cy="button_confirm"]'
Then I expect 'positive' toast to appear with text 'Secret is deleted.'
95 changes: 95 additions & 0 deletions tests/e2e/support/step_definitions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ const defaultResponse = {
size: 10,
totalElements: 0,
};
const secret1 = {
id: '1',
key: 'SONAR_TOKEN',
updateDate: '2024-10-23T14:30:00.000+00:00',
};
const secret2 = {
id: '2',
key: 'GEMINI_TOKEN',
updateDate: '2024-10-23T15:00:00.000+00:00',
};

/**
* User-specific intercepts
Expand Down Expand Up @@ -917,11 +927,96 @@ function setLibraryIntercepts() {
});
}

/**
* Secret-specific intercepts
*/
function setSecretIntercepts() {
cy.intercept('GET', '/api/ai/secrets', (request) => {
request.reply({
statusCode: 200,
body: {
...defaultResponse,
content: [secret1, secret2],
},
});
});

cy.intercept('GET', '/api/ai/secrets?key=lk_*SONAR*', {
statusCode: 200,
body: {
...defaultResponse,
content: [secret1],
},
});

cy.intercept('GET', '/api/ai/secrets/1', {
statusCode: 200,
body: secret1,
});

cy.intercept('GET', '/api/ai/secrets/2', {
statusCode: 200,
body: secret2,
});

cy.intercept('DELETE', '/api/ai/secrets/2', (request) => {
request.reply({ statusCode: 204 });
});

cy.intercept('POST', '/api/ai/secrets', (request) => {
const { key } = request.body;

if (key === 'alreadyExist') {
request.reply({
statusCode: 400,
body: {
message: 'Secret with this key already exists',
},
});
} else {
request.reply({
statusCode: 200,
body: {
id: '1',
},
});
}
});

cy.intercept('PUT', '/api/ai/secrets/1', (request) => {
const { key } = request.body;

if (key === 'notFound') {
request.reply({
statusCode: 400,
body: {
message: 'Other error',
},
});
} else if (key === 'alreadyExist') {
request.reply({
statusCode: 400,
body: {
message: 'Secret with this key already exists',
},
});
} else {
request.reply({
statusCode: 200,
body: {
id: '1',
},
});
}
});
}

Before(() => {
setUserIntercepts();
setGroupIntercepts();
setRoleIntercepts();
setLibraryIntercepts();
setSecretIntercepts();

cy.intercept('GET', '/api/permissions', {
statusCode: 200,
Expand Down

0 comments on commit 880456a

Please sign in to comment.