Browse Source

test: [cypress] Swagger API verification

Signed-off-by: Raju Udava <sivadstala@gmail.com>
pull/559/head
Raju Udava 3 years ago
parent
commit
75fcbf1f0a
  1. 13
      cypress/integration/common/6b_auth_token_verification.js
  2. 68
      cypress/integration/common/6c_swagger_api.js
  3. 5
      cypress/support/page_objects/mainPage.js

13
cypress/integration/common/6b_auth_token_verification.js

@ -1,12 +1,16 @@
import { loginPage, projectsPage } from "../../support/page_objects/navigation" import { loginPage, projectsPage } from "../../support/page_objects/navigation"
import { staticProjects, roles } from "../../support/page_objects/projectConstants" import { staticProjects, roles } from "../../support/page_objects/projectConstants"
import { mainPage } from "../../support/page_objects/mainPage"
// https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript-without-using-a-library
// sample code to parse Jwt
//
function parseJwt (token) { function parseJwt (token) {
var base64Url = token.split('.')[1]; var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join('')); }).join(''))
return JSON.parse(jsonPayload); return JSON.parse(jsonPayload);
}; };
@ -22,10 +26,9 @@ const genTest = (type, xcdb) => {
}) })
it('auth info', ()=> { it('auth info', ()=> {
let obj = JSON.parse(localStorage['vuex']) var decodedToken = parseJwt(mainPage.getAuthToken())
var decoded = parseJwt(obj["users"]["token"]) let email = decodedToken["email"]
let email = decoded["email"] let role = decodedToken["roles"]
let role = decoded["roles"]
assert.equal(email, roles.owner.credentials.username) assert.equal(email, roles.owner.credentials.username)
assert.equal(role, "user") assert.equal(role, "user")

68
cypress/integration/common/6c_swagger_api.js

@ -0,0 +1,68 @@
import { loginPage } from "../../support/page_objects/navigation"
import { mainPage } from "../../support/page_objects/mainPage"
describe(`Swagger API - Test preparation`, () => {
before(()=> {
loginPage.loginAndOpenProject('rest', false)
})
it("[REST] open project & record swagger URL, AuthToken", () => {
let authToken = mainPage.getAuthToken()
cy.url().then( (url) => {
// retrieve project name from URL & use it to construct Swagger URL
// URL on homepage: http://localhost:3000/#/nc/externalrest_weUO?type=roles&dbalias=&name=Team%20%26%20Auth%20
// Swagger URL: http://localhost:8080/nc/externalrest_weUO/db/swagger
//
const projectName = url.split("/")[5].split("?")[0];
let swaggerURL = `http://localhost:8080/nc/${projectName}/db/swagger`
// exchange information between two tests using a file
// https://stackoverflow.com/questions/52050657/what-is-the-best-practice-of-pass-states-between-tests-in-cypress
//
cy.writeFile("shared.json", {SWAGGER_URL: swaggerURL, AUTH_TOKEN: authToken})
})
})
})
describe(`Swagger page, base verification`, () => {
// returns swagger button intended for
//
const getSwaggerButton = (tag, idx, desc) => {
return cy.get(`#operations-tag-${tag}`).next().find('.opblock').eq(idx).find(`button:contains(${desc})`)
}
// basic authentication tag verification
//
it("Swagger URL access & basic validation", () => {
// retrieve information stored in previous IT block
//
cy.readFile("shared.json").then((jsonPayload) => {
let URL = jsonPayload.SWAGGER_URL
let Token = jsonPayload.AUTH_TOKEN
cy.visit(URL)
cy.log(Token)
// validate
cy.get('#operations-tag-Authentication').next().find('.opblock').should('has.length', 9)
getSwaggerButton("Authentication", 0, "User login").should('exist')
getSwaggerButton("Authentication", 1, "User signup").should('exist')
getSwaggerButton("Authentication", 2, "Password Forgot").should('exist')
getSwaggerButton("Authentication", 3, "Email validate link").should('exist')
getSwaggerButton("Authentication", 4, "Validate password reset token").should('exist')
getSwaggerButton("Authentication", 5, "Password reset").should('exist')
getSwaggerButton("Authentication", 6, "User details").should('exist')
getSwaggerButton("Authentication", 7, "Update user details").should('exist')
getSwaggerButton("Authentication", 8, "Update user details").should('exist')
})
})
// clean-up created file
after(() => {
cy.exec("del shared.json").then(()=> {
cy.log("file cleaned up!")
})
})
})

5
cypress/support/page_objects/mainPage.js

@ -120,6 +120,11 @@ export class _mainPage {
cy.get('.nc-column-name-input input', {timeout: 3000}).clear().type(colName) cy.get('.nc-column-name-input input', {timeout: 3000}).clear().type(colName)
cy.get('.nc-col-create-or-edit-card').contains('Save').click() cy.get('.nc-col-create-or-edit-card').contains('Save').click()
} }
getAuthToken = () => {
let obj = JSON.parse(localStorage['vuex'])
return obj["users"]["token"]
}
} }

Loading…
Cancel
Save