|
| 1 | +import swaggerFunctions from '../src/resources/functions'; |
| 2 | +import { AutoSwaggerCustomConfig, CustomServerless } from '../src/types/serverless-plugin.types'; |
| 3 | + |
| 4 | +const defaultServiceDetails: CustomServerless = { |
| 5 | + configSchemaHandler: { |
| 6 | + defineCustomProperties: () => undefined, |
| 7 | + defineFunctionEvent: () => undefined, |
| 8 | + defineFunctionEventProperties: () => undefined, |
| 9 | + defineFunctionProperties: () => undefined, |
| 10 | + defineProvider: () => undefined, |
| 11 | + defineTopLevelProperty: () => undefined, |
| 12 | + }, |
| 13 | + configurationInput: {}, |
| 14 | + service: { |
| 15 | + service: '', |
| 16 | + provider: { |
| 17 | + name: 'aws', |
| 18 | + runtime: undefined, |
| 19 | + stage: '', |
| 20 | + region: undefined, |
| 21 | + profile: '', |
| 22 | + environment: {}, |
| 23 | + }, |
| 24 | + plugins: [], |
| 25 | + functions: { |
| 26 | + mocked: { |
| 27 | + handler: 'mocked.handler', |
| 28 | + }, |
| 29 | + }, |
| 30 | + custom: { |
| 31 | + autoswagger: {}, |
| 32 | + }, |
| 33 | + }, |
| 34 | +}; |
| 35 | + |
| 36 | +type GetCustomServerlessConfigParams = { |
| 37 | + autoswaggerOptions?: AutoSwaggerCustomConfig; |
| 38 | +}; |
| 39 | + |
| 40 | +const getCustomServerlessConfig = ({ autoswaggerOptions }: GetCustomServerlessConfigParams = {}): CustomServerless => ({ |
| 41 | + ...defaultServiceDetails, |
| 42 | + service: { |
| 43 | + ...defaultServiceDetails.service, |
| 44 | + custom: { |
| 45 | + ...defaultServiceDetails.service.custom, |
| 46 | + autoswagger: { |
| 47 | + ...defaultServiceDetails.service.custom?.autoswagger, |
| 48 | + ...autoswaggerOptions, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | +}); |
| 53 | + |
| 54 | +describe('swaggerFunctions tests', () => { |
| 55 | + it('includes swaggerRedirectURI if useRedirectUI is set to true', () => { |
| 56 | + const serviceDetails = getCustomServerlessConfig({ |
| 57 | + autoswaggerOptions: { |
| 58 | + useRedirectUI: true, |
| 59 | + }, |
| 60 | + }); |
| 61 | + const result = swaggerFunctions(serviceDetails); |
| 62 | + expect(Object.keys(result)).toContain('swaggerRedirectURI'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('does not includes swaggerRedirectURI if useRedirectUI is set to false', () => { |
| 66 | + const serviceDetails = getCustomServerlessConfig({ |
| 67 | + autoswaggerOptions: { |
| 68 | + useRedirectUI: false, |
| 69 | + }, |
| 70 | + }); |
| 71 | + const result = swaggerFunctions(serviceDetails); |
| 72 | + expect(Object.keys(result)).not.toContain('swaggerRedirectURI'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('does not includes swaggerRedirectURI if useRedirectUI is not set', () => { |
| 76 | + const serviceDetails = getCustomServerlessConfig(); |
| 77 | + const result = swaggerFunctions(serviceDetails); |
| 78 | + expect(Object.keys(result)).not.toContain('swaggerRedirectURI'); |
| 79 | + }); |
| 80 | +}); |
0 commit comments