Skip to content

Commit

Permalink
Do not export autocompleteOAS3
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Apr 20, 2023
1 parent 02ef45a commit 98ff758
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/javascript/src/ActiveDocs/OAS3Autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export interface Response extends SwaggerUIResponse {
text: string;
}

export const autocompleteOAS3 = (response: SwaggerUIResponse, accountData: AccountDataResponse, serviceEndpoint: string): Response => {
const autocompleteOAS3 = (response: SwaggerUIResponse, accountData: AccountDataResponse, serviceEndpoint: string): Response => {
const bodyWithServer = injectServerToResponseBody(response.body, serviceEndpoint)

let body = undefined
Expand Down
43 changes: 19 additions & 24 deletions spec/javascripts/ActiveDocs/OAS3Autocomplete.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { autocompleteOAS3, autocompleteRequestInterceptor } from 'ActiveDocs/OAS3Autocomplete'
import { autocompleteRequestInterceptor } from 'ActiveDocs/OAS3Autocomplete'

import type { Request as SwaggerUIRequest, Response as SwaggerUIResponse } from 'swagger-ui'
import type { AccountDataResponse} from 'Types/SwaggerTypes'
Expand Down Expand Up @@ -63,37 +63,32 @@ const accountData: AccountDataResponse = {
}
}

describe('autocompleteOAS3', () => {
it('should inject servers to the spec', async () => {
const res: SwaggerUIResponse = await autocompleteOAS3(specResponse, accountData, serviceEndpoint)
expect(res.body.servers).toEqual([{ 'url': 'foo/bar/serviceEndpoint' }])
})

it('should autocomplete fields of OpenAPI spec with x-data-threescale-name property', async () => {
const res: SwaggerUIResponse = await autocompleteOAS3(specResponse, accountData, serviceEndpoint)
const examplesFirstParam = res.body.paths['/'].get.parameters[0].examples
const examplesSecondParam = res.body.paths['/'].get.parameters[1].examples

expect(examplesFirstParam).toEqual([
{ summary: 'First user key from latest 5 applications', value: '-' },
{ summary: 'Some App - 12345678', value: '12345678' },
{ summary: 'Another App', value: '' }
])
expect(examplesSecondParam).toBe(undefined)
})
})

describe('autocompleteRequestInterceptor', () => {
describe('when the request is fetching OpenAPI spec', () => {
it('should update the response interceptor', async () => {
let request: SwaggerUIRequest = { loadSpec: true }
request = autocompleteRequestInterceptor(request, accountData, serviceEndpoint)
let request: SwaggerUIRequest = { loadSpec: true }
request = autocompleteRequestInterceptor(request, accountData, serviceEndpoint)

it('should update the response interceptor', async () => {
expect(request.responseInterceptor).toBeDefined()
})

it('response interceptor should inject servers to the spec', async () => {
const res: SwaggerUIResponse = await request.responseInterceptor(specResponse, accountDataUrl, serviceEndpoint)
expect(res.body.servers).toEqual([{ 'url': 'foo/bar/serviceEndpoint' }])
})

it('response interceptor should autocomplete fields of OpenAPI spec with x-data-threescale-name property', async () => {
const res: SwaggerUIResponse = await request.responseInterceptor(specResponse, accountDataUrl, serviceEndpoint)
const examplesFirstParam = res.body.paths['/'].get.parameters[0].examples
const examplesSecondParam = res.body.paths['/'].get.parameters[1].examples

expect(examplesFirstParam).toEqual([
{ summary: 'First user key from latest 5 applications', value: '-' },
{ summary: 'Some App - 12345678', value: '12345678' },
{ summary: 'Another App', value: '' }
])
expect(examplesSecondParam).toBe(undefined)
})
})

describe('when the request is fetching API call response', () => {
Expand Down

0 comments on commit 98ff758

Please sign in to comment.