Skip to content

Commit

Permalink
Modify the constants path and fix the 'createIndexPattern()' command
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <jiallian@amazon.com>
  • Loading branch information
RyanL1997 committed Oct 19, 2022
1 parent 3e538e8 commit d6ac8b6
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 41 deletions.
6 changes: 3 additions & 3 deletions cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"viewportWidth": 2000,
"viewportHeight": 1320,
"env": {
"openSearchUrl": "http://localhost:9200",
"SECURITY_ENABLED": false,
"AGGREGATION_VIEW": false,
"openSearchUrl": "https://localhost:9200",
"SECURITY_ENABLED": true,
"AGGREGATION_VIEW": true,
"username": "admin",
"password": "admin",
"ENDPOINT_WITH_PROXY": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import {
SAVED_OBJECTS_PATH,
} from '../../../utils/constants';
} from '../../../utils/dashboards/constants';

import {
ADMIN_AUTH,
Expand Down Expand Up @@ -51,7 +51,7 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) {
title: 's*',
timeFieldName: 'timestamp',
});
cy.createIndexPatternWithTenantHeader('index-pattern2', {
cy.createIndexPattern('index-pattern2', {
title: 'se*',
timeFieldName: 'timestamp',
},
Expand Down
21 changes: 1 addition & 20 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,7 @@ Cypress.Commands.add('bulkUploadDocs', (fixturePath, index) => {
});
});

Cypress.Commands.add('createIndexPattern', (id, attributes) => {
const url = `${
Cypress.config().baseUrl
}/api/saved_objects/index-pattern/${id}`;

cy.request({
method: 'POST',
url,
headers: {
'content-type': 'application/json;charset=UTF-8',
'osd-xsrf': true,
},
body: JSON.stringify({
attributes,
references: [],
}),
});
});

Cypress.Commands.add('createIndexPatternWithTenantHeader', (id, attributes, header = {}) => {
Cypress.Commands.add('createIndexPattern', (id, attributes, header = {}) => {
const url = `${
Cypress.config().baseUrl
}/api/saved_objects/index-pattern/${id}`;
Expand Down
8 changes: 8 additions & 0 deletions cypress/utils/dashboards/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { BASE_PATH } from '../base_constants';

// STACK MANAGEMENT PATH
export const STACK_MANAGEMENT_PATH = BASE_PATH + '/app/management';

export const INDEX_PATTERN_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/indexPatterns';
export const SAVED_OBJECTS_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/objects';
11 changes: 1 addition & 10 deletions cypress/utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,9 @@ declare namespace Cypress {
/**
* Adds an index pattern
* @example
* cy.createIndexPattern('patterId', 'patt*', 'timestamp')
* cy.createIndexPattern('patterId', {'patt*', 'timestamp'})
*/
createIndexPattern<S = any>(
id: string,
attributes: {
title: string;
timeFieldName?: string;
[key: string]: any;
}
): Chainable<S>;

createIndexPatternWithTenantHeader<S = any>(
id: string,
attributes: {
title: string;
Expand Down
52 changes: 52 additions & 0 deletions cypress/utils/plugins/security-dashboards-plugin/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// type definitions for custom commands like "createDefaultTodos"
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable<Subject> {
/**
* Create a test tenant by calling REST API
* @example
* cy.createTenant('test_tenant', tenantJsonFixture )
*/
createTenant<S = any>(
tenantID: string,
tenantJson: string
): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create an internal user by calling REST API
* @example
* cy.createInternalUser('test_user', userJsonFixture )
*/
createInternalUser<S = any>(
userID: string,
userJson: string
): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create a role by calling REST API
* @example
* cy.createRole('role_name', roleJsonFixture )
*/
createRole<S = any>(
roleID: string,
roleJson: string
): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create a role mapping by calling REST API
* @example
* cy.createRoleMapping('role_name', rolemappingJsonFixture )
*/
createRoleMapping<S = any>(
roleID: string,
rolemappingJson: string
): Chainable<S>;
}
}
6 changes: 0 additions & 6 deletions cypress/utils/plugins/security/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,3 @@ export const SEC_API_CACHE_PURGE_PATH = BASE_SEC_API_PATH + '/cache';

export const SEC_API_AUTHINFO_PATH = BASE_PATH + '/api/v1/auth/authinfo';
export const SEC_API_TENANT_PATH = BASE_PATH + '/api/v1/multitenancy/tenant';

// STACK MANAGEMENT PATH
export const STACK_MANAGEMENT_PATH = BASE_PATH + '/app/management';

export const INDEX_PATTERN_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/indexPatterns';
export const SAVED_OBJECTS_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/objects';

0 comments on commit d6ac8b6

Please sign in to comment.