-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch.test.js
More file actions
56 lines (53 loc) · 1.71 KB
/
match.test.js
File metadata and controls
56 lines (53 loc) · 1.71 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
const { matchOperationsDetailed } = require('../lib/match');
const fs = require('fs');
const path = require('path');
describe('Match Module', () => {
beforeAll(() => {
const fixturesDir = path.resolve(__dirname, 'fixtures');
if (!fs.existsSync(fixturesDir)) {
fs.mkdirSync(fixturesDir);
}
});
test('matchOperationsDetailed should match operations correctly', () => {
const specOps = [
{
method: 'get',
path: '/test',
operationId: 'getTest',
tags: ['Test'],
expectedStatusCodes: ['200']
}
];
const postmanReqs = [
{
method: 'get',
rawUrl: 'https://api.example.com/test',
testedStatusCodes: ['200'],
queryParams: [],
bodyInfo: null,
testScripts: ''
}
];
const coverageItems = matchOperationsDetailed(specOps, postmanReqs, { verbose: false, strictQuery: false, strictBody: false });
expect(coverageItems.length).toBe(1);
expect(coverageItems[0].unmatched).toBe(false);
expect(coverageItems[0].matchedRequests.length).toBe(1);
expect(coverageItems[0].matchedRequests[0].method).toBe('GET');
});
test('matchOperationsDetailed should mark unmatched operations', () => {
const specOps = [
{
method: 'post',
path: '/test',
operationId: 'createTest',
tags: ['Test'],
expectedStatusCodes: ['201']
}
];
const postmanReqs = [];
const coverageItems = matchOperationsDetailed(specOps, postmanReqs, { verbose: false, strictQuery: false, strictBody: false });
expect(coverageItems.length).toBe(1);
expect(coverageItems[0].unmatched).toBe(true);
expect(coverageItems[0].matchedRequests.length).toBe(0);
});
});