|
| 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