Skip to content

Commit cf381bf

Browse files
Merge pull request #4848 from linuxfoundation/unicron-v3-apis-test-coverage-dev-3
Some initial V3 tests
2 parents 8e8a407 + 443706e commit cf381bf

17 files changed

Lines changed: 669 additions & 13 deletions

cla-backend-go/company/handlers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ func Configure(api *operations.ClaAPI, service IService, usersService users.Serv
363363

364364
result, err := service.SearchOrganizationByName(ctx, companyName, websiteName, utils.BoolValue(params.IncludeSigningEntityName), filter)
365365
if err != nil {
366-
log.Warnf("error occurred while search org %s. error = %s", *params.CompanyName, err.Error())
366+
companyName := "<nil>"
367+
if params.CompanyName != nil {
368+
companyName = *params.CompanyName
369+
}
370+
log.Warnf("error occurred while search org %s. error = %s", companyName, err.Error())
367371
return organization.NewSearchOrganizationInternalServerError().WithXRequestID(reqID).WithPayload(errorResponse(err))
368372
}
369373
return organization.NewSearchOrganizationOK().WithXRequestID(reqID).WithPayload(result)

cla-backend-go/users/handlers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ func Configure(api *operations.ClaAPI, service Service, eventsService events.Ser
257257
}
258258

259259
userModel, err := service.GetUser(params.UserID)
260-
if err != nil {
260+
if err != nil || userModel == nil {
261+
if err == nil {
262+
err = fmt.Errorf("user not found for user_id: %s", params.UserID)
263+
}
261264
log.WithFields(f).Warnf("error retrieving user for user_id: %s, error: %+v", params.UserID, err)
262265
return users.NewGetUserCompatBadRequest().WithPayload(errorResponse(err))
263266
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { validate_200_Status, getAPIBaseURL, validate_expected_status } from '../../support/commands';
2+
3+
describe('To Validate & test Documentation APIs via API call (V3)', function () {
4+
const claEndpoint = getAPIBaseURL('v3');
5+
let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1);
6+
const timeout = 180000;
7+
const local = Cypress.env('LOCAL');
8+
9+
it('Get API Documentation - Record should return 200 Response', function () {
10+
cy.request({
11+
method: 'GET',
12+
url: `${claEndpoint}api-docs`,
13+
timeout: timeout,
14+
failOnStatusCode: allowFail,
15+
}).then((response) => {
16+
validate_200_Status(response);
17+
expect(response.body).to.not.be.null;
18+
});
19+
});
20+
21+
it('Get Swagger JSON - Record should return 200 Response', function () {
22+
cy.request({
23+
method: 'GET',
24+
url: `${claEndpoint}swagger.json`,
25+
timeout: timeout,
26+
failOnStatusCode: allowFail,
27+
}).then((response) => {
28+
validate_200_Status(response);
29+
expect(response.body).to.be.an('object');
30+
expect(response.body).to.have.property('swagger');
31+
expect(response.body).to.have.property('info');
32+
expect(response.body).to.have.property('paths');
33+
});
34+
});
35+
36+
describe('Expected failures', () => {
37+
it('Returns errors due to malformed requests for Documentation APIs', function () {
38+
const cases: Array<{
39+
title: string;
40+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
41+
url: string;
42+
body?: any;
43+
expectedStatus?: number;
44+
expectedCode?: number;
45+
expectedMessage?: string;
46+
expectedMessageContains?: boolean;
47+
}> = [
48+
{
49+
title: 'POST /api-docs (method not allowed)',
50+
method: 'POST',
51+
url: `${claEndpoint}api-docs`,
52+
body: {},
53+
expectedStatus: 405,
54+
expectedCode: 405,
55+
expectedMessage: 'method POST is not allowed, but [GET] are',
56+
expectedMessageContains: true,
57+
},
58+
{
59+
title: 'POST /swagger.json (method not allowed)',
60+
method: 'POST',
61+
url: `${claEndpoint}swagger.json`,
62+
body: {},
63+
expectedStatus: 405,
64+
expectedCode: 405,
65+
expectedMessage: 'method POST is not allowed, but [GET] are',
66+
expectedMessageContains: true,
67+
},
68+
];
69+
70+
cy.wrap(cases).each((c: any) => {
71+
return cy
72+
.request({
73+
method: c.method,
74+
url: c.url,
75+
body: c.body,
76+
failOnStatusCode: false,
77+
timeout,
78+
})
79+
.then((response) => {
80+
cy.task('log', `Testing: ${c.title}`);
81+
validate_expected_status(
82+
response,
83+
c.expectedStatus,
84+
c.expectedCode,
85+
c.expectedMessage,
86+
c.expectedMessageContains,
87+
);
88+
});
89+
});
90+
});
91+
});
92+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { validate_200_Status, getAPIBaseURL, validate_expected_status } from '../../support/commands';
2+
3+
describe('To Validate & test Health APIs via API call (V3)', function () {
4+
const claEndpoint = getAPIBaseURL('v3');
5+
let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1);
6+
const timeout = 180000;
7+
const local = Cypress.env('LOCAL');
8+
9+
it('Returns the Health of the application - Record should return 200 Response', function () {
10+
cy.request({
11+
method: 'GET',
12+
url: `${claEndpoint}ops/health`,
13+
timeout: timeout,
14+
failOnStatusCode: allowFail,
15+
}).then((response) => {
16+
validate_200_Status(response);
17+
expect(response.body).to.be.an('object');
18+
expect(response.body).to.have.property('Status');
19+
expect(response.body.Status).to.equal('healthy');
20+
});
21+
});
22+
23+
describe('Expected failures', () => {
24+
it('Returns errors due to malformed requests for Health APIs', function () {
25+
const cases: Array<{
26+
title: string;
27+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
28+
url: string;
29+
body?: any;
30+
expectedStatus?: number;
31+
expectedCode?: number;
32+
expectedMessage?: string;
33+
expectedMessageContains?: boolean;
34+
}> = [
35+
{
36+
title: 'POST /ops/health (method not allowed)',
37+
method: 'POST',
38+
url: `${claEndpoint}ops/health`,
39+
body: {},
40+
expectedStatus: 405,
41+
expectedCode: 405,
42+
expectedMessage: 'method POST is not allowed, but [GET] are',
43+
expectedMessageContains: true,
44+
},
45+
];
46+
47+
cy.wrap(cases).each((c: any) => {
48+
return cy
49+
.request({
50+
method: c.method,
51+
url: c.url,
52+
body: c.body,
53+
failOnStatusCode: false,
54+
timeout,
55+
})
56+
.then((response) => {
57+
cy.task('log', `Testing: ${c.title}`);
58+
validate_expected_status(
59+
response,
60+
c.expectedStatus,
61+
c.expectedCode,
62+
c.expectedMessage,
63+
c.expectedMessageContains,
64+
);
65+
});
66+
});
67+
});
68+
});
69+
});
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
});

tests/functional/cypress/e2e/v3/touch

Whitespace-only changes.

0 commit comments

Comments
 (0)