commands.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // ***********************************************
  2. // This example commands.js shows you how to
  3. // create various custom commands and overwrite
  4. // existing commands.
  5. //
  6. // For more comprehensive examples of custom
  7. // commands please read more here:
  8. // https://on.cypress.io/custom-commands
  9. // ***********************************************
  10. //
  11. /**
  12. * Check the swagger schema:
  13. *
  14. * @param {string} method API Method in swagger doc, "get", "put", "post", "delete"
  15. * @param {number} statusCode API status code in swagger doc
  16. * @param {string} path Swagger doc endpoint path, exactly as defined in swagger doc
  17. * @param {*} data The API response data to check against the swagger schema
  18. */
  19. Cypress.Commands.add('validateSwaggerSchema', (method, statusCode, path, data) => {
  20. cy.task('validateSwaggerSchema', {
  21. file: Cypress.env('swaggerBase'),
  22. endpoint: path,
  23. method: method,
  24. statusCode: statusCode,
  25. responseSchema: data,
  26. verbose: true
  27. }).should('equal', null);
  28. });
  29. Cypress.Commands.add('getToken', () => {
  30. // login with existing user
  31. cy.task('backendApiPost', {
  32. path: '/api/tokens',
  33. data: {
  34. identity: '[email protected]',
  35. secret: 'changeme'
  36. }
  37. }).then(res => {
  38. cy.wrap(res.token);
  39. });
  40. });