-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug where going to curl tab modifies form values
- Loading branch information
Showing
10 changed files
with
160 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
generator/konfig-next-app/src/utils/code-generator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { HttpMethodsEnum } from 'konfig-lib' | ||
import { CodeGenerator, CodeGeneratorConstructorArgs } from './code-generator' | ||
import { SECURITY_FORM_NAME_PREFIX } from './generate-initial-operation-form-values' | ||
import clone from 'clone' | ||
|
||
class CodeGeneratorTest extends CodeGenerator { | ||
protected format(code: string): Promise<string> { | ||
throw new Error( | ||
'This class is only used for testing shared functions in CodeGenerator' | ||
) | ||
} | ||
protected gen(): string { | ||
throw new Error( | ||
'This class is only used for testing shared functions in CodeGenerator' | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Creates new instance of CodeGeneratorTest with values used for testing | ||
*/ | ||
function testArgs(): CodeGeneratorConstructorArgs { | ||
return { | ||
path: '', | ||
contentType: 'application/json', | ||
httpMethod: HttpMethodsEnum.POST, | ||
securitySchemes: { | ||
apiKey: { | ||
type: 'apiKey', | ||
in: 'header', | ||
name: 'X-Api-Key', | ||
}, | ||
}, | ||
formData: { | ||
requestBody: '', | ||
parameters: {}, | ||
security: { | ||
apiKey: { | ||
type: 'apiKey', | ||
in: 'header', | ||
key: 'X-API-Key', | ||
value: 'my_api_key', | ||
}, | ||
}, | ||
}, | ||
parameters: [], | ||
languageConfigurations: { | ||
typescript: { | ||
clientName: 'Test', | ||
packageName: 'test', | ||
}, | ||
python: { | ||
clientName: 'Test', | ||
packageName: 'tet', | ||
}, | ||
}, | ||
tag: 'Test', | ||
operationId: 'Test_test', | ||
requestBody: null, | ||
basePath: 'https://test.com/api', | ||
requestBodyRequired: true, | ||
servers: ['https://test.com/api'], | ||
oauthTokenUrl: null, | ||
originalOauthTokenUrl: null, | ||
} | ||
} | ||
|
||
test('ensure nonEmptySecurityMasked does not modify security values in-place', async () => { | ||
const args: CodeGeneratorConstructorArgs = testArgs() | ||
const test = new CodeGeneratorTest(args) | ||
const before = clone(test.configuration.formData[SECURITY_FORM_NAME_PREFIX]) | ||
test.nonEmptySecurityMasked() | ||
const after = test.configuration.formData[SECURITY_FORM_NAME_PREFIX] | ||
expect(before).toStrictEqual(after) | ||
}) |
Oops, something went wrong.