2020-02-18 23:55:06 -05:00
|
|
|
// ***********************************************
|
|
|
|
// This example commands.js shows you how to
|
|
|
|
// create various custom commands and overwrite
|
|
|
|
// existing commands.
|
|
|
|
//
|
|
|
|
// For more comprehensive examples of custom
|
|
|
|
// commands please read more here:
|
|
|
|
// https://on.cypress.io/custom-commands
|
|
|
|
// ***********************************************
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the swagger schema:
|
|
|
|
*
|
|
|
|
* @param {string} method API Method in swagger doc, "get", "put", "post", "delete"
|
2020-08-05 22:47:24 -04:00
|
|
|
* @param {number} statusCode API status code in swagger doc
|
2020-02-18 23:55:06 -05:00
|
|
|
* @param {string} path Swagger doc endpoint path, exactly as defined in swagger doc
|
|
|
|
* @param {*} data The API response data to check against the swagger schema
|
|
|
|
*/
|
2020-08-05 22:47:24 -04:00
|
|
|
Cypress.Commands.add('validateSwaggerSchema', (method, statusCode, path, data) => {
|
2020-02-18 23:55:06 -05:00
|
|
|
cy.task('validateSwaggerSchema', {
|
|
|
|
file: Cypress.env('swaggerBase'),
|
|
|
|
endpoint: path,
|
|
|
|
method: method,
|
2020-08-05 22:47:24 -04:00
|
|
|
statusCode: statusCode,
|
2020-02-18 23:55:06 -05:00
|
|
|
responseSchema: data,
|
|
|
|
verbose: true
|
|
|
|
}).should('equal', null);
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('getToken', () => {
|
2020-08-05 21:57:31 -04:00
|
|
|
// login with existing user
|
|
|
|
cy.task('backendApiPost', {
|
|
|
|
path: '/api/tokens',
|
2020-02-18 23:55:06 -05:00
|
|
|
data: {
|
2020-08-05 22:47:24 -04:00
|
|
|
identity: 'admin@example.com',
|
|
|
|
secret: 'changeme'
|
2020-02-18 23:55:06 -05:00
|
|
|
}
|
2020-08-05 21:57:31 -04:00
|
|
|
}).then(res => {
|
2020-08-05 22:47:24 -04:00
|
|
|
cy.wrap(res.token);
|
2020-02-18 23:55:06 -05:00
|
|
|
});
|
|
|
|
});
|