2023-11-01 10:36:41 +05:30
|
|
|
/*
|
|
|
|
* Copyright 2023 Collate.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2023-11-11 00:08:32 +05:30
|
|
|
|
|
|
|
import {
|
|
|
|
DATABASE_DETAILS,
|
|
|
|
DATABASE_SERVICE_DETAILS,
|
|
|
|
SCHEMA_DETAILS,
|
2023-11-27 15:31:52 +05:30
|
|
|
} from '../constants/EntityConstant';
|
2023-11-11 00:08:32 +05:30
|
|
|
import { uuid } from './common';
|
|
|
|
|
2023-11-01 10:36:41 +05:30
|
|
|
/**
|
|
|
|
* create full hierarchy of database service (service > database > schema > tables)
|
|
|
|
*/
|
|
|
|
export const createEntityTable = ({
|
|
|
|
service,
|
|
|
|
database,
|
|
|
|
schema,
|
|
|
|
tables,
|
|
|
|
token,
|
|
|
|
}) => {
|
2023-11-27 15:31:52 +05:30
|
|
|
const createdEntityIds = {
|
|
|
|
databaseId: undefined,
|
|
|
|
databaseSchemaId: undefined,
|
|
|
|
};
|
|
|
|
|
2023-11-01 10:36:41 +05:30
|
|
|
// Create service
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/services/databaseServices`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body: service,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create Database
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/databases`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body: database,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201);
|
2023-11-27 15:31:52 +05:30
|
|
|
|
|
|
|
createdEntityIds.databaseId = response.body.id;
|
2023-11-01 10:36:41 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
// Create Database Schema
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/databaseSchemas`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body: schema,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201);
|
2023-11-27 15:31:52 +05:30
|
|
|
|
|
|
|
createdEntityIds.databaseSchemaId = response.body.id;
|
2023-11-01 10:36:41 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
tables.forEach((body) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/tables`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201);
|
|
|
|
});
|
|
|
|
});
|
2023-11-27 15:31:52 +05:30
|
|
|
|
|
|
|
return createdEntityIds;
|
2023-11-01 10:36:41 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create single level service like messaging, pipeline, mlmodel etc.
|
|
|
|
*/
|
|
|
|
export const createSingleLevelEntity = ({
|
|
|
|
service,
|
|
|
|
entity,
|
|
|
|
serviceType,
|
|
|
|
entityType,
|
|
|
|
token,
|
|
|
|
}) => {
|
|
|
|
// Create service
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/services/${serviceType}`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body: service,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201);
|
|
|
|
});
|
|
|
|
|
|
|
|
entity.forEach((body) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/${entityType}`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body,
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete full hierarchy of any service
|
|
|
|
*/
|
|
|
|
export const hardDeleteService = ({ serviceFqn, token, serviceType }) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
2023-12-03 13:29:15 +05:30
|
|
|
url: `/api/v1/services/${serviceType}/name/${serviceFqn}?include=all`,
|
2023-11-01 10:36:41 +05:30
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
}).then((response) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/api/v1/services/${serviceType}/${response.body.id}?hardDelete=true&recursive=true`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2023-11-11 00:08:32 +05:30
|
|
|
|
|
|
|
export const generateRandomTable = () => {
|
|
|
|
const id = uuid();
|
|
|
|
const name = `cypress-table-${id}`;
|
|
|
|
|
|
|
|
const table = {
|
|
|
|
name,
|
|
|
|
description: `cypress-table-description-${id}`,
|
|
|
|
displayName: name,
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
name: `cypress-column-${id}`,
|
|
|
|
description: `cypress-column-description-${id}`,
|
|
|
|
dataType: 'NUMERIC',
|
|
|
|
dataTypeDisplay: 'numeric',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
databaseSchema: `${DATABASE_SERVICE_DETAILS.name}.${DATABASE_DETAILS.name}.${SCHEMA_DETAILS.name}`,
|
|
|
|
};
|
|
|
|
|
|
|
|
return table;
|
|
|
|
};
|
2023-11-17 19:59:47 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* get Table by name and create query in the table
|
|
|
|
*/
|
|
|
|
export const createQueryByTableName = (token, table) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
|
|
|
url: `/api/v1/tables/name/${table.databaseSchema}.${table.name}`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
}).then((response) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/queries`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body: {
|
|
|
|
query: 'SELECT * FROM SALES',
|
|
|
|
description: 'this is query description',
|
|
|
|
queryUsedIn: [
|
|
|
|
{
|
|
|
|
id: response.body.id,
|
|
|
|
type: 'table',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
duration: 6199,
|
|
|
|
queryDate: 1700225667191,
|
|
|
|
service: DATABASE_SERVICE_DETAILS.name,
|
|
|
|
},
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(201);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2023-11-21 10:40:20 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new user
|
|
|
|
*/
|
|
|
|
export const createUserEntity = ({ token, user }) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/api/v1/users/signup`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
body: user,
|
|
|
|
}).then((response) => {
|
|
|
|
user.id = response.body.id;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a user by id
|
|
|
|
*/
|
|
|
|
export const deleteUserEntity = ({ token, id }) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/api/v1/users/${id}?hardDelete=true&recursive=false`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete any entity by id
|
|
|
|
*/
|
|
|
|
export const deleteEntityById = ({ entityType, token, entityFqn }) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
|
|
|
url: `/api/v1/${entityType}/name/${entityFqn}`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
}).then((response) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/api/v1/${entityType}/${response.body.id}?hardDelete=true&recursive=true`,
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|