This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still stuck on testing onSubmit for Doc
- Loading branch information
Showing
15 changed files
with
260 additions
and
175 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
53 changes: 53 additions & 0 deletions
53
packages/api-explorer-ui/__tests__/lib/create-code-shower.test.js
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,53 @@ | ||
const createCodeShower = require('../../src/lib/create-code-shower')('results'); | ||
const createCodeShower2 = require('../../src/lib/create-code-shower')('examples'); | ||
|
||
const Oas = require('../../src/lib/Oas.js'); | ||
const example = require('../fixtures/example-results/oas'); | ||
const petstore = require('../fixtures/petstore/oas'); | ||
|
||
const oas = new Oas(example); | ||
const oas2 = new Oas(petstore); | ||
|
||
describe('createCodeShower', () => { | ||
it('should return codes array if there are examples for the operation endpoint', () => { | ||
const operation = oas.operation('/results', 'get'); | ||
|
||
expect(createCodeShower(operation)).toEqual([ | ||
{ | ||
code: JSON.stringify( | ||
{ | ||
user: { | ||
email: 'test@example.com', | ||
name: 'Test user name', | ||
}, | ||
}, | ||
undefined, | ||
2, | ||
), | ||
language: 'application/json', | ||
status: '200', | ||
}, | ||
{ | ||
code: | ||
'<?xml version="1.0" encoding="UTF-8"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don\'t forget me this weekend!</body></note>', | ||
language: 'application/xml', | ||
status: '400', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should return early if there is no example', () => { | ||
const operation = oas2.operation('/pet/findByStatus', 'get'); | ||
expect(createCodeShower(operation)).toEqual([]); | ||
}); | ||
|
||
it('should return early if there is no response', () => { | ||
const operation = oas.operation('/nolang', 'get'); | ||
expect(createCodeShower(operation)).toEqual([]); | ||
}); | ||
|
||
it('should return codes if type is not results', () => { | ||
const operation = oas.operation('/results', 'get'); | ||
expect(createCodeShower2(operation)).toEqual([]); | ||
}); | ||
}); |
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,34 @@ | ||
const getPath = require('../../src/lib/get-path'); | ||
const Oas = require('../../src/lib/Oas.js'); | ||
|
||
const petstore = require('../fixtures/petstore/oas'); | ||
|
||
const swagger = new Oas(petstore); | ||
|
||
describe('getSchema', () => { | ||
it('should return path from swagger file', () => { | ||
const doc = { swagger: { path: '/user/logout' }, api: { method: 'get' } }; | ||
|
||
expect(getPath(swagger, doc)).toEqual({ | ||
get: { | ||
tags: ['user'], | ||
summary: 'Logs out current logged in user session', | ||
description: '', | ||
operationId: 'logoutUser', | ||
parameters: [], | ||
responses: { | ||
default: { | ||
description: 'successful operation', | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
it('should return parameters object if doc does not have swagger property', () => { | ||
const doc = { api: { method: 'get' } }; | ||
|
||
expect(getPath(swagger, doc)).toEqual({ | ||
parameters: [], | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
const getSchema = require('../../src/lib/get-schema'); | ||
const Oas = require('../../src/lib/Oas.js'); | ||
|
||
const petstore = require('../fixtures/petstore/oas'); | ||
|
||
const oas = new Oas(petstore); | ||
|
||
describe('getSchema', () => { | ||
it('should return schema if requestBody content is application json', () => { | ||
const operation = oas.operation('/user/{username}', 'put'); | ||
|
||
expect(getSchema(operation)).toEqual({ | ||
$ref: '#/components/schemas/User', | ||
}); | ||
}); | ||
|
||
it('should return requestBody if content is not application json', () => { | ||
const operation = oas.operation('/user/createWithList', 'post'); | ||
|
||
expect(getSchema(operation)).toEqual({ | ||
$ref: '#/components/requestBodies/UserArray', | ||
}); | ||
}); | ||
}); |
42 changes: 21 additions & 21 deletions
42
packages/api-explorer-ui/__tests__/lib/replace-vars.test.js
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
const { replaceVars } = require('../../src/lib/replace-vars'); | ||
|
||
describe('replaceVars', () => { | ||
it('should return true if auth data is passed in correctly for api key condition', () => { | ||
// const operation = oas.operation('/api-key', 'post'); | ||
// | ||
expect( | ||
replaceVars({ | ||
user: { | ||
email: 'test@example.com', | ||
name: 'Test user name', | ||
}, | ||
}), | ||
).toEqual({ | ||
user: { | ||
email: 'test@example.com', | ||
name: 'Test user name', | ||
}, | ||
}); | ||
}); | ||
}); | ||
// const { replaceVars } = require('../../src/lib/replace-vars'); | ||
// | ||
// describe('replaceVars', () => { | ||
// it('should return true if auth data is passed in correctly for api key condition', () => { | ||
// // const operation = oas.operation('/api-key', 'post'); | ||
// // | ||
// expect( | ||
// replaceVars({ | ||
// user: { | ||
// email: 'test@example.com', | ||
// name: 'Test user name', | ||
// }, | ||
// }), | ||
// ).toEqual({ | ||
// user: { | ||
// email: 'test@example.com', | ||
// name: 'Test user name', | ||
// }, | ||
// }); | ||
// }); | ||
// }); |
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
Oops, something went wrong.