-
Notifications
You must be signed in to change notification settings - Fork 46
Some initial V3 tests #4848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Some initial V3 tests #4848
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { | ||
| validate_200_Status, | ||
| getTokenKey, | ||
| getAPIBaseURL, | ||
| getXACLHeaders, | ||
| validate_expected_status, | ||
| } from '../../support/commands'; | ||
|
|
||
| describe('To Validate & test Documentation APIs via API call (V3)', function () { | ||
| const claEndpoint = getAPIBaseURL('v3'); | ||
| let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1); | ||
| const timeout = 180000; | ||
| const local = Cypress.env('LOCAL'); | ||
|
|
||
lukaszgryglicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let bearerToken: string = null; | ||
| before(() => { | ||
| if (bearerToken == null) { | ||
| getTokenKey(bearerToken); | ||
lukaszgryglicki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cy.window().then((win) => { | ||
| bearerToken = win.localStorage.getItem('bearerToken'); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| it('Get API Documentation - Record should return 200 Response', function () { | ||
| cy.request({ | ||
| method: 'GET', | ||
| url: `${claEndpoint}api-docs`, | ||
| timeout: timeout, | ||
| failOnStatusCode: allowFail, | ||
| }).then((response) => { | ||
| validate_200_Status(response); | ||
| expect(response.body).to.not.be.null; | ||
| }); | ||
| }); | ||
|
|
||
| it('Get Swagger JSON - Record should return 200 Response', function () { | ||
| cy.request({ | ||
| method: 'GET', | ||
| url: `${claEndpoint}swagger.json`, | ||
| timeout: timeout, | ||
| failOnStatusCode: allowFail, | ||
| }).then((response) => { | ||
| validate_200_Status(response); | ||
| expect(response.body).to.be.an('object'); | ||
| expect(response.body).to.have.property('swagger'); | ||
| expect(response.body).to.have.property('info'); | ||
| expect(response.body).to.have.property('paths'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Expected failures', () => { | ||
| it('Returns errors due to malformed requests for Documentation APIs', function () { | ||
| const cases: Array<{ | ||
| title: string; | ||
| method: 'GET' | 'POST' | 'PUT' | 'DELETE'; | ||
| url: string; | ||
| body?: any; | ||
| expectedStatus?: number; | ||
| expectedCode?: number; | ||
| expectedMessage?: string; | ||
| expectedMessageContains?: boolean; | ||
| }> = [ | ||
| { | ||
| title: 'POST /api-docs (method not allowed)', | ||
| method: 'POST', | ||
| url: `${claEndpoint}api-docs`, | ||
| body: {}, | ||
| expectedStatus: 405, | ||
| expectedCode: 405, | ||
| expectedMessage: 'method POST is not allowed, but [GET] are', | ||
| expectedMessageContains: true, | ||
| }, | ||
| { | ||
| title: 'POST /swagger.json (method not allowed)', | ||
| method: 'POST', | ||
| url: `${claEndpoint}swagger.json`, | ||
| body: {}, | ||
| expectedStatus: 405, | ||
| expectedCode: 405, | ||
| expectedMessage: 'method POST is not allowed, but [GET] are', | ||
| expectedMessageContains: true, | ||
| }, | ||
| ]; | ||
|
|
||
| cy.wrap(cases).each((c: any) => { | ||
| return cy | ||
| .request({ | ||
| method: c.method, | ||
| url: c.url, | ||
| body: c.body, | ||
| failOnStatusCode: false, | ||
| timeout, | ||
| }) | ||
| .then((response) => { | ||
| cy.task('log', `Testing: ${c.title}`); | ||
| validate_expected_status( | ||
| response, | ||
| c.expectedStatus, | ||
| c.expectedCode, | ||
| c.expectedMessage, | ||
| c.expectedMessageContains, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { | ||
| validate_200_Status, | ||
| getTokenKey, | ||
| getAPIBaseURL, | ||
| getXACLHeaders, | ||
lukaszgryglicki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| validate_expected_status, | ||
| } from '../../support/commands'; | ||
|
|
||
| describe('To Validate & test Health APIs via API call (V3)', function () { | ||
| const claEndpoint = getAPIBaseURL('v3'); | ||
| let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1); | ||
| const timeout = 180000; | ||
| const local = Cypress.env('LOCAL'); | ||
|
|
||
lukaszgryglicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let bearerToken: string = null; | ||
| before(() => { | ||
| if (bearerToken == null) { | ||
| getTokenKey(bearerToken); | ||
lukaszgryglicki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cy.window().then((win) => { | ||
| bearerToken = win.localStorage.getItem('bearerToken'); | ||
| }); | ||
| } | ||
| }); | ||
lukaszgryglicki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| it('Returns the Health of the application - Record should return 200 Response', function () { | ||
| cy.request({ | ||
| method: 'GET', | ||
| url: `${claEndpoint}ops/health`, | ||
| timeout: timeout, | ||
| failOnStatusCode: allowFail, | ||
| }).then((response) => { | ||
| validate_200_Status(response); | ||
| expect(response.body).to.be.an('object'); | ||
| expect(response.body).to.have.property('Status'); | ||
| expect(response.body.Status).to.equal('healthy'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Expected failures', () => { | ||
| it('Returns errors due to malformed requests for Health APIs', function () { | ||
| const cases: Array<{ | ||
| title: string; | ||
| method: 'GET' | 'POST' | 'PUT' | 'DELETE'; | ||
| url: string; | ||
| body?: any; | ||
| expectedStatus?: number; | ||
| expectedCode?: number; | ||
| expectedMessage?: string; | ||
| expectedMessageContains?: boolean; | ||
| }> = [ | ||
| { | ||
| title: 'POST /ops/health (method not allowed)', | ||
| method: 'POST', | ||
| url: `${claEndpoint}ops/health`, | ||
| body: {}, | ||
| expectedStatus: 405, | ||
| expectedCode: 405, | ||
| expectedMessage: 'method POST is not allowed, but [GET] are', | ||
| expectedMessageContains: true, | ||
| }, | ||
| ]; | ||
|
|
||
| cy.wrap(cases).each((c: any) => { | ||
| return cy | ||
| .request({ | ||
| method: c.method, | ||
| url: c.url, | ||
| body: c.body, | ||
| failOnStatusCode: false, | ||
| timeout, | ||
| }) | ||
| .then((response) => { | ||
| cy.task('log', `Testing: ${c.title}`); | ||
| validate_expected_status( | ||
| response, | ||
| c.expectedStatus, | ||
| c.expectedCode, | ||
| c.expectedMessage, | ||
| c.expectedMessageContains, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { | ||
| validate_200_Status, | ||
| validate_401_Status, | ||
| getTokenKey, | ||
| getAPIBaseURL, | ||
| getXACLHeaders, | ||
lukaszgryglicki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| validate_expected_status, | ||
| } from '../../support/commands'; | ||
lukaszgryglicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| describe('To Validate & test Organization APIs via API call (V3)', function () { | ||
| const claEndpoint = getAPIBaseURL('v3'); | ||
| let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1); | ||
| const timeout = 180000; | ||
| const local = Cypress.env('LOCAL'); | ||
lukaszgryglicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let bearerToken: string = null; | ||
| before(() => { | ||
| getTokenKey(bearerToken); | ||
lukaszgryglicki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cy.window().then((win) => { | ||
| bearerToken = win.localStorage.getItem('bearerToken'); | ||
| }); | ||
| }); | ||
lukaszgryglicki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| it('Search Organization by company name - Record should return 200 Response', function () { | ||
| const companyName = 'Linux Foundation'; | ||
| cy.request({ | ||
| method: 'GET', | ||
| url: `${claEndpoint}organization/search?companyName=${encodeURIComponent(companyName)}`, | ||
| timeout: timeout, | ||
| failOnStatusCode: allowFail, | ||
| }).then((response) => { | ||
| validate_200_Status(response); | ||
| expect(response.body).to.be.an('object'); | ||
| if (response.body.list) { | ||
| expect(response.body.list).to.be.an('array'); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('Search Organization by website name - Record should return 200 Response', function () { | ||
| const websiteName = 'linuxfoundation.org'; | ||
| cy.request({ | ||
| method: 'GET', | ||
| url: `${claEndpoint}organization/search?websiteName=${encodeURIComponent(websiteName)}`, | ||
| timeout: timeout, | ||
| failOnStatusCode: allowFail, | ||
| }).then((response) => { | ||
| validate_200_Status(response); | ||
| expect(response.body).to.be.an('object'); | ||
| if (response.body.list) { | ||
| expect(response.body.list).to.be.an('array'); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('Search Organization with both company name and website - Record should return 200 Response', function () { | ||
| const companyName = 'Linux Foundation'; | ||
| const websiteName = 'linuxfoundation.org'; | ||
| cy.request({ | ||
| method: 'GET', | ||
| url: `${claEndpoint}organization/search?companyName=${encodeURIComponent(companyName)}&websiteName=${encodeURIComponent(websiteName)}`, | ||
| timeout: timeout, | ||
| failOnStatusCode: allowFail, | ||
| }).then((response) => { | ||
| validate_200_Status(response); | ||
| expect(response.body).to.be.an('object'); | ||
| if (response.body.list) { | ||
| expect(response.body.list).to.be.an('array'); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('Expected failures', () => { | ||
| it('Returns errors due to missing or malformed parameters for Organization APIs', function () { | ||
| const cases: Array<{ | ||
| title: string; | ||
| method: 'GET'; | ||
| url: string; | ||
| expectedStatus: number; | ||
| expectedCode?: number; | ||
| expectedMessage?: string; | ||
| expectedMessageContains?: boolean; | ||
| }> = [ | ||
| { | ||
| title: 'GET /organization/search with neither companyName nor websiteName', | ||
| method: 'GET', | ||
| url: `${claEndpoint}organization/search`, | ||
| expectedStatus: 400, | ||
| expectedMessage: 'companyName or websiteName', | ||
| expectedMessageContains: true, | ||
| }, | ||
| { | ||
| title: 'GET /organization/search with malformed websiteName', | ||
| method: 'GET', | ||
| url: `${claEndpoint}organization/search?websiteName=not-a-valid-url`, | ||
| expectedStatus: 422, | ||
| expectedMessage: 'websiteName in query should match', | ||
| expectedMessageContains: true, | ||
| }, | ||
| ]; | ||
|
|
||
| cy.wrap(cases).each((c: any) => { | ||
| cy.task('log', `--> ${c.title} | ${c.method} ${c.url}`); | ||
| return cy | ||
| .request({ | ||
| method: c.method, | ||
| url: c.url, | ||
| failOnStatusCode: false, | ||
| timeout, | ||
| }) | ||
| .then((response) => { | ||
| return cy.logJson('response', response).then(() => { | ||
| validate_expected_status( | ||
| response, | ||
| c.expectedStatus, | ||
| c.expectedCode, | ||
| c.expectedMessage, | ||
| c.expectedMessageContains, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.