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 <[email protected]>
  • Loading branch information
RyanL1997 committed Oct 19, 2022
1 parent 3e538e8 commit 2a6974b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 38 deletions.
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,12 +51,13 @@ 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',
},
indexPatternTenantHeaderSetUp
);
cy.wait(30000);
});

it('should check the saved objects as global tenant', () => {
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 2a6974b

Please sign in to comment.