Skip to content

Commit 1c864be

Browse files
author
Sophia Marie Terry
committed
Added tests for extension utilities
1 parent 00a2052 commit 1c864be

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { describe, it, expect, toBe } from '@jest/globals';
2+
import { hasMethodWithVerbOverride, hasCustomMethodOverride, hasMethodVerbOverride } from '../../rulesets/functions/utils/extensions';
3+
4+
const methodWithExtension = {
5+
'x-xgen-method-verb-override': {
6+
verb: 'get',
7+
customMethod: false,
8+
},
9+
};
10+
11+
const customMethod = {
12+
'x-xgen-method-verb-override': {
13+
verb: 'add',
14+
customMethod: true,
15+
},
16+
}
17+
18+
const endpointWithMethodExtension = {
19+
delete: {
20+
'x-xgen-method-verb-override': { verb: '‘remove’', customMethod: true }
21+
}
22+
};
23+
24+
const endpointWithNoMethodExtension = {
25+
'exception' : true
26+
};
27+
28+
describe('tools/spectral/ipa/rulesets/functions/utils/extensions.js', () => {
29+
describe('hasMethodWithVerbOverride', () => {
30+
it('returns true if endpoint has method with the extension', () => {
31+
expect(hasMethodWithVerbOverride(endpointWithMethodExtension)).toBe(true);
32+
});
33+
it('returns false if object does not a method with the extension', () => {
34+
expect(hasMethodWithVerbOverride(endpointWithNoMethodExtension)).toBe(false);
35+
});
36+
});
37+
});
38+
39+
describe('tools/spectral/ipa/rulesets/functions/utils/extensions.js', () => {
40+
describe('hasCustomMethodOverride', () => {
41+
it('returns true if the method has the extension with the cusotmMethod boolean set to true', () => {
42+
expect(hasCustomMethodOverride(customMethod)).toBe(true);
43+
});
44+
it('returns false if the method does not have the extension', () => {
45+
expect(hasCustomMethodOverride({})).toBe(false);
46+
});
47+
it('returns false if the method has the extension but is not a custom method', () => {
48+
expect(hasCustomMethodOverride(methodWithExtension)).toBe(false);
49+
});
50+
});
51+
});
52+
53+
describe('tools/spectral/ipa/rulesets/functions/utils/extensions.js', () => {
54+
describe('hasMethodVerbOverride', () => {
55+
it('returns true if the method has the extension with the expected verb', () => {
56+
expect(hasMethodVerbOverride(methodWithExtension, "get")).toBe(true);
57+
});
58+
it('returns false if the method does not have the extension', () => {
59+
expect(hasMethodVerbOverride({}, "get")).toBe(false);
60+
});
61+
it('returns false if the method has the extension but with an unexpected verb', () => {
62+
expect(hasMethodVerbOverride(methodWithExtension, "put")).toBe(false);
63+
});
64+
});
65+
});

0 commit comments

Comments
 (0)