-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmart-mapping-cli.test.js
More file actions
204 lines (163 loc) · 7.92 KB
/
smart-mapping-cli.test.js
File metadata and controls
204 lines (163 loc) · 7.92 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
const { exec } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execAsync = promisify(exec);
describe('Smart Mapping CLI Integration', () => {
const sampleApiPath = path.resolve(__dirname, 'fixtures', 'sample-api.yaml');
const sampleNewmanPath = path.resolve(__dirname, 'fixtures', 'sample-newman-report.json');
test('should improve coverage with smart mapping enabled', async () => {
// Test without smart mapping
const { stdout: normalOutput } = await execAsync(
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman --verbose`,
{ cwd: path.resolve(__dirname, '..') }
);
// Test with smart mapping
const { stdout: smartOutput } = await execAsync(
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman --verbose`,
{ cwd: path.resolve(__dirname, '..') }
);
// Extract coverage percentages
const normalCoverageMatch = normalOutput.match(/Coverage: ([\d.]+)%/);
const smartCoverageMatch = smartOutput.match(/Coverage: ([\d.]+)%/);
expect(normalCoverageMatch).toBeTruthy();
expect(smartCoverageMatch).toBeTruthy();
const normalCoverage = parseFloat(normalCoverageMatch[1]);
const smartCoverage = parseFloat(smartCoverageMatch[1]);
console.log(`Normal mapping coverage: ${normalCoverage}%`);
console.log(`Smart mapping coverage: ${smartCoverage}%`);
// Smart mapping should provide equal or better coverage
expect(smartCoverage).toBeGreaterThanOrEqual(normalCoverage);
// Verify smart mapping output contains expected indicators
expect(smartOutput).toContain('Smart mapping:');
expect(smartOutput).toContain('primary matches');
expect(smartOutput).toContain('secondary matches');
}, 30000);
test('should show smart mapping statistics in verbose mode', async () => {
const { stdout } = await execAsync(
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman --verbose`,
{ cwd: path.resolve(__dirname, '..') }
);
// Should contain smart mapping statistics
expect(stdout).toContain('Smart mapping:');
expect(stdout).toMatch(/\d+ primary matches/);
expect(stdout).toMatch(/\d+ secondary matches/);
// Should show improved coverage
expect(stdout).toContain('Operations mapped:');
}, 15000);
test('should maintain backward compatibility when smart mapping is disabled', async () => {
const { stdout: withoutFlag } = await execAsync(
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman`,
{ cwd: path.resolve(__dirname, '..') }
);
const { stdout: withFalsyFlag } = await execAsync(
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman`,
{ cwd: path.resolve(__dirname, '..') }
);
// Both should produce identical results
const withoutCoverage = withoutFlag.match(/Coverage: ([\d.]+)%/)[1];
const withFalsyCoverage = withFalsyFlag.match(/Coverage: ([\d.]+)%/)[1];
expect(withoutCoverage).toBe(withFalsyCoverage);
// Should not contain smart mapping statistics
expect(withoutFlag).not.toContain('Smart mapping:');
expect(withoutFlag).not.toContain('primary matches');
}, 15000);
test('should work with multi-API scenarios', async () => {
const usersApiPath = path.resolve(__dirname, 'fixtures', 'users-api.yaml');
const productsApiPath = path.resolve(__dirname, 'fixtures', 'products-api.yaml');
const testCollectionPath = path.resolve(__dirname, 'fixtures', 'test-collection.json');
const { stdout } = await execAsync(
`node cli.js "${usersApiPath},${productsApiPath}" "${testCollectionPath}" --verbose`,
{ cwd: path.resolve(__dirname, '..') }
);
// Should show smart mapping statistics for multi-API scenario
expect(stdout).toContain('Smart mapping:');
expect(stdout).toMatch(/\d+ primary matches/);
expect(stdout).toMatch(/\d+ secondary matches/);
expect(stdout).toContain('Coverage:');
}, 15000);
test('should handle strict validation with smart mapping', async () => {
const strictApiPath = path.resolve(__dirname, 'fixtures', 'strict-validation-api.yaml');
const strictCollectionPath = path.resolve(__dirname, 'fixtures', 'strict-validation-collection.json');
const { stdout } = await execAsync(
`node cli.js "${strictApiPath}" "${strictCollectionPath}" --strict-query --strict-body --verbose`,
{ cwd: path.resolve(__dirname, '..') }
);
// Should show smart mapping working with strict validation
expect(stdout).toContain('Smart mapping:');
expect(stdout).toContain('Coverage:');
// Coverage should be reasonable even with strict validation
const coverageMatch = stdout.match(/Coverage: ([\d.]+)%/);
expect(coverageMatch).toBeTruthy();
const coverage = parseFloat(coverageMatch[1]);
expect(coverage).toBeGreaterThanOrEqual(0); // Should not fail completely
}, 15000);
test('should generate HTML reports with smart mapping indicators', async () => {
const { stdout } = await execAsync(
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman --output smart-test-report.html`,
{ cwd: path.resolve(__dirname, '..') }
);
expect(stdout).toContain('HTML report saved to: smart-test-report.html');
// Check if the HTML file was created
const fs = require('fs');
const reportPath = path.resolve(__dirname, '..', 'smart-test-report.html');
expect(fs.existsSync(reportPath)).toBe(true);
// Read the HTML content and check for smart mapping indicators
const htmlContent = fs.readFileSync(reportPath, 'utf8');
expect(htmlContent).toContain('primary-match-badge');
expect(htmlContent).toContain('confidence-badge');
}, 15000);
test('should handle CSV API specification with smart mapping', async () => {
const csvApiPath = path.resolve(__dirname, 'fixtures', 'analytics-api.csv');
const testCollectionPath = path.resolve(__dirname, 'fixtures', 'test-collection.json');
// Only run this test if the CSV file exists
const fs = require('fs');
if (!fs.existsSync(csvApiPath)) {
console.log('Skipping CSV test - analytics-api.csv not found');
return;
}
const { stdout } = await execAsync(
`node cli.js "${csvApiPath}" "${testCollectionPath}" --verbose`,
{ cwd: path.resolve(__dirname, '..') }
);
expect(stdout).toContain('Coverage:');
// CSV format should work with smart mapping
if (stdout.includes('Smart mapping:')) {
expect(stdout).toMatch(/\d+ primary matches/);
}
}, 15000);
test('should handle edge case with empty collections', async () => {
// Create a temporary empty collection
const fs = require('fs');
const emptyCollection = {
info: { name: 'Empty Collection' },
item: []
};
const emptyCollectionPath = path.resolve(__dirname, '..', 'tmp-empty-collection.json');
fs.writeFileSync(emptyCollectionPath, JSON.stringify(emptyCollection, null, 2));
try {
const { stdout } = await execAsync(
`node cli.js "${sampleApiPath}" "${emptyCollectionPath}" --verbose`,
{ cwd: path.resolve(__dirname, '..') }
);
expect(stdout).toContain('Coverage: 0.00%');
expect(stdout).toContain('Smart mapping: 0 primary matches, 0 secondary matches');
} finally {
// Clean up
if (fs.existsSync(emptyCollectionPath)) {
fs.unlinkSync(emptyCollectionPath);
}
}
}, 15000);
test('should handle large API specifications efficiently', async () => {
// This is a performance test to ensure smart mapping doesn't significantly slow down processing
const startTime = Date.now();
const { stdout } = await execAsync(
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman`,
{ cwd: path.resolve(__dirname, '..') }
);
const endTime = Date.now();
const processingTime = endTime - startTime;
expect(stdout).toContain('Coverage:');
expect(processingTime).toBeLessThan(10000); // Should complete within 10 seconds
}, 15000);
});