-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration.test.js
More file actions
134 lines (120 loc) · 4.72 KB
/
integration.test.js
File metadata and controls
134 lines (120 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const { loadNewmanReport, extractRequestsFromNewman } = require('../lib/newman');
const { loadPostmanCollection, extractRequestsFromPostman } = require('../lib/postman');
const { loadAndParseSpec, extractOperationsFromSpec } = require('../lib/swagger');
const { matchOperationsDetailed } = require('../lib/match');
const fs = require('fs');
const path = require('path');
describe('Integration Tests - Newman vs Postman', () => {
let testApiSpec, postmanCollection, newmanReport;
beforeAll(() => {
// Create test API spec
testApiSpec = {
openapi: '3.0.0',
info: { title: 'Test API', version: '1.0.0' },
paths: {
'/users': {
get: {
operationId: 'getUsers',
responses: { '200': { description: 'Success' } }
},
post: {
operationId: 'createUser',
responses: { '201': { description: 'Created' } }
}
}
}
};
// Create test Postman collection
postmanCollection = {
info: { name: 'Test Collection' },
item: [
{
name: 'Get Users',
request: {
method: 'GET',
url: 'https://api.example.com/users'
},
event: [
{
listen: 'test',
script: {
exec: ['pm.test("Status code is 200", function () {', ' pm.response.to.have.status(200);', '});']
}
}
]
}
]
};
// Create test Newman report
newmanReport = {
collection: { info: { name: 'Test Collection' } },
run: {
executions: [
{
item: { name: 'Get Users' },
request: {
method: 'GET',
url: { raw: 'https://api.example.com/users' }
},
response: { code: 200, status: 'OK' },
assertions: [{ assertion: 'Status code is 200', error: null }]
},
{
item: { name: 'Create User' },
request: {
method: 'POST',
url: { raw: 'https://api.example.com/users' }
},
response: { code: 201, status: 'Created' },
assertions: [{ assertion: 'Status code is 201', error: null }]
}
]
}
};
});
test('Both Postman collection and Newman report should work with same API spec', () => {
// Extract operations from spec
const specOps = extractOperationsFromSpec(testApiSpec);
expect(specOps.length).toBe(2);
// Extract requests from Postman collection
const postmanReqs = extractRequestsFromPostman(postmanCollection);
expect(postmanReqs.length).toBe(1);
// Extract requests from Newman report
const newmanReqs = extractRequestsFromNewman(newmanReport);
expect(newmanReqs.length).toBe(2);
// Test coverage with Postman collection
const postmanCoverage = matchOperationsDetailed(specOps, postmanReqs, {
verbose: false, strictQuery: false, strictBody: false
});
const postmanMatchedCount = postmanCoverage.filter(item => !item.unmatched).length;
const postmanCoveragePercent = (postmanMatchedCount / postmanCoverage.length) * 100;
// Test coverage with Newman report
const newmanCoverage = matchOperationsDetailed(specOps, newmanReqs, {
verbose: false, strictQuery: false, strictBody: false
});
const newmanMatchedCount = newmanCoverage.filter(item => !item.unmatched).length;
const newmanCoveragePercent = (newmanMatchedCount / newmanCoverage.length) * 100;
// Newman should have better coverage since it has both requests
expect(postmanCoveragePercent).toBe(50); // Only GET /users is covered
expect(newmanCoveragePercent).toBe(100); // Both GET and POST /users are covered
// Verify Newman requests have execution data
expect(newmanReqs[0].executed).toBe(true);
expect(newmanReqs[0].responseCode).toBe(200);
expect(newmanReqs[1].responseCode).toBe(201);
});
test('Newman requests should contain more detailed execution information', () => {
const postmanReqs = extractRequestsFromPostman(postmanCollection);
const newmanReqs = extractRequestsFromNewman(newmanReport);
// Postman collection requests should not have execution data
expect(postmanReqs[0].executed).toBeUndefined();
expect(postmanReqs[0].responseCode).toBeUndefined();
expect(postmanReqs[0].responseTime).toBeUndefined();
expect(postmanReqs[0].assertions).toBeUndefined();
// Newman report requests should have execution data
expect(newmanReqs[0].executed).toBe(true);
expect(newmanReqs[0].responseCode).toBe(200);
expect(newmanReqs[0].assertions).toBeDefined();
expect(newmanReqs[0].assertions.length).toBe(1);
expect(newmanReqs[0].assertions[0].passed).toBe(true);
});
});