2022-01-21 13:43:27 +01:00
|
|
|
import filterTests from "../support/filterTests"
|
|
|
|
|
|
|
|
filterTests(['smoke', 'all'], () => {
|
2022-02-09 13:56:27 +01:00
|
|
|
xcontext("Query Level Transformers", () => {
|
2022-01-21 13:43:27 +01:00
|
|
|
before(() => {
|
|
|
|
cy.login()
|
|
|
|
cy.deleteApp("Cypress Tests")
|
|
|
|
cy.createApp("Cypress Tests")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should write a transformer function", () => {
|
|
|
|
// Add REST datasource - contains API for breweries
|
|
|
|
const datasource = "REST"
|
|
|
|
const restUrl = "https://api.openbrewerydb.org/breweries"
|
|
|
|
cy.selectExternalDatasource(datasource)
|
|
|
|
cy.createRestQuery("GET", restUrl)
|
|
|
|
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click()
|
|
|
|
// Get Transformer Function from file
|
|
|
|
cy.readFile("cypress/support/queryLevelTransformerFunction.js").then((transformerFunction) => {
|
|
|
|
cy.get(".CodeMirror textarea")
|
|
|
|
// Highlight current text and overwrite with file contents
|
|
|
|
.type(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a', { force: true })
|
|
|
|
.type(transformerFunction, { parseSpecialCharSequences: false })
|
|
|
|
})
|
|
|
|
// Send Query
|
|
|
|
cy.intercept('**/queries/preview').as('query')
|
|
|
|
cy.get(".spectrum-Button").contains("Send").click({ force: true })
|
|
|
|
cy.wait("@query")
|
|
|
|
// Assert against Status Code, body, & body rows
|
|
|
|
cy.get("@query").its('response.statusCode')
|
|
|
|
.should('eq', 200)
|
|
|
|
cy.get("@query").its('response.body').should('not.be.empty')
|
|
|
|
cy.get("@query").its('response.body.rows').should('not.be.empty')
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should add data to the previous query", () => {
|
2021-11-15 16:25:58 +01:00
|
|
|
// Add REST datasource - contains API for breweries
|
|
|
|
const datasource = "REST"
|
|
|
|
const restUrl = "https://api.openbrewerydb.org/breweries"
|
|
|
|
cy.selectExternalDatasource(datasource)
|
2021-12-24 11:38:03 +01:00
|
|
|
cy.createRestQuery("GET", restUrl)
|
|
|
|
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click()
|
2022-01-21 13:43:27 +01:00
|
|
|
// Get Transformer Function with Data from file
|
|
|
|
cy.readFile("cypress/support/queryLevelTransformerFunctionWithData.js").then((transformerFunction) => {
|
|
|
|
//console.log(transformerFunction[1])
|
2021-11-18 14:47:41 +01:00
|
|
|
cy.get(".CodeMirror textarea")
|
|
|
|
// Highlight current text and overwrite with file contents
|
|
|
|
.type(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a', { force: true })
|
|
|
|
.type(transformerFunction, { parseSpecialCharSequences: false })
|
|
|
|
})
|
2021-12-24 11:38:03 +01:00
|
|
|
// Send Query
|
|
|
|
cy.intercept('**/queries/preview').as('query')
|
|
|
|
cy.get(".spectrum-Button").contains("Send").click({ force: true })
|
|
|
|
cy.wait("@query")
|
|
|
|
// Assert against Status Code, body, & body rows
|
|
|
|
cy.get("@query").its('response.statusCode')
|
|
|
|
.should('eq', 200)
|
|
|
|
cy.get("@query").its('response.body').should('not.be.empty')
|
|
|
|
cy.get("@query").its('response.body.rows').should('not.be.empty')
|
2021-11-15 16:25:58 +01:00
|
|
|
})
|
2022-01-21 13:43:27 +01:00
|
|
|
|
|
|
|
it("should run an invalid query within the transformer section", () => {
|
|
|
|
// Add REST datasource - contains API for breweries
|
|
|
|
const datasource = "REST"
|
|
|
|
const restUrl = "https://api.openbrewerydb.org/breweries"
|
|
|
|
cy.selectExternalDatasource(datasource)
|
|
|
|
cy.createRestQuery("GET", restUrl)
|
|
|
|
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click()
|
|
|
|
// Clear the code box and add "test"
|
2021-11-18 14:47:41 +01:00
|
|
|
cy.get(".CodeMirror textarea")
|
|
|
|
.type(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a', { force: true })
|
2022-01-21 13:43:27 +01:00
|
|
|
.type("test")
|
|
|
|
// Run Query and intercept
|
|
|
|
cy.intercept('**/preview').as('queryError')
|
|
|
|
cy.get(".spectrum-Button").contains("Send").click({ force: true })
|
|
|
|
cy.wait("@queryError")
|
|
|
|
cy.wait(500)
|
|
|
|
// Assert against message and status for the query error
|
|
|
|
cy.get("@queryError").its('response.body').should('have.property', 'message', "test is not defined")
|
|
|
|
cy.get("@queryError").its('response.body').should('have.property', 'status', 400)
|
2021-11-18 14:47:41 +01:00
|
|
|
})
|
2022-01-21 13:43:27 +01:00
|
|
|
|
|
|
|
it("should run an invalid query via POST request", () => {
|
|
|
|
// POST request with transformer as null
|
|
|
|
cy.request({method: 'POST',
|
|
|
|
url: `${Cypress.config().baseUrl}/api/queries/`,
|
|
|
|
body: {fields : {"headers":{},"queryString":null,"path":null},
|
|
|
|
parameters : [],
|
|
|
|
schema : {},
|
|
|
|
name : "test",
|
|
|
|
queryVerb : "read",
|
|
|
|
transformer : null,
|
|
|
|
datasourceId: "test"},
|
|
|
|
// Expected 400 error - Transformer must be a string
|
|
|
|
failOnStatusCode: false}).then((response) => {
|
|
|
|
expect(response.status).to.equal(400)
|
|
|
|
expect(response.body.message).to.include('Invalid body - "transformer" must be a string')
|
|
|
|
})
|
2021-11-15 16:25:58 +01:00
|
|
|
})
|
2022-01-21 13:43:27 +01:00
|
|
|
|
|
|
|
it("should run an empty query", () => {
|
|
|
|
// POST request with Transformer as an empty string
|
|
|
|
cy.request({method: 'POST',
|
|
|
|
url: `${Cypress.config().baseUrl}/api/queries/preview`,
|
|
|
|
body: {fields : {"headers":{},"queryString":null,"path":null},
|
|
|
|
queryVerb : "read",
|
|
|
|
transformer : "",
|
|
|
|
datasourceId: "test"},
|
|
|
|
// Expected 400 error - Transformer is not allowed to be empty
|
|
|
|
failOnStatusCode: false}).then((response) => {
|
|
|
|
expect(response.status).to.equal(400)
|
|
|
|
expect(response.body.message).to.include('Invalid body - "transformer" is not allowed to be empty')
|
|
|
|
})
|
2021-11-18 14:47:41 +01:00
|
|
|
})
|
2021-11-15 16:25:58 +01:00
|
|
|
})
|
|
|
|
})
|