|
| 1 | +import { |
| 2 | + validate_200_Status, |
| 3 | + validate_401_Status, |
| 4 | + getAPIBaseURL, |
| 5 | + validate_expected_status, |
| 6 | +} from '../../support/commands'; |
| 7 | + |
| 8 | +describe('To Validate & test Organization APIs via API call (V3)', function () { |
| 9 | + const claEndpoint = getAPIBaseURL('v3'); |
| 10 | + let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1); |
| 11 | + const timeout = 180000; |
| 12 | + const local = Cypress.env('LOCAL'); |
| 13 | + |
| 14 | + it('Search Organization by company name - Record should return 200 Response', function () { |
| 15 | + const companyName = 'Linux Foundation'; |
| 16 | + cy.request({ |
| 17 | + method: 'GET', |
| 18 | + url: `${claEndpoint}organization/search?companyName=${encodeURIComponent(companyName)}`, |
| 19 | + timeout: timeout, |
| 20 | + failOnStatusCode: allowFail, |
| 21 | + }).then((response) => { |
| 22 | + return cy.logJson('response', response).then(() => { |
| 23 | + validate_200_Status(response); |
| 24 | + expect(response.body).to.be.an('object'); |
| 25 | + expect(response.body.list).to.be.an('array'); |
| 26 | + expect(response.body.list.length).to.be.greaterThan(0); |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + it('Search Organization by website name - Record should return 200 Response', function () { |
| 32 | + const websiteName = 'linuxfoundation.org'; |
| 33 | + cy.request({ |
| 34 | + method: 'GET', |
| 35 | + url: `${claEndpoint}organization/search?websiteName=${encodeURIComponent(websiteName)}`, |
| 36 | + timeout: timeout, |
| 37 | + failOnStatusCode: false, // Handle connection issues for local |
| 38 | + }).then((response) => { |
| 39 | + return cy.logJson('response', response).then(() => { |
| 40 | + validate_200_Status(response); |
| 41 | + expect(response.body).to.be.an('object'); |
| 42 | + expect(response.body.list).to.be.an('array'); |
| 43 | + expect(response.body.list.length).to.be.greaterThan(0); |
| 44 | + }); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('Search Organization with both company name and website - Record should return 200 Response', function () { |
| 49 | + const companyName = 'Linux Foundation'; |
| 50 | + const websiteName = 'linuxfoundation.org'; |
| 51 | + cy.request({ |
| 52 | + method: 'GET', |
| 53 | + url: `${claEndpoint}organization/search?companyName=${encodeURIComponent(companyName)}&websiteName=${encodeURIComponent(websiteName)}`, |
| 54 | + timeout: timeout, |
| 55 | + failOnStatusCode: allowFail, |
| 56 | + }).then((response) => { |
| 57 | + return cy.logJson('response', response).then(() => { |
| 58 | + validate_200_Status(response); |
| 59 | + expect(response.body).to.be.an('object'); |
| 60 | + expect(response.body.list).to.be.an('array'); |
| 61 | + expect(response.body.list.length).to.be.greaterThan(0); |
| 62 | + }); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + it('Search Organization by non-existing company name - Record should return 200 Response', function () { |
| 67 | + const companyName = 'Non-existing XYZ'; |
| 68 | + cy.request({ |
| 69 | + method: 'GET', |
| 70 | + url: `${claEndpoint}organization/search?companyName=${encodeURIComponent(companyName)}`, |
| 71 | + timeout: timeout, |
| 72 | + failOnStatusCode: allowFail, |
| 73 | + }).then((response) => { |
| 74 | + return cy.logJson('response', response).then(() => { |
| 75 | + validate_200_Status(response); |
| 76 | + expect(response.body).to.be.an('object'); |
| 77 | + expect(response.body.list).to.be.an('array'); |
| 78 | + expect(response.body.list.length).to.eq(0); |
| 79 | + }); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + describe('Expected failures', () => { |
| 84 | + it('Returns errors due to missing or malformed parameters for Organization APIs', function () { |
| 85 | + const cases: Array<{ |
| 86 | + title: string; |
| 87 | + method: 'GET'; |
| 88 | + url: string; |
| 89 | + expectedStatus: number; |
| 90 | + expectedCode?: number; |
| 91 | + expectedMessage?: string; |
| 92 | + expectedMessageContains?: boolean; |
| 93 | + }> = [ |
| 94 | + { |
| 95 | + title: 'GET /organization/search with neither companyName nor websiteName', |
| 96 | + method: 'GET', |
| 97 | + url: `${claEndpoint}organization/search`, |
| 98 | + expectedStatus: 400, |
| 99 | + expectedMessage: 'companyName or websiteName or filter at least one required', |
| 100 | + expectedMessageContains: true, |
| 101 | + }, |
| 102 | + { |
| 103 | + title: 'GET /organization/search with malformed websiteName', |
| 104 | + method: 'GET', |
| 105 | + url: `${claEndpoint}organization/search?websiteName=not-a-valid-url`, |
| 106 | + expectedStatus: 422, |
| 107 | + expectedMessage: 'websiteName in query should match', |
| 108 | + expectedMessageContains: true, |
| 109 | + expectedCode: 605, |
| 110 | + }, |
| 111 | + ]; |
| 112 | + |
| 113 | + cy.wrap(cases).each((c: any) => { |
| 114 | + cy.task('log', `--> ${c.title} | ${c.method} ${c.url}`); |
| 115 | + return cy |
| 116 | + .request({ |
| 117 | + method: c.method, |
| 118 | + url: c.url, |
| 119 | + failOnStatusCode: false, |
| 120 | + timeout, |
| 121 | + }) |
| 122 | + .then((response) => { |
| 123 | + return cy.logJson('response', response).then(() => { |
| 124 | + validate_expected_status( |
| 125 | + response, |
| 126 | + c.expectedStatus, |
| 127 | + c.expectedCode, |
| 128 | + c.expectedMessage, |
| 129 | + c.expectedMessageContains, |
| 130 | + ); |
| 131 | + }); |
| 132 | + }); |
| 133 | + }); |
| 134 | + }); |
| 135 | + }); |
| 136 | +}); |
0 commit comments